def get_entities(pattern, relative_to): """get_entities(pattern, relative_to) -> list_of_tuples Returns a list of (entity_name,file_path) tuples, one for each file that matches glob pattern. file_path is relative to directory relative_to. """ files = glob.glob(pattern) files.sort() # relative_to should always be specified, unless the path will just be # discarded later on if relative_to != None: # Make paths relative for i in range(len(files)): files[i] = make_relative_path( from_dir = relative_to, to_dir = files[i], ) entities = [] # Determine entity names and then create Entity objects for file in files: # Strip leading directories name = os.path.basename(file) # Strip extension name = re.sub(r"\.[^.]+$", "", name) # Create Entity object entities.append(Entity(name, file)) return entities
def get_entities(pattern, relative_to): """get_entities(pattern, relative_to) -> list_of_tuples Returns a list of (entity_name,file_path) tuples, one for each file that matches glob pattern. file_path is relative to directory relative_to. """ files = glob.glob(pattern) files.sort() # relative_to should always be specified, unless the path will just be # discarded later on if relative_to != None: # Make paths relative for i in range(len(files)): files[i] = make_relative_path( from_dir=relative_to, to_dir=files[i], ) entities = [] # Determine entity names and then create Entity objects for file in files: # Strip leading directories name = os.path.basename(file) # Strip extension name = re.sub(r"\.[^.]+$", "", name) # Create Entity object entities.append(Entity(name, file)) return entities
elems.sort() #------------------------------------------------------------------------------ # Now we actually do what was requested of us :) #------------------------------------------------------------------------------ if ops == []: print "***** Error: no operation specified\n" usage() for op in ops: if "list-missing" == op: print "Elements in %s for which there is no file matching %s:" % ( make_relative_path(os.curdir,dtd_filename), make_relative_path(os.curdir,pattern), ) missing_file_elements = find_missing_elements(elems, pattern) if len(missing_file_elements): for elem in missing_file_elements: print " " + elem # else: # print "(None)" elif "create-missing" == op: template_text = open(template_file, "r").read() missing_elems = find_missing_elements(elems, pattern)