PiDP-8/I SoftwareCheck-in [f921ba10f9]
Not logged in

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Opening class simh log files in binary mode to avoid a problem introduced by an unbelievably screwy change in Python 3 vs 2: https://stackoverflow.com/a/5513856/142454
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | os8-run-python3
Files: files | file ages | folders
SHA3-256:f921ba10f9ff48ecbde6a4970dc5e0b699bb9403f5daa9b13f2be990fb33c08f
User & Date: tangent 2019-04-15 06:39:16
Context
2019-04-15
07:33
Merged in the tiny trunk differences relative to the SIMH update accidentally checked in on this branch. Now this branch contains only the Python 2-ism fixes relative to trunk. check-in: 18d667556a user: tangent tags: os8-run-python3
06:39
Opening class simh log files in binary mode to avoid a problem introduced by an unbelievably screwy change in Python 3 vs 2: https://stackoverflow.com/a/5513856/142454 check-in: f921ba10f9 user: tangent tags: os8-run-python3
06:33
Replaced use of dict.iteritems() with items() check-in: 394ecc357c user: tangent tags: os8-run-python3
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to bin/os8-cp.in.

2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
...
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
# -*- coding: utf-8 -*-
########################################################################
# Generalized facility to manipulate os8 device images from the POSIX
# (host) side using OS/8 system programs under SIMH.
#
# See USAGE message below for details.
#
# Copyright © 2018 by Bill Cattey and Warren Young
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
................................................................................

  # Create the SIMH child instance and tell it where to send log output
  try:
    s = simh (dirs.build, True)
  except (RuntimeError) as e:
    print "Could not start simulator: " + e.message + '!'
    exit (1)
  # s.set_logfile (os.fdopen (sys.stdout.fileno (), 'w', 0))
  s.set_logfile (open ("logfile.txt", 'w'))
  if VERBOSE: s.verbose = True
  
  # Perform sys attach
  att_spec = action_plan["sys"]
  if att_spec == None: att_spec = _default_att_spec
  simh_boot_dev = att_spec[0] + att_spec[1]     # Compose simh dev from name and unit.
  imagename = att_spec[2]







|







 







|
|







2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
...
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
# -*- coding: utf-8 -*-
########################################################################
# Generalized facility to manipulate os8 device images from the POSIX
# (host) side using OS/8 system programs under SIMH.
#
# See USAGE message below for details.
#
# Copyright © 2018-2019 by Bill Cattey and Warren Young
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
................................................................................

  # Create the SIMH child instance and tell it where to send log output
  try:
    s = simh (dirs.build, True)
  except (RuntimeError) as e:
    print "Could not start simulator: " + e.message + '!'
    exit (1)
  # s.set_logfile (os.fdopen (sys.stdout.fileno (), 'wb', 0))
  s.set_logfile (open ("logfile.txt", 'wb'))
  if VERBOSE: s.verbose = True
  
  # Perform sys attach
  att_spec = action_plan["sys"]
  if att_spec == None: att_spec = _default_att_spec
  simh_boot_dev = att_spec[0] + att_spec[1]     # Compose simh dev from name and unit.
  imagename = att_spec[2]

Changes to bin/os8-run.

195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
  # media and once for the actual RK05 bootable media.  So, the second
  # run must append its logs to the first run's log file.
  #
  # Send the log info to the console instead of the progress messages if
  # -v was given.  See https://stackoverflow.com/questions/21239338
  s = simh (dirs.build, True)
  if VERBOSE: s.verbose = True
  s.set_logfile (open (dirs.log + 'os8-run' + '.log', 'a') \
      if not VERY_VERBOSE else os.fdopen (sys.stdout.fileno (), 'w', 0))

  os8 = os8script (s, options_enabled, options_disabled, verbose=VERBOSE, debug=DEBUG)

  for script_file in script_files:
    if VERBOSE:
      print(os.path.basename (__file__) + " -- Language Version: " + os8.lang_version)








|
|







195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
  # media and once for the actual RK05 bootable media.  So, the second
  # run must append its logs to the first run's log file.
  #
  # Send the log info to the console instead of the progress messages if
  # -v was given.  See https://stackoverflow.com/questions/21239338
  s = simh (dirs.build, True)
  if VERBOSE: s.verbose = True
  s.set_logfile (open (dirs.log + 'os8-run' + '.log', 'ab') \
      if not VERY_VERBOSE else os.fdopen (sys.stdout.fileno (), 'wb', 0))

  os8 = os8script (s, options_enabled, options_disabled, verbose=VERBOSE, debug=DEBUG)

  for script_file in script_files:
    if VERBOSE:
      print(os.path.basename (__file__) + " -- Language Version: " + os8.lang_version)

Changes to bin/teco-pi-demo.

55
56
57
58
59
60
61
62
63
64
65
66
67
68
69

  # Create the SIMH child instance and tell it where to send log output
  try:
    s = simh (dirs.build)
  except (RuntimeError) as e:
    print "Could not start simulator: " + e.message + '!'
    exit (1)
  s.set_logfile (os.fdopen (sys.stdout.fileno (), 'w', 0))

  # Find and boot the built OS/8 bin disk
  rk = os.path.join (dirs.os8mo, 'v3d.rk05')
  if not os.path.isfile (rk):
    print "Could not find " + rk + "; OS/8 media not yet built?"
    exit (1)
  print "Booting " + rk + "..."







|







