-
Notifications
You must be signed in to change notification settings - Fork 174
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1449 from clinton-hall/release-11.7
Release 11.07
- Loading branch information
Showing
5 changed files
with
107 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
from __future__ import print_function | ||
|
||
import subprocess | ||
import sys | ||
|
||
|
||
def git_clean(remove_directories=False, force=False, dry_run=False, interactive=False, quiet=False, exclude=None, | ||
ignore_rules=False, clean_ignored=False, paths=None): | ||
"""Execute git clean commands.""" | ||
command = ['git', 'clean'] | ||
if remove_directories: | ||
command.append('-d') | ||
if force: | ||
command.append('--force') | ||
if interactive: | ||
command.append('--interactive') | ||
if quiet: | ||
command.append('--quiet') | ||
if dry_run: | ||
command.append('--dry-run') | ||
if exclude: | ||
try: | ||
exclude = exclude.split(' ') | ||
except AttributeError: | ||
pass | ||
for exclusion in exclude: | ||
command.append('--exclude={pattern}'.format(pattern=exclusion)) | ||
if ignore_rules: | ||
command.append('-x') | ||
if clean_ignored: | ||
command.append('-X') | ||
if paths: | ||
try: | ||
paths = paths.split(' ') | ||
except AttributeError: | ||
pass | ||
command.extend(paths) | ||
return subprocess.check_output(command) | ||
|
||
|
||
def clean_bytecode(): | ||
"""Clean bytecode files.""" | ||
try: | ||
result = git_clean( | ||
remove_directories=True, | ||
force=True, | ||
exclude=[ | ||
'*.*', # exclude everything | ||
'!*.py[co]', # except bytecode | ||
'!**/__pycache__/', # and __pycache__ folders | ||
], | ||
) | ||
except subprocess.CalledProcessError as error: | ||
sys.exit(error.returncode) | ||
else: | ||
return result | ||
|
||
|
||
def clean_folders(*paths): | ||
"""Clean obsolete folders.""" | ||
try: | ||
result = git_clean( | ||
remove_directories=True, | ||
force=True, | ||
ignore_rules=True, | ||
paths=paths, | ||
) | ||
except subprocess.CalledProcessError as error: | ||
sys.exit(error.returncode) | ||
else: | ||
return result | ||
|
||
|
||
def clean(*paths): | ||
"""Clean up bytecode and obsolete folders.""" | ||
print('-- Cleaning bytecode --') | ||
result = clean_bytecode() | ||
print(result or 'No bytecode to clean\n') | ||
if paths: | ||
print('-- Cleaning folders: {} --'.format(paths)) | ||
result = clean_folders(*paths) | ||
print(result or 'No folders to clean\n') | ||
|
||
|
||
if __name__ == '__main__': | ||
clean('libs', 'core') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters