Changeset View
Changeset View
Standalone View
Standalone View
scap/utils.py
Show First 20 Lines • Show All 183 Lines • ▼ Show 20 Lines | with open(os.devnull, 'wb') as dev_null: | ||||
remote = subprocess.check_output( | remote = subprocess.check_output( | ||||
('/usr/bin/git', 'remote'), | ('/usr/bin/git', 'remote'), | ||||
cwd=repo_directory, stderr=dev_null).strip() | cwd=repo_directory, stderr=dev_null).strip() | ||||
return subprocess.check_output( | return subprocess.check_output( | ||||
('/usr/bin/git', 'merge-base', 'HEAD', remote), | ('/usr/bin/git', 'merge-base', 'HEAD', remote), | ||||
cwd=repo_directory, stderr=dev_null).strip() | cwd=repo_directory, stderr=dev_null).strip() | ||||
def git_describe(location): | |||||
"""Returns a convenient label for the current state of the git repo.""" | |||||
ensure_git_dir(location) | |||||
with cd(location): | |||||
cmd = '/usr/bin/git describe --always' | |||||
return subprocess.check_output(cmd, shell=True).strip() | |||||
def git_info(directory): | def git_info(directory): | ||||
"""Compute git version information for a given directory that is | """Compute git version information for a given directory that is | ||||
compatible with MediaWiki's GitInfo class. | compatible with MediaWiki's GitInfo class. | ||||
:param directory: Directory to scan for git information | :param directory: Directory to scan for git information | ||||
:returns: Dict of information about current repository state | :returns: Dict of information about current repository state | ||||
""" | """ | ||||
git_dir = os.path.join(directory, '.git') | git_dir = os.path.join(directory, '.git') | ||||
▲ Show 20 Lines • Show All 477 Lines • ▼ Show 20 Lines | if pattern == '*' or pattern == 'all': | ||||
return hosts | return hosts | ||||
# If pattern is a regex, handle that and return | # If pattern is a regex, handle that and return | ||||
if pattern[0] == '~': | if pattern[0] == '~': | ||||
regex = re.compile(pattern[1:]) | regex = re.compile(pattern[1:]) | ||||
return [target for target in hosts if regex.match(target)] | return [target for target in hosts if regex.match(target)] | ||||
# Handle replacements of anything like [*:*] in pattern | # Handle replacements of anything like [*:*] in pattern | ||||
has_range = lambda x: 0 <= x.find('[') < x.find(':') < x.find(']') | has_range = lambda x: 0 <= x.find('[') < x.find(':') < x.find(']') | ||||
Lint: PEP8 E731: do not assign a lambda expression, use a def | |||||
patterns = [] | patterns = [] | ||||
rpattern = pattern | rpattern = pattern | ||||
while(has_range(rpattern)): | while(has_range(rpattern)): | ||||
head, nrange, tail = rpattern.replace( | head, nrange, tail = rpattern.replace( | ||||
'[', '|', 1).replace(']', '|', 1).split('|') | '[', '|', 1).replace(']', '|', 1).split('|') | ||||
beg, end = nrange.split(':') | beg, end = nrange.split(':') | ||||
▲ Show 20 Lines • Show All 41 Lines • Show Last 20 Lines |
Content licensed under Creative Commons Attribution-ShareAlike 3.0 (CC-BY-SA) unless otherwise noted; code licensed under GNU General Public License (GPL) or other open source licenses. By using this site, you agree to the Terms of Use, Privacy Policy, and Code of Conduct. · Wikimedia Foundation · Privacy Policy · Code of Conduct · Terms of Use · Disclaimer · CC-BY-SA · GPL
do not assign a lambda expression, use a def