Skip to content

Commit

Permalink
Add "apps", "themes", "demos" commands
Browse files Browse the repository at this point in the history
Reference `distributions.json` to obtain the latest distribution
data, then display the desired section from these three choices:
"apps", "themes", "demos".

Resolves #10
  • Loading branch information
grahamu committed Aug 2, 2016
1 parent bfde2cf commit 92f5b75
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 5 deletions.
5 changes: 5 additions & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Patrick Altman
Brian Rosner
Anna Ossowski
Seyi Ogunyemi
Graham Ullrich
40 changes: 39 additions & 1 deletion pcli.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
class Config(object):
def __init__(self):
self.url = "https://raw.githubusercontent.com/pinax/pinax/master/projects.json"
self.apps_url = "https://raw.githubusercontent.com/pinax/pinax/master/distributions.json"


pass_config = click.make_pass_decorator(Config, ensure=True)
Expand Down Expand Up @@ -55,11 +56,14 @@ def cleanup(name):

@click.group()
@click.option("--url", type=str, required=False, help="url to project data source")
@click.option("--apps_url", type=str, required=False, help="url to application data source")
@click.version_option()
@pass_config
def main(config, url):
def main(config, url, apps_url):
if url:
config.url = url
if apps_url:
config.apps_url = apps_url


@main.command()
Expand All @@ -83,6 +87,40 @@ def projects(config):
click.echo("The projects manifest you are trying to consume will not work: \n{}".format(config.url))


def show_distribution_section(config, title, section_name):
"""
Obtain distribution data and display latest distribution section,
i.e. "demos" or "apps" or "themes".
"""
payload = requests.get(config.apps_url).json()
distributions = sorted(payload.keys(), reverse=True)
latest_distribution = payload[distributions[0]]
click.echo("{} {}".format("Release".rjust(7), title))
click.echo("------- ---------------")
section = latest_distribution[section_name]
names = sorted(section.keys())
for name in names:
click.echo("{} {}".format(section[name].rjust(7), name))


@main.command()
@pass_config
def apps(config):
show_distribution_section(config, "Application", "apps")


@main.command()
@pass_config
def demos(config):
show_distribution_section(config, "Demo", "demos")


@main.command()
@pass_config
def themes(config):
show_distribution_section(config, "Theme", "themes")


@main.command()
@click.option("--dev", is_flag=True, help="use latest development branch instead of release")
@click.argument("project", type=str, required=True)
Expand Down
8 changes: 4 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ def read(*parts):
description="a command line for Pinax",
name="pinax-cli",
long_description=read("README.rst"),
version="1.0.0",
version="1.1.0",
url="http://github.com/pinax/pinax-cli/",
license="MIT",
py_modules=["pcli"],
install_requires=[
"Click==5.1",
"requests==2.7.0",
"colorama==0.3.3"
"Click==6.6",
"requests==2.10.0",
"colorama==0.3.7"
],
entry_points="""
[console_scripts]
Expand Down

0 comments on commit 92f5b75

Please sign in to comment.