add verbose output to checkout command

This commit is contained in:
Frédéric Péters 2021-04-30 11:06:59 +02:00
parent 608cc8e61b
commit 74a56a9c0f
1 changed files with 7 additions and 9 deletions

View File

@ -10,7 +10,8 @@ from scrutiny.projects.models import Module
class Command(BaseCommand):
help = 'Create checkouts of modules'
def handle(self, *args, **options):
def handle(self, verbosity, *args, **options):
self.verbose = int(verbosity) > 1
checkouts_directory = os.path.join(settings.MEDIA_ROOT, 'src')
if not os.path.exists(checkouts_directory):
os.mkdir(checkouts_directory)
@ -21,18 +22,15 @@ class Command(BaseCommand):
checkout_dir = os.path.join(checkouts_directory, module.name)
kws = {}
kws['stdout'] = subprocess.PIPE
kws['stderr'] = subprocess.STDOUT
if not os.path.exists(checkout_dir):
# full clone
cmd = ['git', 'clone', module.repository_url, module.name]
kws['cwd'] = checkouts_directory
cwd = checkouts_directory
else:
# pull
cmd = ['git', 'pull']
kws['cwd'] = checkout_dir
cwd = checkout_dir
p = subprocess.Popen(cmd, **kws)
p.communicate()
p.wait()
if self.verbose:
print('- ' + module.name)
subprocess.run(cmd, capture_output=not (self.verbose), cwd=cwd)