Catalogs: Converted all print statements into Python 3 compatible functions.

This commit is contained in:
Edward d'Auvergne 2019-11-18 10:06:24 +01:00
parent 3b1a3c51b1
commit 5d3fcd3ba0
3 changed files with 30 additions and 30 deletions

View File

@ -104,7 +104,7 @@ def scan_set_file(aircraft_dir, set_file, includes):
if sim_node.hasChild('minimum-fg-version'): if sim_node.hasChild('minimum-fg-version'):
variant['minimum-fg-version'] = sim_node.getValue('minimum-fg-version', None) variant['minimum-fg-version'] = sim_node.getValue('minimum-fg-version', None)
#print ' ', variant #print(" %s" % variant)
return variant return variant
def extract_previews(previews_node, aircraft_dir): def extract_previews(previews_node, aircraft_dir):
@ -143,13 +143,13 @@ def scan_aircraft_dir(aircraft_dir, includes):
files = os.listdir(aircraft_dir) files = os.listdir(aircraft_dir)
for file in sorted(files, key=lambda s: s.lower()): for file in sorted(files, key=lambda s: s.lower()):
if file.endswith('-set.xml'): if file.endswith('-set.xml'):
# print 'trying:', file # print('trying: %s' % file)
try: try:
d = scan_set_file(aircraft_dir, file, includes) d = scan_set_file(aircraft_dir, file, includes)
if d == None: if d == None:
continue continue
except: except:
print "Skipping set file since couldn't be parsed:", os.path.join(aircraft_dir, file), sys.exc_info()[0] print("Skipping set file since couldn't be parsed: %s %s" % os.path.join(aircraft_dir, file), sys.exc_info()[0])
continue continue
setDicts.append(d) setDicts.append(d)
@ -159,13 +159,13 @@ def scan_aircraft_dir(aircraft_dir, includes):
elif d['variant-of'] == None: elif d['variant-of'] == None:
primaryAircraft.append(d) primaryAircraft.append(d)
# print setDicts # print(setDicts)
if len(setDicts) == 0: if len(setDicts) == 0:
return None, None return None, None
# use the first one # use the first one
if len(primaryAircraft) == 0: if len(primaryAircraft) == 0:
print "Aircraft has no primary aircraft at all:", aircraft_dir print("Aircraft has no primary aircraft at all: %s" % aircraft_dir)
primaryAircraft = [setDicts[0]] primaryAircraft = [setDicts[0]]
package = primaryAircraft[0] package = primaryAircraft[0]
@ -217,8 +217,8 @@ def append_author_nodes(node, info):
node.append( make_xml_leaf('author', info['author']) ) node.append( make_xml_leaf('author', info['author']) )
def make_aircraft_node(aircraftDirName, package, variants, downloadBase, mirrors): def make_aircraft_node(aircraftDirName, package, variants, downloadBase, mirrors):
#print "package:", package #print("package: %s" % package)
#print "variants:", variants #print("variants: %s" % variants)
package_node = ET.Element('package') package_node = ET.Element('package')
package_node.append( make_xml_leaf('name', package['name']) ) package_node.append( make_xml_leaf('name', package['name']) )
package_node.append( make_xml_leaf('status', package['status']) ) package_node.append( make_xml_leaf('status', package['status']) )

View File

@ -133,9 +133,9 @@ class Node(object):
elif isinstance(self._value, bool): elif isinstance(self._value, bool):
n.set('type', "bool") n.set('type', "bool")
except UnicodeEncodeError: except UnicodeEncodeError:
print "Encoding error with", self._value, type(self._value) print("Encoding error with %s %s" % (self._value, type(self._value)))
except: except:
print "Some other exceptiong in sgprops._createXMLElement()" print("Some other exceptiong in sgprops._createXMLElement()")
# index in parent # index in parent
if (self.index != 0): if (self.index != 0):
@ -194,7 +194,7 @@ class PropsHandler(handler.ContentHandler):
try: try:
index = int(attrs['n']) index = int(attrs['n'])
except: except:
print "Invalid index at line:", self._locator.getLineNumber(), "of", self._path print("Invalid index at line: %s of %s" % (self._locator.getLineNumber(), self._path))
raise IndexError("Invalid index at line:", self._locator.getLineNumber(), "of", self._path) raise IndexError("Invalid index at line:", self._locator.getLineNumber(), "of", self._path)
currentState.recordExplicitIndex(name, index) currentState.recordExplicitIndex(name, index)
@ -251,7 +251,7 @@ class PropsHandler(handler.ContentHandler):
self._content = self._content[:-1] self._content = self._content[:-1]
self._current.value = float(self._content) self._current.value = float(self._content)
except: except:
print "Parse error for value:", self._content, "at line:", self._locator.getLineNumber(), "of:", self._path print("Parse error for value: %s at line: %s of: %s" % (self._content, self._locator.getLineNumber(), self._path))
self._current = self._current.parent self._current = self._current.parent
self._content = None self._content = None