55
56
57
58
59
60
61
62
63
64
65
66
67
68
69

  # Create the SIMH child instance and tell it where to send log output
  try:
    s = simh (dirs.build)
  except (RuntimeError) as e:
    print "Could not start simulator: " + e.message + '!'
    exit (1)
  s.set_logfile (os.fdopen (sys.stdout.fileno (), 'wb', 0))

  # Find and boot the built OS/8 bin disk
  rk = os.path.join (dirs.os8mo, 'v3d.rk05')
  if not os.path.isfile (rk):
    print "Could not find " + rk + "; OS/8 media not yet built?"
    exit (1)
  print "Booting " + rk + "..."

Changes to bin/txt2os8.

15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
...
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# IMPORTANT:  Currently all input files are mindlessly passed through
# txt2ptp which transforms POSIX ASCII files to OS/8 ASCII files.
# It WILL mutilate non-ASCII files.
#
# This program is based on the old cc8-tu56-update program, last
# shipped by this project in release v20171222.
#
# Copyright © 2017 by Warren Young and Bill Cattey
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
................................................................................

  # Create the SIMH child instance and tell it where to send log output
  try:
    s = simh (dirs.build, True)
  except (RuntimeError) as e:
    print "Could not start simulator: " + e.message + '!'
    exit (1)
  s.set_logfile (os.fdopen (sys.stdout.fileno (), 'w', 0))

  # Attach a clean version of the image to the simulator
  if os.path.exists (imagename):
    print "Overwriting old " + stat_str + " image " + imagename

  s.send_cmd ("att " + sdev + " " + imagename)








|







 







|







15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
...
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# IMPORTANT:  Currently all input files are mindlessly passed through
# txt2ptp which transforms POSIX ASCII files to OS/8 ASCII files.
# It WILL mutilate non-ASCII files.
#
# This program is based on the old cc8-tu56-update program, last
# shipped by this project in release v20171222.
#
# Copyright © 2017-2019 by Warren Young and Bill Cattey
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
................................................................................

  # Create the SIMH child instance and tell it where to send log output
  try:
    s = simh (dirs.build, True)
  except (RuntimeError) as e:
    print "Could not start simulator: " + e.message + '!'
    exit (1)
  s.set_logfile (os.fdopen (sys.stdout.fileno (), 'wb', 0))

  # Attach a clean version of the image to the simulator
  if os.path.exists (imagename):
    print "Overwriting old " + stat_str + " image " + imagename

  s.send_cmd ("att " + sdev + " " + imagename)

Changes to doc/class-simh.md.

82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102


## Logging

The next step is to tell the `s` object where to send its logging
output:

    s.set_logfile (os.fdopen (sys.stdout.fileno (), 'w', 0))

Contrast the corresponding line in `os8-run` which chooses whether to send
logging output to the console or to a log file:

    s.set_logfile (open (dirs.log + 'os8-run' + '.log', 'a') \
        if not VERY_VERBOSE else os.fdopen (sys.stdout.fileno (), 'w', 0))

Note that this more complicated scheme appends to the log file instead
of overwriting it because there are cases where `os8-run` gets run
more than once with different script inputs, so we want to preserve
the prior script outputs, not keep only the latest.









|




|
|







82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102


## Logging

The next step is to tell the `s` object where to send its logging
output:

    s.set_logfile (os.fdopen (sys.stdout.fileno (), 'wb', 0))

Contrast the corresponding line in `os8-run` which chooses whether to send
logging output to the console or to a log file:

    s.set_logfile (open (dirs.log + 'os8-run' + '.log', 'ab') \
        if not VERY_VERBOSE else os.fdopen (sys.stdout.fileno (), 'wb', 0))

Note that this more complicated scheme appends to the log file instead
of overwriting it because there are cases where `os8-run` gets run
more than once with different script inputs, so we want to preserve
the prior script outputs, not keep only the latest.


Changes to tools/test-os8-send-file.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
..
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#!/usr/bin/env python
# -*- coding: utf-8 -*-
########################################################################
# test-os8-send-file - Repeatedly sends random files through class simh
#   method os8_send_file() and pulls it back through os8_get_file(),
#   then checks that the file is unchanged.
#
# Copyright © 2017 by Warren Young.
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
................................................................................
def main ():
  # Create the SIMH child instance and tell it where to send log output
  try:
    s = simh (dirs.build)
  except (RuntimeError) as e:
    print "Could not start simulator: " + e.message + '!'
    exit (1)
  s.set_logfile (os.fdopen (sys.stdout.fileno (), 'w', 0))

  # Find and boot the built OS/8 bin disk
  rk = os.path.join (dirs.os8mo, 'v3d.rk05')
  if not os.path.isfile (rk):
    print "Could not find " + rk + "; OS/8 media not yet built?"
    exit (1)
  print "Booting " + rk + "..."







|







 







|







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
..
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#!/usr/bin/env python
# -*- coding: utf-8 -*-
########################################################################
# test-os8-send-file - Repeatedly sends random files through class simh
#   method os8_send_file() and pulls it back through os8_get_file(),
#   then checks that the file is unchanged.
#
# Copyright © 2017-2019 by Warren Young.
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
................................................................................
def main ():
  # Create the SIMH child instance and tell it where to send log output
  try:
    s = simh (dirs.build)
  except (RuntimeError) as e:
    print "Could not start simulator: " + e.message + '!'
    exit (1)
  s.set_logfile (os.fdopen (sys.stdout.fileno (), 'wb', 0))

  # Find and boot the built OS/8 bin disk
  rk = os.path.join (dirs.os8mo, 'v3d.rk05')
  if not os.path.isfile (rk):
    print "Could not find " + rk + "; OS/8 media not yet built?"
    exit (1)
  print "Booting " + rk + "..."