def main(): parser = build_argparser() opts = parser.parse_args(sys.argv[1:]) # Process all the files xml_strs = [] filespecs = opts.filespecs[:] for filespec in filespecs: # A concrete .info file: if isfile(filespec): f = InfoFile.from_info_file(filespec) f.location = opts.location xml_strs.append(f.to_xml_str()) elif isdir(filespec): filespecs.extend(glob(os.path.join(filespec, "*.info"))) if opts.recurse: # Also add all the subdirectories filespecs.extend(d for d in os.listdir(filespec) if isdir(d)) # Output appropriately if getattr(opts, "append", None): raise NotImplementedError if opts.output is None: opts.output = "updates.xml" outfile = file(opts.output, "w") outfile.write("\n".join(xml_strs) + "\n") outfile.close()
def main(): parser = build_argparser() opts = parser.parse_args(sys.argv[1:]) filespecs = opts.filespecs[:] for filespec in filespecs: infofile_name = filespec + ".info" # Regular file if isfile(filespec): # Handle .info files if filespec.endswith(".info") and not opts.include_info: continue if not opts.quiet: if isfile(infofile_name): if not opts.all: print "[Skip]\t\t", else: print "[Replaced]\t", else: print "\t\t", print infofile_name if not isfile(infofile_name) or opts.all: # Create a new .info file try: info = InfoFile.from_target_file(filespec) f = file(infofile_name, "w") f.write(info.to_info_str()) f.close() except IOError, e: print " [Error]" print str(e) else: # Skip this file continue # Handle globs elif ('*' in filespec) or ('?' in filespec): filespecs.extend(glob(filespec))
def files2xml(filenames): """ Given a list of filenames, extracts the app version and log information from accompanying files produces an output xml string. There are no constraints or restrictions on the names or extensions of the input files. They just need to be accompanied by a sidecar file named similarly, but with a ".info" extension, that can be loaded by the InfoFile class. If there is no .info file for a filename or an error occurs while constructing it a warning message is printed. """ _xmlheader = """<?xml version="1.0" encoding="ISO-8859-1"?> <!-- DO NOT EDIT MANUALLY --> <!-- Automatically generated file using enthought.util.updates --> """ xmlparts = [_xmlheader] for file in filenames: #info_file_name = "{0}.info".format(file) info_file_name = "%s.info" % (file, ) if not os.path.exists(info_file_name): #print "Warning: {0} was not found.".format(info_file_name) print "Warning: %s was not found." % (info_file_name, ) continue try: info = InfoFile.from_info_file(info_file_name) xml_list = info.get_xml() except: #print "Warning: Failure in creating XML for {0}".format(info_file_name) print "Warning: Failure in creating XML for %s" % ( info_file_name, ) continue xmlparts.append('<update_file>') xmlparts.extend(xml_list) xmlparts.append('</update_file>') return "\n".join(xmlparts)
def files2xml(filenames): """ Given a list of filenames, extracts the app version and log information from accompanying files produces an output xml string. There are no constraints or restrictions on the names or extensions of the input files. They just need to be accompanied by a sidecar file named similarly, but with a ".info" extension, that can be loaded by the InfoFile class. If there is no .info file for a filename or an error occurs while constructing it a warning message is printed. """ _xmlheader = """<?xml version="1.0" encoding="ISO-8859-1"?> <!-- DO NOT EDIT MANUALLY --> <!-- Automatically generated file using enthought.util.updates --> """ xmlparts = [_xmlheader] for file in filenames: #info_file_name = "{0}.info".format(file) info_file_name = "%s.info" % (file,) if not os.path.exists(info_file_name): #print "Warning: {0} was not found.".format(info_file_name) print "Warning: %s was not found." % (info_file_name,) continue try: info = InfoFile.from_info_file(info_file_name) xml_list = info.get_xml() except: #print "Warning: Failure in creating XML for {0}".format(info_file_name) print "Warning: Failure in creating XML for %s" % (info_file_name,) continue xmlparts.append('<update_file>') xmlparts.extend(xml_list) xmlparts.append('</update_file>') return "\n".join(xmlparts)