Changeset 28f4adb in mainline for tools


Ignore:
Timestamp:
2010-11-02T11:13:36Z (15 years ago)
Author:
Martin Decky <martin@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
4687a26c, e06ef614
Parents:
458619f7
git-author:
Vojtech Horky <> (2010-11-02 11:13:36)
git-committer:
Martin Decky <martin@…> (2010-11-02 11:13:36)
Message:

update scripts for compatibility with Python 3 (thx Vojtech Horky and Martin Sucha)

Location:
tools
Files:
12 edited

Legend:

Unmodified
Added
Removed
  • tools/autotool.py

    r458619f7 r28f4adb  
    7575        "Read HelenOS build configuration"
    7676       
    77         inf = file(fname, 'r')
     77        inf = open(fname, 'r')
    7878       
    7979        for line in inf:
     
    191191        check_common(common, "CC")
    192192       
    193         outf = file(PROBE_SOURCE, 'w')
     193        outf = open(PROBE_SOURCE, 'w')
    194194        outf.write(PROBE_HEAD)
    195195       
     
    212212        if (not os.path.isfile(PROBE_OUTPUT)):
    213213                sys.stderr.write("failed\n")
    214                 print output[1]
     214                print(output[1])
    215215                print_error(["Error executing \"%s\"." % " ".join(args),
    216216                             "The compiler did not produce the output file \"%s\"." % PROBE_OUTPUT,
     
    221221        sys.stderr.write("ok\n")
    222222       
    223         inf = file(PROBE_OUTPUT, 'r')
     223        inf = open(PROBE_OUTPUT, 'r')
    224224        lines = inf.readlines()
    225225        inf.close()
     
    343343        "Create makefile output"
    344344       
    345         outmk = file(mkname, 'w')
     345        outmk = open(mkname, 'w')
    346346       
    347347        outmk.write('#########################################\n')
     
    357357        "Create header output"
    358358       
    359         outhd = file(hdname, 'w')
     359        outhd = open(hdname, 'w')
    360360       
    361361        outhd.write('/***************************************\n')
  • tools/checkers/clang.py

    r458619f7 r28f4adb  
    4242def usage(prname):
    4343        "Print usage syntax"
    44         print prname + " <ROOT>"
     44        print(prname + " <ROOT>")
    4545
    4646def clang(root, job):
     
    5050       
    5151        if (not os.path.isfile(inname)):
    52                 print "Unable to open %s" % inname
    53                 print "Did you run \"make precheck\" on the source tree?"
     52                print("Unable to open %s" % inname)
     53                print("Did you run \"make precheck\" on the source tree?")
    5454                return False
    5555       
    56         inf = file(inname, "r")
     56        inf = open(inname, "r")
    5757        records = inf.read().splitlines()
    5858        inf.close()
     
    6464               
    6565                if (len(arg) < 6):
    66                         print "Not enought jobfile record arguments"
     66                        print("Not enought jobfile record arguments")
    6767                        return False
    6868               
     
    7676                srcfqname = os.path.join(base, srcfname)
    7777                if (not os.path.isfile(srcfqname)):
    78                         print "Source %s not found" % srcfqname
     78                        print("Source %s not found" % srcfqname)
    7979                        return False
    8080               
     
    108108       
    109109        if (not os.path.isfile(config)):
    110                 print "%s not found." % config
    111                 print "Please specify the path to HelenOS build tree root as the first argument."
     110                print("%s not found." % config)
     111                print("Please specify the path to HelenOS build tree root as the first argument.")
    112112                return
    113113       
     
    115115                if (not clang(rootdir, job)):
    116116                        print
    117                         print "Failed job: %s" % job
     117                        print("Failed job: %s" % job)
    118118                        return
    119119       
    120120        print
    121         print "All jobs passed"
     121        print("All jobs passed")
    122122
    123123if __name__ == '__main__':
  • tools/checkers/jobfile.py

    r458619f7 r28f4adb  
    5454                                nil = True
    5555                        else:
    56                                 print "Unexpected '%s'" % record[i]
     56                                print("Unexpected '%s'" % record[i])
    5757                                return False
    5858               
  • tools/checkers/stanse.py

    r458619f7 r28f4adb  
    4343def usage(prname):
    4444        "Print usage syntax"
    45         print prname + " <ROOT>"
     45        print(prname + " <ROOT>")
    4646
    4747def stanse(root, job):
     
    5454       
    5555        if (not os.path.isfile(inname)):
    56                 print "Unable to open %s" % inname
    57                 print "Did you run \"make precheck\" on the source tree?"
     56                print("Unable to open %s" % inname)
     57                print("Did you run \"make precheck\" on the source tree?")
    5858                return False
    5959       
    60         inf = file(inname, "r")
     60        inf = open(inname, "r")
    6161        records = inf.read().splitlines()
    6262        inf.close()
     
    6969               
    7070                if (len(arg) < 6):
    71                         print "Not enought jobfile record arguments"
     71                        print("Not enought jobfile record arguments")
    7272                        return False
    7373               
     
    8181                srcfqname = os.path.join(base, srcfname)
    8282                if (not os.path.isfile(srcfqname)):
    83                         print "Source %s not found" % srcfqname
     83                        print("Source %s not found" % srcfqname)
    8484                        return False
    8585               
     
    9090                output.append([srcfname, tgtfname, base, options])
    9191       
    92         outf = file(outname, "w")
     92        outf = open(outname, "w")
    9393        for record in output:
    9494                outf.write("{%s},{%s},{%s},{%s}\n" % (record[0], record[1], record[2], record[3]))
     
    121121       
    122122        if (not os.path.isfile(config)):
    123                 print "%s not found." % config
    124                 print "Please specify the path to HelenOS build tree root as the first argument."
     123                print("%s not found." % config)
     124                print("Please specify the path to HelenOS build tree root as the first argument.")
    125125                return
    126126       
     
    128128                if (not stanse(rootdir, job)):
    129129                        print
    130                         print "Failed job: %s" % job
     130                        print("Failed job: %s" % job)
    131131                        return
    132132       
    133133        print
    134         print "All jobs passed"
     134        print("All jobs passed")
    135135
    136136if __name__ == '__main__':
  • tools/checkers/vcc.py

    r458619f7 r28f4adb  
    4949def usage(prname):
    5050        "Print usage syntax"
    51         print prname + " <ROOT> [VCC_PATH]"
     51        print(prname + " <ROOT> [VCC_PATH]")
    5252
    5353def cygpath(upath):
     
    7272        preproc = subprocess.Popen(args, stdout = subprocess.PIPE).communicate()[0]
    7373       
    74         tmpf = file(tmpfname, "w")
     74        tmpf = open(tmpfname, "w")
    7575        tmpf.write(specification)
    7676       
     
    108108       
    109109        if (not os.path.isfile(inname)):
    110                 print "Unable to open %s" % inname
    111                 print "Did you run \"make precheck\" on the source tree?"
     110                print("Unable to open %s" % inname)
     111                print("Did you run \"make precheck\" on the source tree?")
    112112                return False
    113113       
    114         inf = file(inname, "r")
     114        inf = open(inname, "r")
    115115        records = inf.read().splitlines()
    116116        inf.close()
     
    122122               
    123123                if (len(arg) < 6):
    124                         print "Not enought jobfile record arguments"
     124                        print("Not enought jobfile record arguments")
    125125                        return False
    126126               
     
    134134                srcfqname = os.path.join(base, srcfname)
    135135                if (not os.path.isfile(srcfqname)):
    136                         print "Source %s not found" % srcfqname
     136                        print("Source %s not found" % srcfqname)
    137137                        return False
    138138               
     
    153153               
    154154                # Run Vcc
    155                 print " -- %s --" % srcfname           
     155                print(" -- %s --" % srcfname)
    156156                retval = subprocess.Popen([vcc_path, '/pointersize:32', '/newsyntax', cygpath(tmpfqname)]).wait()
    157157               
     
    182182       
    183183        if (not os.path.isfile(vcc_path)):
    184                 print "%s is not a binary." % vcc_path
    185                 print "Please supply the full Cygwin path to Vcc as the second argument."
     184                print("%s is not a binary." % vcc_path)
     185                print("Please supply the full Cygwin path to Vcc as the second argument.")
    186186                return
    187187       
     
    189189       
    190190        if (not os.path.isfile(config)):
    191                 print "%s not found." % config
    192                 print "Please specify the path to HelenOS build tree root as the first argument."
     191                print("%s not found." % config)
     192                print("Please specify the path to HelenOS build tree root as the first argument.")
    193193                return
    194194       
    195195        specpath = os.path.join(rootdir, "tools/checkers/vcc.h")
    196196        if (not os.path.isfile(specpath)):
    197                 print "%s not found." % config
     197                print("%s not found." % config)
    198198                return
    199199       
     
    205205                if (not vcc(vcc_path, rootdir, job)):
    206206                        print
    207                         print "Failed job: %s" % job
     207                        print("Failed job: %s" % job)
    208208                        return
    209209       
    210210        print
    211         print "All jobs passed"
     211        print("All jobs passed")
    212212
    213213if __name__ == '__main__':
  • tools/config.py

    r458619f7 r28f4adb  
    4848        "Read saved values from last configuration run"
    4949       
    50         inf = file(fname, 'r')
     50        inf = open(fname, 'r')
    5151       
    5252        for line in inf:
     
    103103                condval = res.group(3)
    104104               
    105                 if (not defaults.has_key(condname)):
     105                if (not condname in defaults):
    106106                        varval = ''
    107107                else:
     
    131131        "Parse configuration file"
    132132       
    133         inf = file(fname, 'r')
     133        inf = open(fname, 'r')
    134134       
    135135        name = ''
     
    219219                        continue
    220220               
    221                 if (not defaults.has_key(varname)):
     221                if (not varname in defaults):
    222222                        return False
    223223       
     
    232232       
    233233        try:
    234                 version = subprocess.Popen(['bzr', 'version-info', '--custom', '--template={clean}:{revno}:{revision_id}'], stdout = subprocess.PIPE).communicate()[0].split(':')
     234                version = subprocess.Popen(['bzr', 'version-info', '--custom', '--template={clean}:{revno}:{revision_id}'], stdout = subprocess.PIPE).communicate()[0].decode().split(':')
    235235                sys.stderr.write("ok\n")
    236236        except:
     
    246246                revision = None
    247247       
    248         outmk = file(mkname, 'w')
    249         outmc = file(mcname, 'w')
     248        outmk = open(mkname, 'w')
     249        outmc = open(mcname, 'w')
    250250       
    251251        outmk.write('#########################################\n')
     
    263263                        continue
    264264               
    265                 if (not defaults.has_key(varname)):
     265                if (not varname in defaults):
    266266                        default = ''
    267267                else:
     
    368368                        # Cancel out all defaults which have to be deduced
    369369                        for varname, vartype, name, choices, cond in ask_names:
    370                                 if ((vartype == 'y') and (defaults.has_key(varname)) and (defaults[varname] == '*')):
     370                                if ((vartype == 'y') and (varname in defaults) and (defaults[varname] == '*')):
    371371                                        defaults[varname] = None
    372372                       
     
    385385                                        position = cnt
    386386                               
    387                                 if (not defaults.has_key(varname)):
     387                                if (not varname in defaults):
    388388                                        default = None
    389389                                else:
     
    428428                                cnt += 1
    429429                       
    430                         if (position >= options):
     430                        if (position != None) and (position >= len(options)):
    431431                                position = None
    432432                       
     
    449449                       
    450450                        position = None
    451                         if (not opt2row.has_key(value)):
     451                        if (not value in opt2row):
    452452                                raise RuntimeError("Error selecting value: %s" % value)
    453453                       
    454454                        (selname, seltype, name, choices) = opt2row[value]
    455455                       
    456                         if (not defaults.has_key(selname)):
     456                        if (not selname in defaults):
    457457                                        default = None
    458458                        else:
  • tools/jobfile.py

    r458619f7 r28f4adb  
    3838def usage(prname):
    3939        "Print usage syntax"
    40         print prname + " <JOBFILE> <SOURCE> <TARGET> <TOOL> <CATEGORY> [OPTIONS ...]"
     40        print(prname + " <JOBFILE> <SOURCE> <TARGET> <TOOL> <CATEGORY> [OPTIONS ...]")
    4141
    4242def main():
     
    5353        options = " ".join(sys.argv[6:])
    5454       
    55         jobfile = file(jobfname, "a")
     55        jobfile = open(jobfname, "a")
    5656        fcntl.lockf(jobfile, fcntl.LOCK_EX)
    5757        jobfile.write("{%s},{%s},{%s},{%s},{%s},{%s}\n" % (srcfname, tgtfname, toolname, category, cwd, options))
  • tools/mkfat.py

    r458619f7 r28f4adb  
    4646                return size
    4747       
    48         return (((size / alignment) + 1) * alignment)
     48        return ((size // alignment) + 1) * alignment
    4949
    5050def subtree_size(root, cluster_size, dirent_size):
     
    7979        first = 0
    8080       
    81         inf = file(path, "r")
     81        inf = open(path, "rb")
    8282        rd = 0;
    8383        while (rd < size):
     
    9292                prev = empty_cluster
    9393               
    94                 data = inf.read(cluster_size);
     94                data = bytes(inf.read(cluster_size));
    9595                outf.seek(data_start + (empty_cluster - reserved_clusters) * cluster_size)
    9696                outf.write(data)
     
    120120                prev = empty_cluster
    121121               
    122                 data = ''
     122                data = bytes()
    123123                data_len = 0
    124124                while ((i < length) and (data_len < cluster_size)):
     
    343343def usage(prname):
    344344        "Print usage syntax"
    345         print prname + " <EXTRA_BYTES> <PATH> <IMAGE>"
     345        print(prname + " <EXTRA_BYTES> <PATH> <IMAGE>")
    346346
    347347def main():
     
    351351       
    352352        if (not sys.argv[1].isdigit()):
    353                 print "<EXTRA_BYTES> must be a number"
     353                print("<EXTRA_BYTES> must be a number")
    354354                return
    355355       
     
    358358        path = os.path.abspath(sys.argv[2])
    359359        if (not os.path.isdir(path)):
    360                 print "<PATH> must be a directory"
     360                print("<PATH> must be a directory")
    361361                return
    362362       
     
    372372        # Make sure the filesystem is large enought for FAT16
    373373        size = subtree_size(path, cluster_size, dirent_size) + reserved_clusters * cluster_size + extra_bytes
    374         while (size / cluster_size < fat16_clusters):
     374        while (size // cluster_size < fat16_clusters):
    375375                if (cluster_size > sector_size):
    376                         cluster_size /= 2
     376                        cluster_size = cluster_size // 2
    377377                        size = subtree_size(path, cluster_size, dirent_size) + reserved_clusters * cluster_size + extra_bytes
    378378                else:
     
    381381        root_size = align_up(root_entries(path) * dirent_size, cluster_size)
    382382       
    383         fat_size = align_up(align_up(size, cluster_size) / cluster_size * fatent_size, sector_size)
    384        
    385         sectors = (cluster_size + fat_count * fat_size + root_size + size) / sector_size
     383        fat_size = align_up(align_up(size, cluster_size) // cluster_size * fatent_size, sector_size)
     384       
     385        sectors = (cluster_size + fat_count * fat_size + root_size + size) // sector_size
    386386        root_start = cluster_size + fat_count * fat_size
    387387        data_start = root_start + root_size
    388388       
    389         outf = file(sys.argv[3], "w")
     389        outf = open(sys.argv[3], "wb")
    390390       
    391391        boot_sector = xstruct.create(BOOT_SECTOR)
    392392        boot_sector.jmp = [0xEB, 0x3C, 0x90]
    393         boot_sector.oem = "MSDOS5.0"
     393        boot_sector.oem = b'MSDOS5.0'
    394394        boot_sector.sector = sector_size
    395         boot_sector.cluster = cluster_size / sector_size
    396         boot_sector.reserved = cluster_size / sector_size
     395        boot_sector.cluster = cluster_size // sector_size
     396        boot_sector.reserved = cluster_size // sector_size
    397397        boot_sector.fats = fat_count
    398         boot_sector.rootdir = root_size / dirent_size
     398        boot_sector.rootdir = root_size // dirent_size
    399399        if (sectors <= 65535):
    400400                boot_sector.sectors = sectors
     
    402402                boot_sector.sectors = 0
    403403        boot_sector.descriptor = 0xF8
    404         boot_sector.fat_sectors = fat_size / sector_size
     404        boot_sector.fat_sectors = fat_size // sector_size
    405405        boot_sector.track_sectors = 63
    406406        boot_sector.heads = 6
     
    414414        boot_sector.extboot_signature = 0x29
    415415        boot_sector.serial = random.randint(0, 0x7fffffff)
    416         boot_sector.label = "HELENOS"
    417         boot_sector.fstype = "FAT16   "
     416        boot_sector.label = b'HELENOS'
     417        boot_sector.fstype = b'FAT16   '
    418418        boot_sector.boot_signature = [0x55, 0xAA]
    419419       
     
    423423       
    424424        # Reserved sectors
    425         for i in range(1, cluster_size / sector_size):
     425        for i in range(1, cluster_size // sector_size):
    426426                outf.write(empty_sector.pack())
    427427       
    428428        # FAT tables
    429429        for i in range(0, fat_count):
    430                 for j in range(0, fat_size / sector_size):
     430                for j in range(0, fat_size // sector_size):
    431431                        outf.write(empty_sector.pack())
    432432       
    433433        # Root directory
    434         for i in range(0, root_size / sector_size):
     434        for i in range(0, root_size // sector_size):
    435435                outf.write(empty_sector.pack())
    436436       
    437437        # Data
    438         for i in range(0, size / sector_size):
     438        for i in range(0, size // sector_size):
    439439                outf.write(empty_sector.pack())
    440440       
    441         fat = array.array('L', [0] * (fat_size / fatent_size))
     441        fat = array.array('L', [0] * (fat_size // fatent_size))
    442442        fat[0] = 0xfff8
    443443        fat[1] = 0xffff
     
    449449        for i in range(0, fat_count):
    450450                outf.seek(cluster_size + i * fat_size)
    451                 for j in range(0, fat_size / fatent_size):
     451                for j in range(0, fat_size // fatent_size):
    452452                        fat_entry.next = fat[j]
    453453                        outf.write(fat_entry.pack())
  • tools/mkhord.py

    r458619f7 r28f4adb  
    5252def usage(prname):
    5353        "Print usage syntax"
    54         print prname + " <ALIGNMENT> <FS_IMAGE> <HORD_IMAGE>"
     54        print(prname + " <ALIGNMENT> <FS_IMAGE> <HORD_IMAGE>")
    5555
    5656def main():
     
    6060       
    6161        if (not sys.argv[1].isdigit()):
    62                 print "<ALIGNMENT> must be a number"
     62                print("<ALIGNMENT> must be a number")
    6363                return
    6464       
    6565        align = int(sys.argv[1], 0)
    6666        if (align <= 0):
    67                 print "<ALIGNMENT> must be positive"
     67                print("<ALIGNMENT> must be positive")
    6868                return
    6969       
    7070        fs_image = os.path.abspath(sys.argv[2])
    7171        if (not os.path.isfile(fs_image)):
    72                 print "<FS_IMAGE> must be a file"
     72                print("<FS_IMAGE> must be a file")
    7373                return
    7474       
    75         inf = file(fs_image, "rb")
    76         outf = file(sys.argv[3], "wb")
     75        inf = open(fs_image, "rb")
     76        outf = open(sys.argv[3], "wb")
    7777       
    7878        header = xstruct.create(HEADER)
  • tools/mktmpfs.py

    r458619f7 r28f4adb  
    6666def usage(prname):
    6767        "Print usage syntax"
    68         print prname + " <PATH> <IMAGE>"
     68        print(prname + " <PATH> <IMAGE>")
    6969
    7070def recursion(root, outf):
     
    8585                        outf.write(dentry.pack())
    8686                       
    87                         inf = file(canon, "r")
     87                        inf = open(canon, "rb")
    8888                        rd = 0;
    8989                        while (rd < size):
     
    116116        path = os.path.abspath(sys.argv[1])
    117117        if (not os.path.isdir(path)):
    118                 print "<PATH> must be a directory"
     118                print("<PATH> must be a directory")
    119119                return
    120120       
    121         outf = file(sys.argv[2], "w")
     121        outf = open(sys.argv[2], "wb")
    122122       
    123123        header = xstruct.create(HEADER)
  • tools/mkuimage.py

    r458619f7 r28f4adb  
    7272                        start_addr = (int)(optarg, 0)
    7373                else:
    74                         print base_name + ": Unrecognized option."
     74                        print(base_name + ": Unrecognized option.")
    7575                        print_syntax(cmd_name)
    7676                        return
    7777
    7878        if len(args) < 2:
    79                 print base_name + ": Argument missing."
     79                print(base_name + ": Argument missing.")
    8080                print_syntax(cmd_name)
    8181                return
     
    9191
    9292def mkuimage(inf_name, outf_name, image_name, load_addr, start_addr):
    93         inf = file(inf_name, 'rb')
    94         outf = file(outf_name, 'wb')
     93        inf = open(inf_name, 'rb')
     94        outf = open(outf_name, 'wb')
    9595
    9696        header = xstruct.create(UIMAGE_HEADER)
     
    140140        signed_crc = zlib.crc32(byteseq, 0)
    141141        if signed_crc < 0:
    142                 return (long(signed_crc) + 4294967296L) # 2^32L
     142                return (long(signed_crc) + (long(2) ** long(32))) # 2^32L
    143143        else:
    144144                return signed_crc
     
    147147#
    148148def print_syntax(cmd):
    149         print "syntax: " + cmd + " [<options>] <raw_image> <uImage>"
     149        print("syntax: " + cmd + " [<options>] <raw_image> <uImage>")
    150150        print
    151         print "\traw_image\tInput image name (raw binary data)"
    152         print "\tuImage\t\tOutput uImage name (U-Boot image)"
     151        print("\traw_image\tInput image name (raw binary data)")
     152        print("\tuImage\t\tOutput uImage name (U-Boot image)")
    153153        print
    154         print "options:"
    155         print "\t-name <name>\tImage name (default: 'Noname')"
    156         print "\t-laddr <name>\tLoad address (default: 0x00000000)"
    157         print "\t-saddr <name>\tStart address (default: 0x00000000)"
     154        print("options:")
     155        print("\t-name <name>\tImage name (default: 'Noname')")
     156        print("\t-laddr <name>\tLoad address (default: 0x00000000)")
     157        print("\t-saddr <name>\tStart address (default: 0x00000000)")
    158158
    159159if __name__ == '__main__':
  • tools/pack.py

    r458619f7 r28f4adb  
    4343def usage(prname):
    4444        "Print usage syntax"
    45         print "%s <OBJCOPY> <FORMAT> <ARCH> <ARCH_PATH> [COMPONENTS ...]" % prname
     45        print("%s <OBJCOPY> <FORMAT> <ARCH> <ARCH_PATH> [COMPONENTS ...]" % prname)
    4646
    4747def deflate(data):
     
    110110                symbol = "_binary_%s" % basename.replace(".", "_")
    111111               
    112                 print "%s -> %s" % (component, obj)
     112                print("%s -> %s" % (component, obj))
    113113               
    114                 comp_in = file(component, "rb")
     114                comp_in = open(component, "rb")
    115115                comp_data = comp_in.read()
    116116                comp_in.close()
     
    121121               
    122122                try:
    123                         comp_out = file(basename, "wb")
     123                        comp_out = open(basename, "wb")
    124124                        comp_out.write(comp_deflate)
    125125                        comp_out.close()
     
    151151                cnt += 1
    152152       
    153         header = file(os.path.join(arch_path, "include", "%s.h" % COMPONENTS), "w")
     153        header = open(os.path.join(arch_path, "include", "%s.h" % COMPONENTS), "w")
    154154       
    155155        header.write('/***************************************\n')
     
    173173        header.close()
    174174       
    175         data = file(os.path.join(arch_path, "src", "%s.c" % COMPONENTS), "w")
     175        data = open(os.path.join(arch_path, "src", "%s.c" % COMPONENTS), "w")
    176176       
    177177        data.write('/***************************************\n')
     
    187187        data.close()
    188188       
    189         link_in = file(os.path.join(arch_path, "%s.in" % LINK), "r")
     189        link_in = open(os.path.join(arch_path, "%s.in" % LINK), "r")
    190190        template = link_in.read()
    191191        link_in.close()
    192192       
    193         link_out = file(os.path.join(arch_path, "%s.comp" % LINK), "w")
     193        link_out = open(os.path.join(arch_path, "%s.comp" % LINK), "w")
    194194        link_out.write(template.replace("[[COMPONENTS]]", "\n".join(link_ctx)))
    195195        link_out.close()
Note: See TracChangeset for help on using the changeset viewer.