Skip to content
This repository has been archived by the owner on Jul 18, 2023. It is now read-only.

Commit

Permalink
[TAAS-23] Added a single-source processor and front-end.
Browse files Browse the repository at this point in the history
  • Loading branch information
pjf committed Mar 29, 2017
1 parent db9bd04 commit fa9cd63
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 14 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
py_modules=['taas'],
entry_points={
'console_scripts': [
"fetch = taas:process_all_sources",
"gss2json = taas.cmdline:gss2json"
]
},

Expand Down
26 changes: 13 additions & 13 deletions taas/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,34 +225,34 @@ def google_sheet_to_json(name, version, key, gid, mapping, directory=None):
def process_source(source_name, source):
"""
Processes a source, generating JSON and potentially other supporting
files. Right now this is only able to flip sheets to JSON, but we may
support other services in the future.
files.
Expects a dictionary of vesions, with service descriptions underneath.
Expects a `source_name`, with which we label our output, and a dictionary
of vesions, with service descriptions underneath.
"""

# TODO: We should have a service class definition, rather than trusting our
# config file is in the right format.

for version in source:

options = source[version]

google_sheet_to_json(
source_name, version, options['key'], options['gid'], options['mapping']
)


def process_all_sources(config=None):
"""
Processes all sources in a given config, generating JSON output. Uses
the default config if none supplied.
def process_sources(config, sources=None):
"""
Uses the config provided to process the sources given.
if config is None:
config = read_config()
Process all sources if none are provided.
"""
if sources is None:
sources = config['sources']

sources = config['sources']
for source in sources:
if source not in config['sources']:
raise KeyError("Asked to process source '{}', but not found in config.".format(source))

for source_name in sources:
process_source(source_name, sources[source_name])
process_source(source, config['sources'][source])
38 changes: 38 additions & 0 deletions taas/cmdline.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import argparse
import taas

"""Command-line interfaces to TAAS functions."""


def gss2json():
"""Console script for processing google spreadsheet(s) to JSON."""

parser = argparse.ArgumentParser(
description='''
Processes Google spreadsheet(s) to JSON.
If no arguments are given, all sheets will be processed.
'''
)

parser.add_argument('--config', metavar="FILE", help="Config file to use.")

parser.add_argument(
'sheets',
metavar='sheet',
nargs="*",
help="A sheet to process, as named in the config file",
)

args = parser.parse_args()

# This reads the default file if none is specified.
config = taas.read_config(args.config)

# Sheets always comes back as a list. We flip it explicitly to
# a None value if it's empty.
sheets = args.sheets
if not sheets:
sheets = None

taas.process_sources(config, sheets)

0 comments on commit fa9cd63

Please sign in to comment.