def do(config): """ Effectively run the rsync steps once all the checks have been done """ # Check that all required variables are defined. common.var_check(config, ['publish_src_folder', 'publish_dst_folder']) command = ['rsync', '-avz', '--exclude', '*~'] # Get the value stored in extra args and check it is a list extra_args = config.get('publish_extra_args') if extra_args != None: if not isinstance(extra_args, list): print 'ERROR: Variable publish_extra_args must have a list' sys.exit(1) # Append to end of command command.extend(extra_args) # Append the rest of options. command.extend( [config['publish_src_folder'], config['publish_dst_folder']]) if config['debug']: print 'Executing command', ' '.join(command) subprocess.check_call(command)
def do(config): """ Effectively run the rsync steps once all the checks have been done """ # Check that all required variables are defined. common.var_check(config, ['publish_src_folder', 'publish_dst_folder']) command = [ 'rsync', '-avz', '--exclude', '*~'] # Get the value stored in extra args and check it is a list extra_args = config.get('publish_extra_args') if extra_args != None: if not isinstance(extra_args, list): print 'ERROR: Variable publish_extra_args must have a list' sys.exit(1) # Append to end of command command.extend(extra_args) # Append the rest of options. command.extend([ config['publish_src_folder'], config['publish_dst_folder'] ]) if config['debug']: print 'Executing command', ' '.join(command) subprocess.check_call(command)
def do(config): """ Refresh a version number in a given file. """ # Check that all required variables are defined. common.var_check(config, ['version_file', 'version_re', 'version_tag']) if not os.path.exists(config['version_file']) or \ not os.path.isfile(config['version_file']): print 'ERROR:', config['version_file'], 'is not a correct file' sys.exit(1) new_content = '' # New file content matched = False # To detect if a match occurs with open(config['version_file']) as f: for line in f: match = re.match(config['version_re'], line) # If there was a match, treat the line specially if match != None: # Leave a mark that the line was detected matched = True value = match.groupdict().get('tag') # If the match has not a number field, terminate. if value == None: print 'Regular expression in version_re must contain a', print 'field named <tag>.' sys.exit(1) # Replace the tag with a new one. if config['debug']: print 'Replacing', value, 'with', config['version_tag'], print 'in file', config['version_file'] line = line.replace(value, config['version_tag']) new_content += line f.close() # If there was a match, update the file. if matched: with open(config['version_file'], 'w') as f: f.write(new_content) f.close() # If no match was detected, warn else: print 'WARNING: No line matched the given regular expression', print '(var version_re in the conf file)' print 'No changes done to the file.' return
def do(config): """ Effectively run the sanity check once all the checks have been done """ # Check that all required variables are defined. common.var_check(config, ['sanity_src_folder', 'sanity_files', 'sanity_detect']) # Detect all files that match the filter matches = [] for root, dirnames, filenames in os.walk(config['sanity_src_folder']): for filename in fnmatch.filter(filenames, config['sanity_files']): matches.append(os.path.join(root, filename)) # Print the number of files to be processed if config['debug']: print "{:,}".format(len(matches)), 'files to be processed' print "{:,}".format(len(config['sanity_detect'])), print 'expressions to be tested' # Loop over all detected file names total_lines = 0 for filename in matches: with open(filename) as f: line_number = 1 # Loop over all lines in a file for line in f: # Loop over all the given regular expressions for expression in config['sanity_detect']: if re.search(expression, line) != None: print 'Incorrect expression detected in file', print filename, 'line', line_number line_number += 1 f.close() total_lines += line_number if config['debug']: print "{:,}".format(total_lines), 'text lines inspected.' print "{:,}".format(total_lines * len(matches) * len(config['sanity_detect'])), 'checks.' return
def check_branch(config): """ Effectively run the sanity check once all the checks have been done """ # Check that all required variables are defined. common.var_check(config, ['git_root_folder']) repo_dir = config['git_root_folder'] repo = git.Repo(repo_dir) assert not repo.bare if repo.head.ref.name != 'master': print 'Repository in', repo_dir, 'not in master branch.' print 'Terminating' sys.exit(1) if config['debug']: print 'Repository in master branch' return
def do(config): """ Effectively run the linkchecker from a folder. """ # Check that all required variables are defined. common.var_check(config, ['linkchecker_src_folder', 'linkchecker_ignore_urls']) command = [ 'linkchecker', '-a', ] command.extend(['--ignore-url=' + x for x in config['linkchecker_ignore_urls']]) command.append(config['linkchecker_src_folder']) print 'Executing command', ' '.join(command) subprocess.check_call(command) return