Skip to content
Permalink
Browse files

feat: Code generation command for the utility script.

  • Loading branch information...
sergey48k committed Aug 29, 2018
1 parent b616f42 commit 00a5fbdf958b980b589cd9f1dbdd1299ff44e2eb
Showing with 16 additions and 4 deletions.
  1. +16 −4 do.py
20 do.py
@@ -7,6 +7,7 @@
update: Updates a repo.
print: Prints a tracked repo.
glorify: Generate the hall of fame.
code: Generate MD or RST integration code.
"""

__copyright__ = '2018 Sourcerer, Inc.'
@@ -19,6 +20,7 @@

import fame.storage
import fame.ssl_hack
from fame.code_gen import make_md_code, make_rst_code
from fame.github_tracker import RepoTracker
from fame.glory import Glory

@@ -30,6 +32,7 @@ class Command:
LIST = 'list'
PRINT = 'print'
GLORIFY = 'glorify'
CODE = 'code'

@staticmethod
def is_repo_command(command):
@@ -41,7 +44,7 @@ def is_repo_command(command):
def get_all():
return [
Command.ADD, Command.REMOVE, Command.UPDATE,
Command.LIST, Command.PRINT, Command.GLORIFY]
Command.LIST, Command.PRINT, Command.GLORIFY, Command.CODE]


def parse_args():
@@ -59,6 +62,8 @@ def parse_args():
help='Working directory to store data')
parser.add_argument('--gcloud_bucket', type=str,
help='Google cloud bucket to store data')
parser.add_argument('--format', type=str, choices=['md', 'rst'],
default='md', help='Code format to generate')
parser.add_argument('--token', type=str, help='Github API token')
parser.add_argument('--sourcerer_origin', type=str,
default='https://sourcerer.io',
@@ -72,15 +77,16 @@ def parse_args():
help='Disable SSL host checks, useful for debugging')
args = parser.parse_args()

if Command.is_repo_command(args.command):
if Command.is_repo_command(args.command) or args.command == Command.CODE:
if not args.user:
parser.error('Must provide repo user')
if not args.owner:
parser.error('Must provide repo owner')
if not args.repo:
parser.error('Must provide repo name')
if not args.sourcerer_origin:
parser.error('Must provide Sourcerer origin')

if Command.is_repo_command(args.command) and not args.sourcerer_origin:
parser.error('Must provide Sourcerer origin')

if args.work_dir and not os.path.isdir(args.work_dir):
parser.error('--work_dir must be an existing directory')
@@ -132,6 +138,12 @@ def main():
repo = tracker.load()
glory = Glory(args.sourcerer_origin, args.sourcerer_api_origin)
glory.make(repo)
elif args.command == Command.CODE:
if args.format == 'md':
print(make_md_code(args.user, args.owner, args.repo))
elif args.format == 'rst':
print(make_rst_code(args.user, args.owner, args.repo))

except Exception as e:
print('e %s' % str(e))

0 comments on commit 00a5fbd

Please sign in to comment.
You can’t perform that action at this time.