def remove_trailing_spaces_walker(arguments, directory_name, names): """ Walker method to be used by the path walker for the removal of trailing spaces and newlines. :type arguments: Tuple :param arguments: The arguments tuple sent by the walker method. :type directory_name: String :param directory_name: The name of the current directory in the walk. :type names: List :param names: The list of names in the current directory. """ # unpacks the arguments tuple tab_to_spaces, trailing_newlines, windows_newline,\ file_extensions, file_exclusion = arguments # tries to run the handle ignore operation for the current set of names and # in case there's a processing returns the control flow immediately as no # more handling is meant to occur for the current operation (ignored) if extra.handle_ignore(names): return # removes the complete set of names that are meant to be excluded from the # current set names to be visit (avoid visiting them) for exclusion in file_exclusion: if not exclusion in names: continue names.remove(exclusion) # retrieves the valid names for the names list (removes directory entries) valid_complete_names = [ directory_name + "/" + name for name in names\ if not os.path.isdir(directory_name + "/" + name) ] # filters the names with non valid file extensions valid_complete_names = [ os.path.normpath(name) for name in valid_complete_names\ if file_extensions == None or os.path.split(name)[-1].split(".")[-1] in file_extensions ] # creates the string based value of the windows newline taking into # account the boolean value of it windows_newline_s = "windows newline" if windows_newline else "unix newline" # iterates over all the valid complete names with extension filter for valid_complete_name in valid_complete_names: # prints a message about the operation to be performed extra.echo("Removing trail in file: %s (%s)" % (valid_complete_name, windows_newline_s)) # removes the trailing spaces for the (path) name remove_trailing_spaces(valid_complete_name, tab_to_spaces, windows_newline) # in case the trailing newlines flag is active if trailing_newlines: # prints a message about the operation to be performed extra.echo("Removing trail newlines in file: %s" % valid_complete_name) # removes the trailing newlines for the(path) name remove_trailing_newlines(valid_complete_name, windows_newline)
def cleanup_stylesheets_walker(arguments, directory_name, names): """ Walker method to be used by the path walker for the cleanup of stylesheets. :type arguments: Tuple :param arguments: The arguments tuple sent by the walker method. :type directory_name: String :param directory_name: The name of the current directory in the walk. :type names: List :param names: The list of names in the current directory. """ # unpacks the arguments tuple windows_newline, fix_extra_newlines, property_order,\ rules_skip, file_extensions, file_exclusion = arguments # tries to run the handle ignore operation for the current set of names and # in case there's a processing returns the control flow immediately as no # more handling is meant to occur for the current operation (ignored) if extra.handle_ignore(names): return # removes the complete set of names that are meant to be excluded from the # current set names to be visit (avoid visiting them) for exclusion in file_exclusion: if not exclusion in names: continue names.remove(exclusion) # retrieves the valid names for the names list (removes directory entries) valid_complete_names = [ directory_name + "/" + name for name in names\ if not os.path.isdir(directory_name + "/" + name) ] # filters the names with non valid file extensions so that valid_complete_names = [ os.path.normpath(name) for name in valid_complete_names\ if file_extensions == None or os.path.split(name)[-1].split(".")[-1] in file_extensions ] # iterates over all the valid complete names with extension filter for valid_complete_name in valid_complete_names: extra.echo("Cleaning stylesheet file: %s" % valid_complete_name) # removes the cleanups the stylesheet for the (path) name cleanup_stylesheets( valid_complete_name, windows_newline, fix_extra_newlines, property_order, rules_skip )
def misc_walker(arguments, directory_name, names): """ Walker method to be used by the path walker for running the normalization misc process. :type arguments: Tuple :param arguments: The arguments tuple sent by the walker method. :type directory_name: String :param directory_name: The name of the current directory in the walk. :type names: List :param names: The list of names in the current directory. """ # unpacks the arguments tuple into its values file_exclusion, configuration = arguments # retrieves the complete set of extensions registered for the chmod # operations and then gathers their keys as the basis for the extension # based filtering operations (optimization) chmod = configuration.get("chmod", {}) extensions = legacy.keys(chmod) extensions = tuple(extensions) # tries to run the handle ignore operation for the current set of names and # in case there's a processing returns the control flow immediately as no # more handling is meant to occur for the current operation (ignored) if extra.handle_ignore(names): return # removes the complete set of names that are meant to be excluded from the # current set names to be visit (avoid visiting them) for exclusion in file_exclusion: if not exclusion in names: continue names.remove(exclusion) # retrieves the valid names for the names list (removes directory entries) valid_complete_names = [directory_name + "/" + name for name in names\ if not os.path.isdir(directory_name + "/" + name)] # filters the names with non valid file extensions so that only the # ones that conform with the misc source ones are selected valid_complete_names = [os.path.normpath(name) for name in valid_complete_names\ if name.endswith(tuple(extensions))] # iterates over all the valid complete names with valid structure # as defined by the misc file structure definition for valid_complete_name in valid_complete_names: # print a message a message about the misc # operation that is going to be performed and # then runs the operation with the correct path extra.echo("Running the misc operations on file: %s" % valid_complete_name) misc_file(valid_complete_name, configuration)
def jssource_walker(arguments, directory_name, names): """ Walker method to be used by the path walker for running the normalization jssource process. :type arguments: Tuple :param arguments: The arguments tuple sent by the walker method. :type directory_name: String :param directory_name: The name of the current directory in the walk. :type names: List :param names: The list of names in the current directory. """ # unpacks the arguments tuple file_exclusion, = arguments # tries to run the handle ignore operation for the current set of names and # in case there's a processing returns the control flow immediately as no # more handling is meant to occur for the current operation (ignored) if extra.handle_ignore(names): return # removes the complete set of names that are meant to be excluded from the # current set names to be visit (avoid visiting them) for exclusion in file_exclusion: if not exclusion in names: continue names.remove(exclusion) # retrieves the valid names for the names list (removes directory entries) valid_complete_names = [directory_name + "/" + name for name in names\ if not os.path.isdir(directory_name + "/" + name)] # filters the names with non valid file extensions so that only the # ones that conform with the javascript source ones are selected valid_complete_names = [os.path.normpath(name) for name in valid_complete_names\ if name.endswith((".js", ".json"))] # iterates over all the valid complete names with valid structure # as defined by the javascript file structure definition for valid_complete_name in valid_complete_names: # print a message a message about the jssource # operation that is going to be performed and # then runs the operation with the correct path extra.echo("Transforming javascript source file: %s" % valid_complete_name) jssource_file(valid_complete_name)
def join_files_walker(arguments, directory_name, names): """ Walker method to be used by the path walker for the joining of the files. :type arguments: Tuple :param arguments: The arguments tuple sent by the walker method. :type directory_name: String :param directory_name: The name of the current directory in the walk. :type names: List :param names: The list of names in the current directory. """ # unpacks the arguments tuple file_exclusion, = arguments # tries to run the handle ignore operation for the current set of names and # in case there's a processing returns the control flow immediately as no # more handling is meant to occur for the current operation (ignored) if extra.handle_ignore(names): return # removes the complete set of names that are meant to be excluded from the # current set names to be visit (avoid visiting them) for exclusion in file_exclusion: if not exclusion in names: continue names.remove(exclusion) # retrieves the valid names for the names list (removes directory entries) valid_complete_names = [directory_name + "/" + name for name in names\ if not os.path.isdir(directory_name + "/" + name)] # filters the names with non valid file extensions so that only the # ones that contain the join extension are used valid_complete_names = [os.path.normpath(name) for name in valid_complete_names\ if len(name.split(".")) > 1 and name.split(".")[-2] == "join"\ and name.split(".")[-1] == "json"] # iterates over all the valid complete names with extension filter for valid_complete_name in valid_complete_names: # print a message a message about the joining # operation that is going to be performed and # then runs the operation with the correct path extra.echo("Joining files defined in file: %s" % valid_complete_name) join_files(valid_complete_name)
def convert_encoding_walker(arguments, directory_name, names): """ Walker method to be used by the path walker for the encoding conversion. :type arguments: Tuple :param arguments: The arguments tuple sent by the walker method. :type directory_name: String :param directory_name: The name of the current directory in the walk. :type names: List :param names: The list of names in the current directory. """ # unpacks the arguments tuple source_encoding, target_encoding, windows_newline,\ replacements_list, file_extensions, file_exclusion = arguments # tries to run the handle ignore operation for the current set of names and # in case there's a processing returns the control flow immediately as no # more handling is meant to occur for the current operation (ignored) if extra.handle_ignore(names): return # removes the complete set of names that are meant to be excluded from the # current set names to be visit (avoid visiting them) for exclusion in file_exclusion: if not exclusion in names: continue names.remove(exclusion) # retrieves the valid names for the names list (removes directory entries) valid_complete_names = [directory_name + "/" + name\ for name in names if not os.path.isdir(directory_name + "/" + name)] # filters the names with non valid file extensions valid_complete_names = [os.path.normpath(name) for name in valid_complete_names\ if file_extensions == None or os.path.split(name)[-1].split(".")[-1] in file_extensions] # creates the string based value of the windows newline taking into # account the boolean value of it windows_newline_s = "windows newline" if windows_newline else "unix newline" # iterates over all the valid complete names with extension filter # to convert the respective file into the target encoding for valid_complete_name in valid_complete_names: # prints a message about the file that is not going to be converted # into the proper target encoding as defined in the specification extra.echo( "Convert encoding in file: %s (%s to %s) (%s)" %\ ( valid_complete_name, source_encoding, target_encoding, windows_newline_s ) ) try: # converts the encoding for the provided (path) name according to # a set of defined options, for various reasons this operation may # fail if such thing happens the operation is skipped convert_encoding( valid_complete_name, source_encoding, target_encoding, windows_newline, replacements_list ) except Exception: extra.warn( "Failed converting encoding in file: %s (%s to %s)" %\ ( valid_complete_name, source_encoding, target_encoding ) )