Skip to content

Commit ba7e1f3

Browse files
committed
changes to improve interfacing with the backup scripts
- Legacy-Id: 18442
1 parent f4fd4b1 commit ba7e1f3

1 file changed

Lines changed: 17 additions & 10 deletions

File tree

ietf/doc/management/commands/find_github_backup_info.py

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from urllib.parse import urlparse
88

99
from django.conf import settings
10-
from django.core.management.base import BaseCommand
10+
from django.core.management.base import BaseCommand, CommandError
1111

1212
from ietf.doc.models import DocExtResource
1313
from ietf.group.models import GroupExtResource
@@ -20,11 +20,13 @@
2020
class Command(BaseCommand):
2121
help = ('Locate information about github repositories to backup')
2222

23+
def add_arguments(self, parser):
24+
parser.add_argument('--verbose', dest='verbose', action='store_true', help='Show counts of types of repositories')
25+
2326
def handle(self, *args, **options):
2427

25-
if not settings.GITHUB_BACKUP_API_KEY:
26-
# TODO: complain
27-
return
28+
if not (hasattr(settings,'GITHUB_BACKUP_API_KEY') and settings.GITHUB_BACKUP_API_KEY):
29+
raise CommandError("ERROR: can't find GITHUB_BACKUP_API_KEY") # TODO: at >= py3.1, use returncode
2830

2931
github = github3.login(token = settings.GITHUB_BACKUP_API_KEY)
3032
owners = dict()
@@ -59,9 +61,14 @@ def handle(self, *args, **options):
5961
repos.add( (owner, repo.name) )
6062

6163
owner_types = Counter([owners[owner].type for owner in owners])
62-
print ("Owners:")
63-
for key in owner_types:
64-
print(" ",key,':',owner_types[key])
65-
print ("Repositories:", len(repos))
66-
for repo in sorted(repos):
67-
print(" https://github.com/%s/%s" % repo )
64+
if options['verbose']:
65+
self.stdout.write("Owners:")
66+
for key in owner_types:
67+
self.stdout.write(" %s: %s"%(key,owner_types[key]))
68+
self.stdout.write("Repositories: %d" % len(repos))
69+
for repo in sorted(repos):
70+
self.stdout.write(" https://github.com/%s/%s" % repo )
71+
else:
72+
for repo in sorted(repos):
73+
self.stdout.write("%s/%s" % repo )
74+

0 commit comments

Comments
 (0)