mirror of
https://github.com/flatcar/scripts.git
synced 2025-09-21 05:31:05 +02:00
build_library: Convert python2 scripts to python3
This is just a conversion done by 2to3 with a manual updates of shebangs to mention python3 explicitly. The fixups for bytearray vs string issues will follow up.
This commit is contained in:
parent
df63498a91
commit
336a967941
@ -1,4 +1,4 @@
|
||||
#!/usr/bin/python
|
||||
#!/usr/bin/python3
|
||||
# Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
|
||||
# Use of this source code is governed by a BSD-style license that can be
|
||||
# found in the LICENSE file.
|
||||
@ -66,9 +66,9 @@ def LoadPartitionConfig(options):
|
||||
raise InvalidLayout('Metadata is missing required entries: %s' % e)
|
||||
|
||||
def VerifyLayout(layout_name, layout, base=None):
|
||||
for part_num, part in layout.iteritems():
|
||||
for part_num, part in layout.items():
|
||||
part['num'] = int(part_num)
|
||||
part_keys = set(part.iterkeys())
|
||||
part_keys = set(part.keys())
|
||||
unknown_keys = part_keys - valid_layout_keys
|
||||
if unknown_keys:
|
||||
raise InvalidLayout('Unknown items in partition %s %s: %r' %
|
||||
@ -79,7 +79,7 @@ def LoadPartitionConfig(options):
|
||||
|
||||
if base:
|
||||
part_base = base.get(part_num, {})
|
||||
part_keys.update(part_base.iterkeys())
|
||||
part_keys.update(iter(part_base.keys()))
|
||||
|
||||
if part.get('type', None) == 'blank':
|
||||
continue
|
||||
@ -122,12 +122,12 @@ def LoadPartitionConfig(options):
|
||||
# Fill in default values from base,
|
||||
# dict doesn't have a update()+setdefault() method so this looks tedious
|
||||
if base:
|
||||
for part_num, base_part in base.iteritems():
|
||||
for part_num, base_part in base.items():
|
||||
part = layout.setdefault(part_num, {})
|
||||
for base_key, base_value in base_part.iteritems():
|
||||
for base_key, base_value in base_part.items():
|
||||
part.setdefault(base_key, base_value)
|
||||
|
||||
for part_num, part in sorted(layout.iteritems(), key=lambda t: int(t[0])):
|
||||
for part_num, part in sorted(iter(layout.items()), key=lambda t: int(t[0])):
|
||||
if part['type'] == 'blank':
|
||||
continue
|
||||
|
||||
@ -163,7 +163,7 @@ def LoadPartitionConfig(options):
|
||||
# Verify 'base' before other layouts because it is inherited by the others
|
||||
# Fill in extra/default values in base last so they aren't inherited
|
||||
VerifyLayout('base', base)
|
||||
for layout_name, layout in config['layouts'].iteritems():
|
||||
for layout_name, layout in config['layouts'].items():
|
||||
if layout_name == 'base':
|
||||
continue
|
||||
VerifyLayout(layout_name, layout, base)
|
||||
@ -225,7 +225,7 @@ def GetPartitionTableFromImage(options, config, partitions):
|
||||
else:
|
||||
part['image_compat'] = False
|
||||
|
||||
for part in partitions.itervalues():
|
||||
for part in partitions.values():
|
||||
if part.get('type', 'blank') == 'blank':
|
||||
continue
|
||||
if not part.get('image_exists', False):
|
||||
@ -240,7 +240,7 @@ def GetPartitionTableFromImage(options, config, partitions):
|
||||
part['image_fs_type'] = None
|
||||
|
||||
# Set compat flags for any partition not in the image
|
||||
for part in partitions.itervalues():
|
||||
for part in partitions.values():
|
||||
part.setdefault('image_exists', False)
|
||||
if part.get('type', 'blank') == 'blank':
|
||||
part.setdefault('image_compat', True)
|
||||
@ -269,7 +269,7 @@ def WritePartitionTable(options, config=None, partitions=None):
|
||||
else:
|
||||
# If we are not creating a fresh image all partitions must be compatible.
|
||||
GetPartitionTableFromImage(options, config, partitions)
|
||||
if not all(p['image_compat'] for p in partitions.itervalues()):
|
||||
if not all(p['image_compat'] for p in partitions.values()):
|
||||
raise InvalidLayout("New disk layout is incompatible existing image")
|
||||
|
||||
# Extend the disk image size as needed
|
||||
@ -279,7 +279,7 @@ def WritePartitionTable(options, config=None, partitions=None):
|
||||
|
||||
hybrid = None
|
||||
prioritize = []
|
||||
for partition in partitions.itervalues():
|
||||
for partition in partitions.values():
|
||||
if partition['type'] != 'blank':
|
||||
Cgpt('add', '-i', partition['num'],
|
||||
'-b', partition['first_block'],
|
||||
@ -469,8 +469,8 @@ def PartitionLoop(options, partition):
|
||||
|
||||
|
||||
def FormatPartition(options, part):
|
||||
print "Formatting partition %s (%s) as %s" % (
|
||||
part['num'], part['label'], part['fs_type'])
|
||||
print("Formatting partition %s (%s) as %s" % (
|
||||
part['num'], part['label'], part['fs_type']))
|
||||
|
||||
with PartitionLoop(options, part) as loop_dev:
|
||||
if part['fs_type'] in ('ext2', 'ext4'):
|
||||
@ -497,7 +497,7 @@ def Format(options):
|
||||
config, partitions = LoadPartitionConfig(options)
|
||||
WritePartitionTable(options, config, partitions)
|
||||
|
||||
for part in partitions.itervalues():
|
||||
for part in partitions.values():
|
||||
if part['type'] == 'blank' or 'fs_type' not in part:
|
||||
continue
|
||||
|
||||
@ -542,13 +542,13 @@ def Update(options):
|
||||
config, partitions = LoadPartitionConfig(options)
|
||||
WritePartitionTable(options, config, partitions)
|
||||
|
||||
for part in partitions.itervalues():
|
||||
for part in partitions.values():
|
||||
if not part.get('fs_type', None):
|
||||
continue
|
||||
elif not part['image_fs_type']:
|
||||
FormatPartition(options, part)
|
||||
|
||||
for part in partitions.itervalues():
|
||||
for part in partitions.values():
|
||||
resize_func = None
|
||||
if not part.get('fs_type', None):
|
||||
continue
|
||||
@ -561,8 +561,8 @@ def Update(options):
|
||||
else:
|
||||
continue
|
||||
|
||||
print "Resizing partition %s (%s) to %s bytes" % (
|
||||
part['num'], part['label'], part['fs_bytes'])
|
||||
print("Resizing partition %s (%s) to %s bytes" % (
|
||||
part['num'], part['label'], part['fs_bytes']))
|
||||
|
||||
with PartitionLoop(options, part) as loop_dev:
|
||||
resize_func(part, loop_dev)
|
||||
@ -582,7 +582,7 @@ def Mount(options):
|
||||
GetPartitionTableFromImage(options, config, partitions)
|
||||
mounts = {}
|
||||
|
||||
for part_num, part in partitions.iteritems():
|
||||
for part_num, part in partitions.items():
|
||||
path = part.get('mount', None)
|
||||
if not path or not path.startswith('/'):
|
||||
continue
|
||||
@ -625,7 +625,7 @@ def Mount(options):
|
||||
if err is not None:
|
||||
raise err
|
||||
|
||||
for src, dst in mount.get('binds', {}).iteritems():
|
||||
for src, dst in mount.get('binds', {}).items():
|
||||
# src may be relative or absolute, os.path.join handles this.
|
||||
full_src = os.path.realpath(
|
||||
options.mount_dir + os.path.join(mount['mount'], src))
|
||||
@ -650,11 +650,11 @@ def ReadWriteSubvol(options, partition, disable_rw):
|
||||
"""
|
||||
|
||||
if disable_rw:
|
||||
print "Disabling read-write on default subvolume of partition %s (%s)" % (
|
||||
partition['num'], partition['label'])
|
||||
print("Disabling read-write on default subvolume of partition %s (%s)" % (
|
||||
partition['num'], partition['label']))
|
||||
else:
|
||||
print "Enabling read-write on default subvolume of partition %s (%s)" % (
|
||||
partition['num'], partition['label'])
|
||||
print("Enabling read-write on default subvolume of partition %s (%s)" % (
|
||||
partition['num'], partition['label']))
|
||||
|
||||
with PartitionLoop(options, partition) as loop_dev:
|
||||
btrfs_mount = tempfile.mkdtemp()
|
||||
@ -701,11 +701,11 @@ def Tune2fsReadWrite(options, partition, disable_rw):
|
||||
"""
|
||||
|
||||
if disable_rw:
|
||||
print "Disabling read-write mounting of partition %s (%s)" % (
|
||||
partition['num'], partition['label'])
|
||||
print("Disabling read-write mounting of partition %s (%s)" % (
|
||||
partition['num'], partition['label']))
|
||||
else:
|
||||
print "Enabling read-write mounting of partition %s (%s)" % (
|
||||
partition['num'], partition['label'])
|
||||
print("Enabling read-write mounting of partition %s (%s)" % (
|
||||
partition['num'], partition['label']))
|
||||
|
||||
# offset of ro_compat, highest order byte (le 32 bit field)
|
||||
flag_offset = 0x464 + 3
|
||||
@ -767,7 +767,7 @@ def Verity(options):
|
||||
config, partitions = LoadPartitionConfig(options)
|
||||
GetPartitionTableFromImage(options, config, partitions)
|
||||
|
||||
for part_num, part in partitions.iteritems():
|
||||
for part_num, part in partitions.items():
|
||||
if 'verity' not in part.get('features', []):
|
||||
continue
|
||||
|
||||
@ -848,7 +848,7 @@ def GetPartitionByLabel(partitions, label):
|
||||
Returns:
|
||||
An object for the selected partition
|
||||
"""
|
||||
for partition in partitions.itervalues():
|
||||
for partition in partitions.values():
|
||||
if partition['type'] == 'blank':
|
||||
continue
|
||||
elif partition['label'] == label:
|
||||
@ -882,7 +882,7 @@ def GetBlockSize(options):
|
||||
"""
|
||||
|
||||
config, partitions = LoadPartitionConfig(options)
|
||||
print config['metadata']['block_size']
|
||||
print(config['metadata']['block_size'])
|
||||
|
||||
|
||||
def GetFilesystemBlockSize(options):
|
||||
@ -897,7 +897,7 @@ def GetFilesystemBlockSize(options):
|
||||
"""
|
||||
|
||||
config, partitions = LoadPartitionConfig(options)
|
||||
print config['metadata']['fs_block_size']
|
||||
print(config['metadata']['fs_block_size'])
|
||||
|
||||
|
||||
def GetPartitionSize(options):
|
||||
@ -911,7 +911,7 @@ def GetPartitionSize(options):
|
||||
|
||||
partitions = GetPartitionTableFromConfig(options)
|
||||
partition = GetPartitionByNumber(partitions, options.partition_num)
|
||||
print partition['bytes']
|
||||
print(partition['bytes'])
|
||||
|
||||
|
||||
def GetFilesystemSize(options):
|
||||
@ -927,7 +927,7 @@ def GetFilesystemSize(options):
|
||||
|
||||
partitions = GetPartitionTableFromConfig(options)
|
||||
partition = GetPartitionByNumber(partitions, options.partition_num)
|
||||
print partition.get('fs_bytes', partition['bytes'])
|
||||
print(partition.get('fs_bytes', partition['bytes']))
|
||||
|
||||
|
||||
def GetLabel(options):
|
||||
@ -941,7 +941,7 @@ def GetLabel(options):
|
||||
|
||||
partitions = GetPartitionTableFromConfig(options)
|
||||
partition = GetPartitionByNumber(partitions, options.partition_num)
|
||||
print partition.get('label', 'UNTITLED')
|
||||
print(partition.get('label', 'UNTITLED'))
|
||||
|
||||
|
||||
def GetNum(options):
|
||||
@ -955,7 +955,7 @@ def GetNum(options):
|
||||
|
||||
partitions = GetPartitionTableFromConfig(options)
|
||||
partition = GetPartitionByLabel(partitions, options.label)
|
||||
print partition.get('num', '-1')
|
||||
print(partition.get('num', '-1'))
|
||||
|
||||
|
||||
def GetUuid(options):
|
||||
@ -969,7 +969,7 @@ def GetUuid(options):
|
||||
|
||||
partitions = GetPartitionTableFromConfig(options)
|
||||
partition = GetPartitionByLabel(partitions, options.label)
|
||||
print partition.get('uuid', '')
|
||||
print(partition.get('uuid', ''))
|
||||
|
||||
|
||||
def DoDebugOutput(options):
|
||||
@ -983,7 +983,7 @@ def DoDebugOutput(options):
|
||||
"""
|
||||
partitions = GetPartitionTableFromConfig(options)
|
||||
|
||||
for num, partition in sorted(partitions.iteritems()):
|
||||
for num, partition in sorted(partitions.items()):
|
||||
if partition['type'] != 'blank':
|
||||
if partition['bytes'] < 1024 * 1024:
|
||||
size = '%d bytes' % partition['bytes']
|
||||
@ -994,11 +994,11 @@ def DoDebugOutput(options):
|
||||
fs_size = '%d bytes' % partition['fs_bytes']
|
||||
else:
|
||||
fs_size = '%d MB' % (partition['fs_bytes'] / 1024 / 1024)
|
||||
print '%s: %s - %s/%s' % (num, partition['label'], fs_size, size)
|
||||
print('%s: %s - %s/%s' % (num, partition['label'], fs_size, size))
|
||||
else:
|
||||
print '%s: %s - %s' % (num, partition['label'], size)
|
||||
print('%s: %s - %s' % (num, partition['label'], size))
|
||||
else:
|
||||
print '%s: blank' % num
|
||||
print('%s: blank' % num)
|
||||
|
||||
|
||||
def DoParseOnly(options):
|
||||
|
@ -1,4 +1,4 @@
|
||||
#!/usr/bin/python
|
||||
#!/usr/bin/python3
|
||||
'''Scan an existing directory tree and record installed directories.
|
||||
|
||||
During build a number of directories under /var are created in the state
|
||||
@ -82,7 +82,7 @@ def main():
|
||||
fd.write('\n'.join(config)+'\n')
|
||||
fd.close()
|
||||
else:
|
||||
print '\n'.join(config)
|
||||
print('\n'.join(config))
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
@ -1,4 +1,4 @@
|
||||
#!/usr/bin/python
|
||||
#!/usr/bin/python3
|
||||
|
||||
# Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
|
||||
# Use of this source code is governed by a BSD-style license that can be
|
||||
@ -120,7 +120,7 @@ def DepsToCopy(ldd_files, allow_list):
|
||||
proc = subprocess.Popen(cmd, stdout=subprocess.PIPE,
|
||||
stderr=subprocess.PIPE)
|
||||
(stdout_data, stderr_data) = proc.communicate(input=None)
|
||||
except subprocess.CalledProcessError, e:
|
||||
except subprocess.CalledProcessError as e:
|
||||
logging.error('Command %s failed', cmd)
|
||||
logging.error('error code %s', e.returncode)
|
||||
logging.error('ouput %s', e.output)
|
||||
@ -153,7 +153,7 @@ def CopyRequiredFiles(dest_files_root, allow_list):
|
||||
sys.exit(1)
|
||||
|
||||
all_files = DYNAMIC_EXECUTABLES + STATIC_FILES
|
||||
all_files = map(os.path.expanduser, all_files)
|
||||
all_files = list(map(os.path.expanduser, all_files))
|
||||
|
||||
for file_name in all_files:
|
||||
if not os.path.isfile(file_name):
|
||||
@ -181,7 +181,7 @@ def CopyRequiredFiles(dest_files_root, allow_list):
|
||||
logging.exception("Copying '%s' to %s failed", file_name, lib_dir)
|
||||
sys.exit(1)
|
||||
|
||||
for source_dir, target_dir in RECURSE_DIRS.iteritems():
|
||||
for source_dir, target_dir in RECURSE_DIRS.items():
|
||||
logging.debug('Processing directory %s', source_dir)
|
||||
full_path = os.path.expanduser(source_dir)
|
||||
if not os.path.isdir(full_path):
|
||||
@ -212,7 +212,7 @@ def WrapExecutableFiles(dest_files_root, ld_linux):
|
||||
local_exec_wrapped = local_exec + ".bin"
|
||||
shutil.move(local_exec, local_exec_wrapped)
|
||||
|
||||
fd = os.open(local_exec, os.O_WRONLY | os.O_CREAT, 0733)
|
||||
fd = os.open(local_exec, os.O_WRONLY | os.O_CREAT, 0o733)
|
||||
with os.fdopen(fd, 'w') as script:
|
||||
script.write('#!/bin/sh\n')
|
||||
script.write('# Auto-generated wrapper script\n')
|
||||
@ -249,7 +249,7 @@ def GenerateZipFile(base_name, root_dir):
|
||||
try:
|
||||
subprocess.Popen(['zip', '-r', '-9', base_name, '.'],
|
||||
stdout=subprocess.PIPE).communicate()[0]
|
||||
except OSError, e:
|
||||
except OSError as e:
|
||||
logging.error('Execution failed:%s', e.strerror)
|
||||
return False
|
||||
finally:
|
||||
|
@ -1,4 +1,4 @@
|
||||
#!/usr/bin/python
|
||||
#!/usr/bin/python3
|
||||
|
||||
import hashlib
|
||||
import json
|
||||
|
@ -1,4 +1,4 @@
|
||||
#!/usr/bin/python
|
||||
#!/usr/bin/python3
|
||||
|
||||
import hashlib
|
||||
import json
|
||||
@ -10,4 +10,4 @@ version=sys.argv[2]
|
||||
|
||||
with open(path, "rb") as f:
|
||||
kernel = f.read()
|
||||
print json.dumps({"9": {"binaryvalues": [{"prefix": "grub_linux", "values": [{"value": hashlib.sha1(kernel).hexdigest(), "description": "flatcar-%s" % version}]}]}})
|
||||
print(json.dumps({"9": {"binaryvalues": [{"prefix": "grub_linux", "values": [{"value": hashlib.sha1(kernel).hexdigest(), "description": "flatcar-%s" % version}]}]}}))
|
||||
|
Loading…
x
Reference in New Issue
Block a user