-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
rename sdss-astra to astra; update docs; put astra to bin/
- Loading branch information
Showing
6 changed files
with
88 additions
and
132 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,77 @@ | ||
#!/usr/bin/env python | ||
# encoding: utf-8 | ||
# | ||
# @Author: José Sánchez-Gallego | ||
# @Date: Dec 1, 2017 | ||
# @Filename: astra | ||
# @License: BSD 3-Clause | ||
# @Copyright: José Sánchez-Gallego | ||
|
||
import click | ||
import os | ||
from shutil import rmtree | ||
from astra import log | ||
from logging import DEBUG, INFO | ||
from astra.db.connection import Base, engine | ||
from sqlalchemy_utils import database_exists, create_database | ||
|
||
from __future__ import division | ||
from __future__ import print_function | ||
from __future__ import absolute_import | ||
from __future__ import unicode_literals | ||
from astra.tools.sdss_astra import (data, subset, component, execute, | ||
query_execute, schedule) | ||
|
||
import argparse | ||
import os | ||
import sys | ||
# Common options. | ||
@click.group() | ||
@click.option("-v", "verbose", default=False, is_flag=True, | ||
help="verbose mode") | ||
@click.pass_context | ||
def cli(context, verbose): | ||
context.ensure_object(dict) | ||
context.obj["verbose"] = verbose | ||
|
||
# TODO: This isn't correctly followed for sqlalchemy output. | ||
# It defaults to verbose! | ||
log.set_level(DEBUG if verbose else INFO) | ||
|
||
|
||
@cli.command() | ||
@click.option("-y", "confirm", default=False, is_flag=True, | ||
help="drop the database if it already exists") | ||
@click.pass_context | ||
def setup(context, confirm): | ||
r""" Setup databases using the current configuration. """ | ||
|
||
log.debug("Running setup") | ||
|
||
if not database_exists(engine.url): | ||
log.info(f"Creating database {engine.url}") | ||
create_database(engine.url) | ||
|
||
elif not confirm \ | ||
and click.confirm("Database already exists. This will wipe the database, including all "\ | ||
"downloaded components, and start again. Are you sure?", abort=True): | ||
None | ||
|
||
log.debug("Dropping all tables") | ||
Base.metadata.drop_all(engine) | ||
|
||
from astra.main import math | ||
log.debug("Creating all tables") | ||
Base.metadata.create_all(engine) | ||
|
||
log.debug("Removing old components") | ||
component_dir = os.getenv("ASTRA_COMPONENT_DIR", None) | ||
if component_dir is not None: | ||
if os.path.exists(component_dir): | ||
rmtree(component_dir) | ||
os.makedirs(component_dir, exist_ok=True) | ||
|
||
if __name__ == '__main__': | ||
|
||
# An example of how to write a command line parser that works with the | ||
# main.math function. For more details on how to use argparse, start with | ||
# this tutorial: https://kapeli.com/dash_share?docset_file=Python%203&docset_name=Python%203&path=doc/howto/argparse.html%23id1&platform=python&repo=Main&version=3.6.3 | ||
log.info("Astra is ready.") | ||
return None | ||
|
||
parser = argparse.ArgumentParser( | ||
prog=os.path.basename(sys.argv[0]), | ||
description='Performs an arithmetic operation.') | ||
|
||
parser.add_argument('VALUE1', type=float, help='The first operand') | ||
parser.add_argument('OPERATOR', type=str, help='The operator [+, -, *, /]') | ||
parser.add_argument('VALUE2', type=float, help='The second operand') | ||
# Add various commands | ||
cli.add_command(data.data) | ||
cli.add_command(subset.subset) | ||
cli.add_command(component.component) | ||
cli.add_command(execute.execute) | ||
cli.add_command(query_execute.query_execute) | ||
cli.add_command(schedule.schedule) | ||
|
||
parser.add_argument('-v', '--verbose', action='store_true', default=False, | ||
help='sets verbose mode') | ||
|
||
args = parser.parse_args() | ||
|
||
result = math(args.VALUE1, args.VALUE2, arith_operator=args.OPERATOR) | ||
|
||
if args.verbose: | ||
print('{} {} {} = {}'.format(args.VALUE1, args.OPERATOR, args.VALUE2, result)) | ||
else: | ||
print(result) | ||
if __name__ == "__main__": | ||
cli(obj=dict()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.