def getProperty(self, rule, option): """ Try to get a pair rule/option from the ConfigParser in the object. If it does not exist, check if the rule has the form name.subname. If so, check for the option name/option. """ return properties.getProperty(self.options, rule, option)
def findExecutable(rule, dirObj): """ Function to search if an executable is available in the machine. Lifted from StackOverflow and modified to account for possible executable suffixes stored in Windows in the environment variable PATHEXT. """ # Get the program name program = properties.getProperty(dirObj.options, rule, 'exec') suffixes = [''] pext = os.environ.get("PATHEXT") if pext: suffixes = pext.split(';') def is_exe(fpath, suffixes): # Return the first executable when concatenating a suffix return next((fpath + s for s in suffixes \ if os.path.exists(fpath + s) and \ os.access(fpath + s, os.X_OK)), None) fpath, fname = os.path.split(program) if fpath: return is_exe(program, suffixes) # Return the first executable when traversing the path for path in os.environ["PATH"].split(os.pathsep): executable = is_exe(os.path.join(path, program), suffixes) # If found, return it if executable != None: properties.setProperty(dirObj.options, rule, 'exec', executable) return executable return None
def helpRule(rule, dirObj, moduleName, pad = None): """ Check if the requested rule is help Return boolean stating if it has been executed """ # Detect if any of the special rule has been detected hit = False # Calculate the rule prefix (up to the last dot) (prefix, b, c) = rule.rpartition('.') if re.match('.+[^\.]\.help$', rule): print i18n.get('doc_preamble').format(prefix) print properties.getProperty(dirObj.options, prefix, 'help') hit = True return hit
def evaluateCondition(rule, options): """ Evaluates the following condition with the given options (conjunction) 1) option "enable_open" is '1' 2) option "enable_begin" is empty or is a datetime before now 3) option "enable_end" is empty or is a datetime past now 4) If "adagio.enabled_profiles" is empty or contains the value of option "rule.enable_profile" The function returns the conjunction of these 5 rules. """ # Check part 1 of the rule: open must be 1 if properties.getProperty(options, rule, 'enable_open') != '1': print i18n.get('enable_not_open').format(openData) return False # Get current date/time now = datetime.datetime.now() # Get the date_format dateFormat = properties.getProperty(options, rule, 'enable_date_format') # Check part 2 of the rule: begin date is before current date beginDate = properties.getProperty(options, rule, 'enable_begin') if beginDate != '': if checkDateFormat(beginDate, dateFormat) < now: print i18n.get('enable_closed_begin').format(beginDate) return False # Check part 3 of the rule: end date is after current date endDate = properties.getProperty(options, rule, 'enable_end') if endDate != '': if now < checkDateFormat(endDate, dateFormat): print i18n.get('enable_closed_end').format(endDate) return False # Check part 4 of the rule: rule.enable_profile must be in # adagio.enabled_profiles revisionsData = properties.getProperty(options, 'adagio', 'enabled_profiles') thisRevision = properties.getProperty(options, rule, 'enable_profile') if revisionsData != '' and thisRevision != '': if not (thisRevision in set(revisionsData.split())): print i18n.get('enable_not_revision').format(rule, thisRevision, revisionsData) return False return True