Commit f4f2d267 authored by Jaden DIEFENBAUGH's avatar Jaden DIEFENBAUGH
Browse files

reindent python to be more consistent

parent 19955b36
......@@ -72,7 +72,7 @@ class Layout(Resource):
"""Exposes toolchain layout functionality"""
def __init__(self, config):
self.config = config
self.config = config
def post(self):
data = request.get_json()
......@@ -93,50 +93,50 @@ class Environments(Resource):
def get(self):
return [
{
"name": "Scientific Python 2.7",
"packages": {
"alabaster": "0.7.6",
"babel": "1.3"
"name": "Scientific Python 2.7",
"packages": {
"alabaster": "0.7.6",
"babel": "1.3"
},
"queues": {
"Default": {
"memory_limit": 5983,
"nb_slots": 2,
"max_slots_per_user": 2,
"nb_cores_per_slot": 1,
"time_limit": 360
}
"queues": {
"Default": {
"memory_limit": 5983,
"nb_slots": 2,
"max_slots_per_user": 2,
"nb_cores_per_slot": 1,
"time_limit": 360
}
},
"accessibility": "public",
"languages": [
"python"
"accessibility": "public",
"languages": [
"python"
],
"version": "0.0.4",
"short_description": "Scientific Python 2.7"
},
"version": "0.0.4",
"short_description": "Scientific Python 2.7"
},
{
"name": "Scientific Python 2.7",
"packages": {
"alabaster": "0.7.10",
"Babel": "2.4.0"
"name": "Scientific Python 2.7",
"packages": {
"alabaster": "0.7.10",
"Babel": "2.4.0"
},
"queues": {
"Default": {
"memory_limit": 5983,
"nb_slots": 2,
"max_slots_per_user": 2,
"nb_cores_per_slot": 1,
"time_limit": 360
}
"queues": {
"Default": {
"memory_limit": 5983,
"nb_slots": 2,
"max_slots_per_user": 2,
"nb_cores_per_slot": 1,
"time_limit": 360
}
},
"accessibility": "public",
"languages": [
"python"
"accessibility": "public",
"languages": [
"python"
],
"version": "1.0.0",
"short_description": "Scientific Python 2.7"
}
]
"version": "1.0.0",
"short_description": "Scientific Python 2.7"
}
]
class Templates(Resource):
......@@ -177,7 +177,7 @@ VALID_ENTITIES = [
'experiments',
'plotters',
'plotterparameters',
]
]
"""List of valid BEAT object entitities"""
......@@ -230,7 +230,7 @@ def generate_entity_tree(entity, config):
'toolchains',
'plotters',
'plotterparameters',
]
]
if entity in user_and_name:
for user in file_tree['children']:
......@@ -352,7 +352,7 @@ def gen_endpoint(entity):
"""A class representing the template for an endpoint for a BEAT entity"""
def __init__(self, config):
self.config = config
self.config = config
def refresh(self):
"""Regenerates the entity tree"""
......
......@@ -72,51 +72,53 @@ from beat.cmdline.config import Configuration
def main(user_input=None):
if user_input is not None:
argv = user_input
else:
argv = sys.argv[1:]
import pkg_resources
completions = dict(
prog=os.path.basename(sys.argv[0]),
version=pkg_resources.require('beat.editor')[0].version
)
from beat.cmdline.config import Configuration
completions.update(Configuration({}).as_dict())
args = docopt.docopt(
__doc__ % completions,
argv=argv,
version=completions['version'],
)
from ..utils import setup_logger
logger = setup_logger('beat.editor', args['--verbose'])
# Check that we are in a BEAT working folder
config = Configuration(args)
logger.info('BEAT prefix set to `%s\'', config.path)
logger.info('BEAT cache set to `%s\'', config.cache)
from flask import Flask, request
from flask_restful import Api
from flask_cors import CORS
from ..resources import Home, Layout, Templates, Environments
from ..resources import VALID_ENTITIES, gen_endpoint
app = Flask(__name__)
api = Api(app)
CORS(app)
api.add_resource(Home, '/')
api.add_resource(Layout, '/layout', resource_class_kwargs={'config': config})
api.add_resource(Templates, '/templates', resource_class_kwargs={'config': config})
api.add_resource(Environments, '/environments')
for entity in VALID_ENTITIES:
api.add_resource(gen_endpoint(entity), '/' + entity,
resource_class_kwargs={'config': config})
app.run(debug=args['--debug'])
if user_input is not None:
argv = user_input
else:
argv = sys.argv[1:]
import pkg_resources
completions = dict(
prog=os.path.basename(sys.argv[0]),
version=pkg_resources.require('beat.editor')[0].version
)
from beat.cmdline.config import Configuration
completions.update(Configuration({}).as_dict())
args = docopt.docopt(
__doc__ % completions,
argv=argv,
version=completions['version'],
)
from ..utils import setup_logger
logger = setup_logger('beat.editor', args['--verbose'])
# Check that we are in a BEAT working folder
config = Configuration(args)
logger.info('BEAT prefix set to `%s\'', config.path)
logger.info('BEAT cache set to `%s\'', config.cache)
from flask import Flask, request
from flask_restful import Api
from flask_cors import CORS
from ..resources import Home, Layout, Templates, Environments
from ..resources import VALID_ENTITIES, gen_endpoint
app = Flask(__name__)
api = Api(app)
CORS(app)
api.add_resource(Home, '/')
api.add_resource(Layout, '/layout', resource_class_kwargs={'config': config})
api.add_resource(Templates, '/templates', resource_class_kwargs={'config': config})
api.add_resource(Environments, '/environments')
for entity in VALID_ENTITIES:
print(entity)
api.add_resource(gen_endpoint(entity), '/' + entity,
resource_class_kwargs={'config': config})
app.run(debug=args['--debug'])
......@@ -45,13 +45,13 @@ def generate_database(views=None):
Parameters:
views (:py:class:`list`, Optional): A list of strings that represents the
views for the database
views (:py:class:`list`, Optional): A list of strings that represents the
views for the database
Returns:
str: The rendered template as a string
str: The rendered template as a string
"""
......@@ -66,14 +66,14 @@ def generate_library(uses=None):
Parameters:
uses (:py:class:`dict`, Optional): A dict of other libraries that the
library uses. Keys are the value to reference the library, values are
the library being referenced.
uses (:py:class:`dict`, Optional): A dict of other libraries that the
library uses. Keys are the value to reference the library, values are
the library being referenced.
Returns:
str: The rendered template as a string
str: The rendered template as a string
"""
......@@ -88,17 +88,17 @@ def generate_algorithm(has_parameters=False, uses=None):
Parameters:
has_parameters (:py:class:`bool`, Optional): Whether the algorithm has
parameters or not (default: False)
has_parameters (:py:class:`bool`, Optional): Whether the algorithm has
parameters or not (default: False)
uses (:py:class:`dict`, Optional): A dict of libraries that the algorithm
uses. Keys are the value to reference the library, values are the
library being referenced.
uses (:py:class:`dict`, Optional): A dict of libraries that the algorithm
uses. Keys are the value to reference the library, values are the
library being referenced.
Returns:
str: The rendered template as a string
str: The rendered template as a string
"""
......@@ -111,7 +111,7 @@ TEMPLATE_FUNCTION = dict(
databases=generate_database,
libraries=generate_library,
algorithms=generate_algorithm,
)
)
"""Functions for template instantiation within beat.editor"""
......@@ -121,7 +121,7 @@ def generate_python_template(entity, name, config, **kwargs):
Parameters:
entity (str): A valid BEAT entity (valid values are
entity (str): A valid BEAT entity (valid values are
"""
s = TEMPLATE_FUNCTION[entity](**kwargs)
......@@ -134,42 +134,43 @@ def generate_python_template(entity, name, config, **kwargs):
def setup_logger(name, verbosity):
'''Sets up the logging of a script
'''Sets up the logging of a script
Parameters:
Parameters:
name (str): The name of the logger to setup
name (str): The name of the logger to setup
verbosity (int): The verbosity level to operate with. A value of ``0``
(zero) means only errors, ``1``, errors and warnings; ``2``, errors,
warnings and informational messages and, finally, ``3``, all types of
messages including debugging ones.
verbosity (int): The verbosity level to operate with. A value of ``0``
(zero) means only errors, ``1``, errors and warnings; ``2``, errors,
warnings and informational messages and, finally, ``3``, all types of
messages including debugging ones.
'''
'''
logger = logging.getLogger(name)
formatter = logging.Formatter("%(name)s@%(asctime)s -- %(levelname)s: " \
"%(message)s")
logger = logging.getLogger(name)
formatter = logging.Formatter("%(name)s@%(asctime)s -- %(levelname)s: " \
"%(message)s")
_warn_err = logging.StreamHandler(sys.stderr)
_warn_err.setFormatter(formatter)
_warn_err.setLevel(logging.WARNING)
_warn_err = logging.StreamHandler(sys.stderr)
_warn_err.setFormatter(formatter)
_warn_err.setLevel(logging.WARNING)
class _InfoFilter:
def filter(self, record): return record.levelno <= logging.INFO
class _InfoFilter:
def filter(self, record): return record.levelno <= logging.INFO
_debug_info = logging.StreamHandler(sys.stdout)
_debug_info.setFormatter(formatter)
_debug_info.setLevel(logging.DEBUG)
_debug_info.addFilter(_InfoFilter())
_debug_info = logging.StreamHandler(sys.stdout)
_debug_info.setFormatter(formatter)
_debug_info.setLevel(logging.DEBUG)
_debug_info.addFilter(_InfoFilter())
logger.addHandler(_debug_info)
logger.addHandler(_warn_err)
logger.addHandler(_debug_info)
logger.addHandler(_warn_err)
logger.setLevel(logging.ERROR)
if verbosity == 1: logger.setLevel(logging.WARNING)
elif verbosity == 2: logger.setLevel(logging.INFO)
elif verbosity >= 3: logger.setLevel(logging.DEBUG)
logger.setLevel(logging.ERROR)
if verbosity == 1: logger.setLevel(logging.WARNING)
elif verbosity == 2: logger.setLevel(logging.INFO)
elif verbosity >= 3: logger.setLevel(logging.DEBUG)
return logger
return logger
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment