From 1e9717757dd2cfb753731b7421ae9a092ef84747 Mon Sep 17 00:00:00 2001 From: Serge Rehbinder Date: Wed, 17 Feb 2016 15:24:44 +0100 Subject: [PATCH] rename all the function to be pep0008 compliant --- commands/config.py | 22 +++++++++++----------- commands/log.py | 11 +++++------ salomeTools.py | 8 ++++---- src/logger.py | 20 ++++++++++---------- src/xmlManager.py | 2 +- 5 files changed, 31 insertions(+), 32 deletions(-) diff --git a/commands/config.py b/commands/config.py index 72edb28..c5439ad 100644 --- a/commands/config.py +++ b/commands/config.py @@ -52,10 +52,10 @@ class ConfigOpener: if os.path.isabs(name): return src.pyconf.ConfigInputStream(open(name, 'rb')) else: - return src.pyconf.ConfigInputStream( open(os.path.join( self.getPath(name), name ), 'rb') ) + return src.pyconf.ConfigInputStream( open(os.path.join( self.get_path(name), name ), 'rb') ) raise IOError(_("Configuration file '%s' not found") % name) - def getPath( self, name ): + def get_path( self, name ): '''The method that returns the entire path of the pyconf searched :param name str: The name of the searched pyconf. ''' @@ -145,7 +145,7 @@ class ConfigManager: over.extend(filter(lambda l: l.startswith(section + "."), options.overwrite)) return over - def getConfig(self, application=None, options=None, command=None, dataDir=None): + def get_config(self, application=None, options=None, command=None, dataDir=None): '''get the config from all the configuration files. :param application str: The application for which salomeTools is called. @@ -263,8 +263,8 @@ class ConfigManager: # ======================================================================================= # load USER config - self.setUserConfigFile(cfg) - user_cfg_file = self.getUserConfigFile() + self.set_user_config_file(cfg) + user_cfg_file = self.get_user_config_file() user_cfg = src.pyconf.Config(open(user_cfg_file)) merger.merge(cfg, user_cfg) @@ -274,7 +274,7 @@ class ConfigManager: return cfg - def setUserConfigFile(self, config): + def set_user_config_file(self, config): '''Set the user config file name and path. If necessary, build it from another one or create it from scratch. @@ -286,9 +286,9 @@ class ConfigManager: # if pyconf does not exist, create it from scratch if not os.path.isfile(self.user_config_file_path): - self.createConfigFile(config) + self.create_config_file(config) - def createConfigFile(self, config): + def create_config_file(self, config): '''This method is called when there are no user config file. It build it from scratch. :param config class 'src.pyconf.Config': The global config. @@ -296,7 +296,7 @@ class ConfigManager: :rtype: config class 'src.pyconf.Config' ''' - cfg_name = self.getUserConfigFile() + cfg_name = self.get_user_config_file() user_cfg = src.pyconf.Config() # @@ -326,13 +326,13 @@ class ConfigManager: return user_cfg - def getUserConfigFile(self): + def get_user_config_file(self): '''Get the user config file :return: path to the user config file. :rtype: str ''' if not self.user_config_file_path: - raise src.SatException(_("Error in getUserConfigFile: missing user config file path")) + raise src.SatException(_("Error in get_user_config_file: missing user config file path")) return self.user_config_file_path diff --git a/commands/log.py b/commands/log.py index dab5d09..ba593ce 100644 --- a/commands/log.py +++ b/commands/log.py @@ -4,7 +4,6 @@ import os import shutil import re -import gettext # Compatibility python 2/3 for input function # input stays input for python 3 and input = raw_input for python 2 @@ -22,7 +21,7 @@ parser.add_option('l', 'last', 'boolean', 'last', "Show the log of the last laun parser.add_option('f', 'full', 'boolean', 'full', "Show the logs of ALL launched commands.") parser.add_option('c', 'clean', 'int', 'clean', "Erase the n most ancient log files.") -def getLastLogFile(logDir, notShownCommands): +def get_last_log_file(logDir, notShownCommands): '''Used in case of last option. Get the last log command file path. :param logDir str: The directory where to search the log files @@ -114,7 +113,7 @@ def run(args, runner, logger): if options.clean: nbClean = options.clean # get the list of files to remove - lLogs = src.logger.listLogFile(logDir, src.logger.logCommandFileExpression) + lLogs = src.logger.list_log_file(logDir, src.logger.logCommandFileExpression) nbLogFiles = len(lLogs) # Delete all if the invoked number is bigger than the number of log files if nbClean > nbLogFiles: @@ -137,10 +136,10 @@ def run(args, runner, logger): # If the user asks for a terminal display if options.terminal: # Parse the log directory in order to find all the files corresponding to the commands - lLogs = src.logger.listLogFile(logDir, src.logger.logCommandFileExpression) + lLogs = src.logger.list_log_file(logDir, src.logger.logCommandFileExpression) lLogsFiltered = [] for filePath, _, date, _, hour, cmd in lLogs: - showLog, cmdAppli = src.logger.showcommandLog(filePath, cmd, runner.cfg.VARS.application, notShownCommands) + showLog, cmdAppli = src.logger.show_command_log(filePath, cmd, runner.cfg.VARS.application, notShownCommands) if showLog: lLogsFiltered.append((filePath, date, hour, cmd, cmdAppli)) @@ -179,7 +178,7 @@ def run(args, runner, logger): # If the last option is invoked, just, show the last log file if options.last: - lastLogFilePath = getLastLogFile(logDir, notShownCommands) + lastLogFilePath = get_last_log_file(logDir, notShownCommands) # open the log xml file in the user editor src.system.show_in_editor(runner.cfg.USER.browser, lastLogFilePath, logger) return 0 diff --git a/salomeTools.py b/salomeTools.py index bc5f8aa..65d909e 100755 --- a/salomeTools.py +++ b/salomeTools.py @@ -140,7 +140,7 @@ class Sat(object): # read the configuration from all the pyconf files cfgManager = config.ConfigManager() - self.cfg = cfgManager.getConfig(dataDir=self.dataDir, application=appliToLoad, options=self.options, command=__nameCmd__) + self.cfg = cfgManager.get_config(dataDir=self.dataDir, application=appliToLoad, options=self.options, command=__nameCmd__) # set output level if self.options.output_level: @@ -159,7 +159,7 @@ class Sat(object): finally: # put final attributes in xml log file (end time, total time, ...) and write it launchedCommand = ' '.join([self.cfg.VARS.salometoolsway + os.path.sep + 'sat', self.arguments.split(' ')[0], args]) - logger_command.endWrite({"launchedCommand" : launchedCommand}) + logger_command.end_write({"launchedCommand" : launchedCommand}) return res @@ -185,7 +185,7 @@ class Sat(object): command = opt[0] # read the configuration from all the pyconf files cfgManager = config.ConfigManager() - self.cfg = cfgManager.getConfig(dataDir=self.dataDir) + self.cfg = cfgManager.get_config(dataDir=self.dataDir) # Check if this command exists if not hasattr(self, command): @@ -225,7 +225,7 @@ def print_version(): ''' # read the config cfgManager = config.ConfigManager() - cfg = cfgManager.getConfig() + cfg = cfgManager.get_config() # print the key corresponding to salomeTools version print(src.printcolors.printcHeader( _("Version: ") ) + cfg.INTERNAL.sat_version + '\n') diff --git a/src/logger.py b/src/logger.py index 19a53ac..5a19ab2 100644 --- a/src/logger.py +++ b/src/logger.py @@ -55,12 +55,12 @@ class Logger(object): self.txtFileName = txtFileName self.txtFilePath = txtFilePath # Initialize xml instance and put first fields like beginTime, user, command, etc... - self.xmlFile = xmlManager.xmlLogFile(logFilePath, "SATcommand", attrib = {"application" : config.VARS.application}) - self.putInitialXMLFields() + self.xmlFile = xmlManager.XmlLogFile(logFilePath, "SATcommand", attrib = {"application" : config.VARS.application}) + self.put_initial_xml_fields() # Initialize the txt file for reading self.logTxtFile = open(str(self.txtFilePath), 'w') - def putInitialXMLFields(self): + def put_initial_xml_fields(self): '''Method called at class initialization : Put all fields corresponding to the command context (user, time, ...) ''' # command name @@ -129,7 +129,7 @@ class Logger(object): ''' sys.stdout.flush() - def endWrite(self, attribute): + def end_write(self, attribute): '''Method called just after command end : Put all fields corresponding to the command end context (time). Write the log xml file on the hard drive. And display the command to launch to get the log @@ -184,7 +184,7 @@ def timedelta_total_seconds(timedelta): timedelta.microseconds + 0.0 + (timedelta.seconds + timedelta.days * 24 * 3600) * 10 ** 6) / 10 ** 6 -def showcommandLog(logFilePath, cmd, application, notShownCommands): +def show_command_log(logFilePath, cmd, application, notShownCommands): '''Used in updateHatXml. Determine if the log xml file logFilePath has to be shown or not in the hat log. :param logFilePath str: the path to the command xml log file @@ -216,7 +216,7 @@ def showcommandLog(logFilePath, cmd, application, notShownCommands): return False, None -def listLogFile(dirPath, expression): +def list_log_file(dirPath, expression): '''Find all files corresponding to expression in dirPath :param dirPath str: the directory where to search the files @@ -246,13 +246,13 @@ def update_hat_xml(logDir, application=None, notShownCommands = []): :param logDir str: the directory to parse :param application str: the name of the application if there is any ''' - # Create an instance of xmlLogFile class to create hat.xml file + # Create an instance of XmlLogFile class to create hat.xml file xmlHatFilePath = os.path.join(logDir, 'hat.xml') - xmlHat = src.xmlManager.xmlLogFile(xmlHatFilePath, "LOGlist", {"application" : application}) + xmlHat = src.xmlManager.XmlLogFile(xmlHatFilePath, "LOGlist", {"application" : application}) # parse the log directory to find all the command logs, then add it to the xml file - lLogFile = listLogFile(logDir, logCommandFileExpression) + lLogFile = list_log_file(logDir, logCommandFileExpression) for filePath, _, date, _, hour, cmd in lLogFile: - showLog, cmdAppli = showcommandLog(filePath, cmd, application, notShownCommands) + showLog, cmdAppli = show_command_log(filePath, cmd, application, notShownCommands) #if cmd not in notShownCommands: if showLog: # add a node to the hat.xml file diff --git a/src/xmlManager.py b/src/xmlManager.py index 0572b74..76ad6e0 100644 --- a/src/xmlManager.py +++ b/src/xmlManager.py @@ -21,7 +21,7 @@ import os import src from . import ElementTree as etree -class xmlLogFile(object): +class XmlLogFile(object): '''Class to manage writing in salomeTools xml log file ''' def __init__(self, filePath, rootname, attrib = {}): -- 2.39.2