View File

@ -82,7 +82,7 @@ def copy_previews_for_variant(variant, package_name, package_dir, previews_dir):
for preview in variant['previews']: for preview in variant['previews']:
preview_src = os.path.join(package_dir, preview['path']) preview_src = os.path.join(package_dir, preview['path'])
preview_dst = os.path.join(previews_dir, package_name + '_' + preview['path']) preview_dst = os.path.join(previews_dir, package_name + '_' + preview['path'])
#print preview_src, preview_dst, preview['path'] #print(preview_src, preview_dst, preview['path'])
dir = os.path.dirname(preview_dst) dir = os.path.dirname(preview_dst)
if not os.path.isdir(dir): if not os.path.isdir(dir):
os.makedirs(dir) os.makedirs(dir)
@ -129,11 +129,11 @@ def process_aircraft_dir(name, repo_path):
(package, variants) = catalog.scan_aircraft_dir(aircraft_dir, includes) (package, variants) = catalog.scan_aircraft_dir(aircraft_dir, includes)
if package == None: if package == None:
if not args.quiet: if not args.quiet:
print "skipping:", name, "(no -set.xml files)" print("skipping: %s (no -set.xml files)" % name)
return return
if not args.quiet: if not args.quiet:
print "%s:" % name, print("%s:" % name)
package_node = make_aircraft_node(name, package, variants, download_base, mirrors) package_node = make_aircraft_node(name, package, variants, download_base, mirrors)
@ -154,8 +154,8 @@ def process_aircraft_dir(name, repo_path):
d = datetime.datetime.utcfromtimestamp(dir_mtime) d = datetime.datetime.utcfromtimestamp(dir_mtime)
rev = d.strftime("%Y%m%d") rev = d.strftime("%Y%m%d")
package_node.append( catalog.make_xml_leaf('revision', rev) ) package_node.append( catalog.make_xml_leaf('revision', rev) )
#print "rev:", rev #print("rev: %s" % rev)
#print "dir mtime:", dir_mtime #print("dir mtime: %s" % dir_mtime)
zipfile = os.path.join( output_dir, name + '.zip' ) zipfile = os.path.join( output_dir, name + '.zip' )
valid_zips.append(name + '.zip') valid_zips.append(name + '.zip')
if not os.path.exists(zipfile) \ if not os.path.exists(zipfile) \
@ -163,12 +163,12 @@ def process_aircraft_dir(name, repo_path):
or args.clean: or args.clean:
# rebuild zip file # rebuild zip file
if not args.quiet: if not args.quiet:
print "updating:", zipfile print("updating: %s" % zipfile)
make_aircraft_zip(repo_path, name, zipfile, zip_excludes, verbose=not args.quiet) make_aircraft_zip(repo_path, name, zipfile, zip_excludes, verbose=not args.quiet)
md5sum = get_md5sum(zipfile) md5sum = get_md5sum(zipfile)
else: else:
if not args.quiet: if not args.quiet:
print "(no change)" print("(no change)")
if md5sum == "": if md5sum == "":
md5sum = get_md5sum(zipfile) md5sum = get_md5sum(zipfile)
filesize = os.path.getsize(zipfile) filesize = os.path.getsize(zipfile)
@ -189,7 +189,7 @@ def process_aircraft_dir(name, repo_path):
shared_md5 = get_xml_text(sharedNode) shared_md5 = get_xml_text(sharedNode)
if shared_md5 == md5sum: if shared_md5 == md5sum:
if not args.quiet: if not args.quiet:
print "Sharing zip with share catalog for:",name print("Sharing zip with share catalog for: %s" % name)
os.remove(zipfile) os.remove(zipfile)
os.symlink(os.path.join( share_output_dir, name + '.zip' ), zipfile) os.symlink(os.path.join( share_output_dir, name + '.zip' ), zipfile)
@ -210,7 +210,7 @@ def process_aircraft_dir(name, repo_path):
# return (md5, file_size) # return (md5, file_size)
if not os.path.isdir(args.dir): if not os.path.isdir(args.dir):
print "A valid catalog directory must be provided" print("A valid catalog directory must be provided")
exit(0) exit(0)
parser = ET.XMLParser(remove_blank_text=True) parser = ET.XMLParser(remove_blank_text=True)
@ -229,7 +229,7 @@ else:
share_output_dir = get_xml_text(config_node.find('share-output')) share_output_dir = get_xml_text(config_node.find('share-output'))
share_md5_file = get_xml_text(config_node.find('share-md5-sums')) share_md5_file = get_xml_text(config_node.find('share-md5-sums'))
if share_output_dir != '' and share_md5_file != '': if share_output_dir != '' and share_md5_file != '':
print 'Output shared with:', share_output_dir print("Output shared with: %s" % share_output_dir)
share_md5sum_tree = ET.parse(share_md5_file, parser) share_md5sum_tree = ET.parse(share_md5_file, parser)
share_md5sum_root = share_md5sum_tree.getroot() share_md5sum_root = share_md5sum_tree.getroot()
else: else:
@ -271,13 +271,13 @@ zip_excludes = os.path.realpath(tmp)
for i in config_node.findall("include-dir"): for i in config_node.findall("include-dir"):
path = get_xml_text(i) path = get_xml_text(i)
if not os.path.exists(path): if not os.path.exists(path):
print "Skipping missing include path:", path print("Skipping missing include path: %s" % path)
continue continue
includes.append(path) includes.append(path)
# freshen repositories # freshen repositories
if args.no_update: if args.no_update:
print 'Skipping repository updates.' print('Skipping repository updates.')
else: else:
cwd = os.getcwd() cwd = os.getcwd()
for scm in scm_list: for scm in scm_list:
@ -292,16 +292,16 @@ else:
includes.append(repo_path) includes.append(repo_path)
if repo_type == 'svn': if repo_type == 'svn':
print 'SVN update:', repo_path print("SVN update: %s" % repo_path)
subprocess.call(['svn', 'update', repo_path]) subprocess.call(['svn', 'update', repo_path])
elif repo_type == 'git': elif repo_type == 'git':
print 'GIT pull:', repo_path print("GIT pull: %s" % repo_path)
os.chdir(repo_path) os.chdir(repo_path)
subprocess.call(['git','pull']) subprocess.call(['git','pull'])
elif repo_type == 'no-scm': elif repo_type == 'no-scm':
print "No update of unmannaged files:", repo_path print("No update of unmannaged files: %s" % repo_path)
else: else:
print "Unknown scm type:", scm, repo_path print("Unknown scm type: %s %s" % (scm, repo_path))
os.chdir(cwd) os.chdir(cwd)
# names of zip files we want (so we can identify/remove orphans) # names of zip files we want (so we can identify/remove orphans)
@ -343,7 +343,7 @@ for scm in scm_list:
continue continue
# process each aircraft in turn # process each aircraft in turn
# print name, repo_path # print("%s %s" % (name, repo_path))
process_aircraft_dir(name, repo_path) process_aircraft_dir(name, repo_path)
# write out the master catalog file # write out the master catalog file
@ -351,11 +351,11 @@ cat_file = os.path.join(output_dir, 'catalog.xml')
catalog_root.write(cat_file, encoding='utf-8', xml_declaration=True, pretty_print=True) catalog_root.write(cat_file, encoding='utf-8', xml_declaration=True, pretty_print=True)
# write out the md5sum cache file # write out the md5sum cache file
print md5sum_file print(md5sum_file)
md5sum_tree.write(md5sum_file, encoding='utf-8', xml_declaration=True, pretty_print=True) md5sum_tree.write(md5sum_file, encoding='utf-8', xml_declaration=True, pretty_print=True)
# look for orphaned zip files # look for orphaned zip files
files = os.listdir(output_dir) files = os.listdir(output_dir)
for file in files: for file in files:
if file.endswith('.zip')and not file in valid_zips: if file.endswith('.zip')and not file in valid_zips:
print "orphaned zip:", file print("orphaned zip: %s" % file)