def main(): defaults = backend.defaults('wight', 'log') defaults['log']['level'] = 'WARN' app = WightApp(config_defaults=defaults) app.register_controllers() bright_yellow = "%s%s" % (Fore.YELLOW, Style.BRIGHT) bright_magenta = "%s%s" % (Fore.MAGENTA, Style.BRIGHT) dim_red = "%s%s" % (Fore.RED, Style.DIM) dim_white = "%s%s" % (Fore.WHITE, Style.DIM) reset = "%s%s" % (Style.RESET_ALL, dim_white) try: app.setup() app.run() except UnauthenticatedError: print "\n%sYou need to be logged to use this command. Use '%swight login%s %s<user e-mail>%s%s' to login.%s\n" % ( dim_red, bright_yellow, reset, bright_magenta, reset, dim_red, reset) except TargetNotSetError: print "\n%sYou need to set the target to use wight. Use '%swight target-set%s %s<url of target>%s%s' to login.%s\n" % ( dim_red, bright_yellow, reset, bright_magenta, reset, dim_red, reset) finally: app.close()
def main(): defaults = backend.defaults('wight', 'log') defaults['log']['level'] = 'WARN' app = WightApp(config_defaults=defaults) app.register_controllers() bright_yellow = "%s%s" % (Fore.YELLOW, Style.BRIGHT) bright_magenta = "%s%s" % (Fore.MAGENTA, Style.BRIGHT) dim_red = "%s%s" % (Fore.RED, Style.DIM) dim_white = "%s%s" % (Fore.WHITE, Style.DIM) reset = "%s%s" % (Style.RESET_ALL, dim_white) try: app.setup() app.run() except UnauthenticatedError: print "\n%sYou need to be logged to use this command. Use '%swight login%s %s<user e-mail>%s%s' to login.%s\n" % ( dim_red, bright_yellow, reset, bright_magenta, reset, dim_red, reset ) except TargetNotSetError: print "\n%sYou need to set the target to use wight. Use '%swight target-set%s %s<url of target>%s%s' to login.%s\n" % ( dim_red, bright_yellow, reset, bright_magenta, reset, dim_red, reset ) finally: app.close()
def test_main_instantiate_app(self, app_mock): main() defaults = backend.defaults('wight', 'log') defaults['log']['level'] = 'WARN' app_mock.assert_called_with(config_defaults=defaults) expect(app_mock.mock_calls).to_be_like( [ call(config_defaults={'wight': {}, 'log': {'level': 'WARN'}}), call().register_controllers(), call().setup(), call().run(), call().close() ] )
def test_main_instantiate_app(self, app_mock): main() defaults = backend.defaults('wight', 'log') defaults['log']['level'] = 'WARN' app_mock.assert_called_with(config_defaults=defaults) expect(app_mock.mock_calls).to_be_like([ call(config_defaults={ 'wight': {}, 'log': { 'level': 'WARN' } }), call().register_controllers(), call().setup(), call().run(), call().close() ])
def main(argv=None): myname = 'cement-demo' defaults = backend.defaults(myname) defaults[myname]['foo'] = "BAR!" app = foundation.CementApp(myname, config_defaults=defaults) try: app.setup() app.args.add_argument('-f', '--foo', action='store', metavar='STR', help='set foo') app.run() print("Hello world from cement-demo") if app.pargs.foo: app.log.info("Argument Foo == {}".format(app.pargs.foo)) if app.config.has_key(myname, 'foo'): app.log.info( "Config Foo == {}".format(app.config.get(myname, 'foo'))) finally: app.close() return(0)
#!/usr/bin/env python # # @description@ # # Created by: @creator@ <@email@> # License: @license@ # URL: @url@ # from cement.core import foundation, backend from cement.core.controller import CementBaseController, expose from cement.core.exc import FrameworkError, CaughtSignal defaults = backend.defaults('@module@') defaults['@module@'] = dict( debug=False, foo='bar', ) class @class_prefix@BaseController(CementBaseController): class Meta: label = 'base' description = '@module@ base controller'.capitalize() arguments = [ ( ['-f', '--foo'], dict(help='the notorious foo option')), ] @expose(hide=True) def default(self): raise NotImplementedError
"""Configuration settings""" import os from cement.core import backend config_defaults = backend.defaults('production', 'archive', 'config', 'project','log', 'distributed', 'db') config_defaults['production']['root'] = None config_defaults['production']['swestore'] = None config_defaults['archive']['root'] = None config_defaults['project']['root'] = None config_defaults['project']['repos'] = None config_defaults['project']['finished'] = None config_defaults['config']['ignore'] = ["slurm*", "tmp*"] config_defaults['log']['level'] = "INFO" config_defaults['log']['file'] = os.path.join(os.getenv("HOME"), "log", "pm.log") config_defaults['distributed']['jobaccount'] = None config_defaults['db']['url'] = None config_defaults['db']['password'] = None config_defaults['db']['username'] = None config_defaults['db']['samples'] = "samples" config_defaults['db']['projects'] = "projects" config_defaults['db']['flowcells'] = "flowcells"
"""pm configuration settings""" import os from cement.core import backend config_defaults = backend.defaults('log') config_defaults['log']['level'] = "INFO" config_defaults['log']['file'] = os.path.join(os.getenv("HOME"), "log", "pm.log")
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. """ Created September 4, 2012 @author: Justin Hammond, Rackspace Hosting """ from cement.core import backend, foundation import aiclib INVALID_VALUE = "N/A" defaults = backend.defaults('queries') defaults['queries']['debug'] = False app = foundation.CementApp('queries', config_defaults=defaults) def invalid_switch_ports(json=False, username="******", password="******", uri="https://nvp"): nvp = aiclib.nvp.Connection(uri, username=username, password=password) query = nvp.lswitch_port('*').query().length(1000) results = query.relations(['LogicalQueueConfig', 'LogicalSwitchConfig']).results() output = {} if json else "" msg = "Port:\t%s\nType:\t%s\nQRate:\t%s\nIP:\t%s\nMAC:\t%s\n\n" while results: if len(results['results']) == 0: break
sys.path.append(module_path) from ntr.cli.controllers.base import NotarioBaseController from ntr.core import exc as ntr_exc # Ugly, but how to improve? USER_PATH = os.path.expanduser('~') USER_PATH_CONFIG = USER_PATH + '/.notario/config' # TODO: figure out if we want to have also a ~/notario.ini file_path = os.path.abspath(__file__) base_path = os.path.dirname(file_path) config_path = os.path.join(module_path, 'data/config/notario.cfg') # Default values for the config. defaults = backend.defaults('notario') defaults['notario']['dir'] = "/.notes/" defaults['notario']['ext'] = ".txt" defaults['notario']['edt'] = "subl" """ Entry point for the Notario.minion application. """ class NotarioApp(foundation.CementApp): class Meta: label = 'notario' bootstrap = 'ntr.cli.bootstrap' base_controller = NotarioBaseController
#!/usr/bin/env python from cement.core import controller, foundation, backend, handler import boto import sys import string defaults = backend.defaults('base') defaults['base']['AWS_REGIONS'] = ['us-east-1', 'us-west-2', 'us-west-1', 'eu-west-1', 'ap-southeast-1', 'ap-northeast-1', 'sa-east-1'] class BaseController(controller.CementBaseController): class Meta: label = 'base' description = 'AWS CLI.' configuration_defaults = defaults arguments = [ (['-r', '--region'], dict( default=defaults['base']['AWS_REGIONS'][0], choices=defaults['base']['AWS_REGIONS'], nargs=1, help="Set AWS regional context.")) ] @controller.expose(hide=True, aliases=['run', 'help']) def default(self): print self._usage_text print self._help_text class StackController(controller.CementBaseController): class Meta:
from pm.experiment import setup_project from pm.utils import test import logbook LOG = logbook.Logger(__name__) has_ngstestdata = False try: import ngstestdata as ntd has_ngstestdata = True datadir = os.path.join(os.path.dirname(ntd.__file__), os.pardir, "data") except ImportError: LOG.warn("Module ngstestdata not found. Not running full tests") filedir = os.path.dirname(__file__) config_defaults = backend.defaults('config', 'projects','log', 'bcbio') config_defaults['log']['level'] = "INFO" config_defaults['log']['file'] = os.path.join(os.curdir, "log", "pm.log") config_defaults['projects']['J.Doe_00_01'] = {'alias':"null", 'path':os.path.join(filedir, "data", "projects", "J.Doe_00_01")} config_defaults['projects']['J.Doe_00_02'] = {'alias':"null", 'path':os.path.join(filedir, "data", "projects", "J.Doe_00_02")} config_defaults['projects']['J.Doe_00_03'] = {'alias':"null", 'path':os.path.join(filedir, "data", "projects", "J.Doe_00_03")} config_defaults['config']['project'] = "projects.yaml" config_defaults['config']['sample'] = "samples.yaml" samples = {'P001_101_index3': {'120924_AC003CCCXX': {'1_120924_AC003CCCXX_TGACCA': {'id': '1_120924_AC003CCCXX_3', 'analysis': []}}, '121015_BB002BBBXX': {'1_121015_BB002BBBXX_TGACCA': {'id': '1_121015_BB002BBBXX_3', 'analysis': []}}}, 'P001_102_index6': {'120924_AC003CCCXX': {'2_120924_AC003CCCXX_ACAGTG': {'id': '2_120924_AC003CCCXX_5', 'analysis': []}}}} # Add plugin directory class PmBcbioTestApp(test.PmTestApp): class Meta(PmMainApp.Meta): plugin_dir = os.path.join(filedir, os.pardir, "plugin") config_defaults = config_defaults
import os from cement.core import backend, handler, output from cement.utils import test, shell LOG = backend.minimal_logger(__name__) BASEDIR = os.path.join(os.path.dirname(__file__), os.pardir) from pm.cli import PmMainApp ## Set default configuration filedir = os.path.abspath(os.curdir) config_defaults = backend.defaults('config', 'project','log') config_defaults['project']['root'] = os.path.join(filedir, "data", "projects") config_defaults['config']['ignore'] = ["slurm*", "tmp*"] config_defaults['log']['level'] = "INFO" config_defaults['log']['file'] = os.path.join(filedir, "log", "pm.log") def safe_makedir(dname): """Make directory""" if not os.path.exists(dname): try: os.makedirs(dname) except OSError: if not os.path.isdir(dname): raise else: print "Directory %s already exists" % dname return dname
import os import glob from cement.core import backend, foundation, handler from cli import JSONConfigParserHandler from cli import controllers CONFIG_DIR = os.path.join(__path__[0], './config') CONFIG_FILES = glob.glob(os.path.join(CONFIG_DIR, '*.json')) # defined app first and handlers afterwards app = foundation.CementApp('credovi', config_defaults=backend.defaults('credovi'), config_handler='JSONConfigParser', config_files=CONFIG_FILES) # hooks must be registered afterwards from cli.hooks import * handler.register(JSONConfigParserHandler) handler.register(controllers.BaseController) handler.register(controllers.DatabaseController) handler.register(controllers.CredoController) handler.register(controllers.CredoStandAloneController) handler.register(controllers.MMCIFController) handler.register(controllers.LigandController) handler.register(controllers.ModuleController) # setup the application app.setup()
import sys import logging from cement.core import backend, foundation, controller, handler logo_ascii = """ _ _ _ _ _ __ _ _| |_| |_ ___ _ _ ___ __ _ _ _| |_ _ _ ___| |_ | '_ \ || | _| ' \/ _ \ ' \___/ _` | '_| _| ' \/ -_) _| | .__/\_, |\__|_||_\___/_||_| \__,_|_| \__|_||_\___|\__| |_| |__/ """ defaults = backend.defaults('base') defaults['base']['address'] = '<broadcast>' log = logging.getLogger(__name__) def run(name, config, controller=None): mod = __import__('artnet.scripts', globals(), locals(), [name], -1) try: getattr(mod, name).main(config, controller) except: log.error("Couldn't find lighting script named %r" % name) class ArtnetBaseController(controller.CementBaseController): class Meta: label = 'base' description = "%s\nBasic artnet protocol support." % logo_ascii
import os from cement.core import backend, handler, output from cement.utils import test, shell from scilifelab.pm import PmApp from data import setup_data_files from empty_files import setup_empty_files ## Set default configuration filedir = os.path.abspath(os.path.dirname(os.path.realpath(__file__))) config_defaults = backend.defaults("production", "archive", "config", "project", "log", "db") config_defaults["production"]["root"] = os.path.join(filedir, "data", "production") config_defaults["archive"]["root"] = os.path.join(filedir, "data", "archive") config_defaults["project"]["root"] = os.path.join(filedir, "data", "projects") config_defaults["project"]["repos"] = os.path.join(filedir, "data", "repos") config_defaults["config"]["ignore"] = ["slurm*", "tmp*"] config_defaults["log"]["level"] = "INFO" config_defaults["log"]["file"] = os.path.join(filedir, "data", "log", "pm.log") config_defaults["db"]["url"] = "localhost" config_defaults["db"]["user"] = "******" config_defaults["db"]["password"] = "******" config_defaults["db"]["samples"] = "samples-test" config_defaults["db"]["flowcells"] = "flowcells-test" config_defaults["db"]["projects"] = "projects-test" def safe_makedir(dname): """Make directory""" if not os.path.exists(dname): try: os.makedirs(dname) except OSError:
import os import sys from cement.core import foundation, backend from cement.core import exc as cement_exc from cement.utils import fs from boss.cli.controllers.base import BossBaseController from boss.core import exc as boss_exc if sys.version_info[0] >= 3: from imp import reload defaults = backend.defaults('boss', 'answers') defaults['boss']['data_dir'] = '~/.boss/' class BossApp(foundation.CementApp): class Meta: label = 'boss' bootstrap = 'boss.cli.bootstrap' base_controller = BossBaseController config_defaults = defaults config_files = [ '/etc/boss/boss.conf', '~/.boss.conf', '~/.boss/config', ] def validate_config(self): # fix up paths self.config.set('boss', 'data_dir', fs.abspath(self.config.get('boss', 'data_dir')))
from cement.core import backend from skyler import Skyler defaults = backend.defaults('base', 'keystone') defaults['base']['rabbitmq_host'] = 'localhost' defaults['base']['rabbitmq_user'] = '******' defaults['base']['rabbitmq_password'] = '******' defaults['base']['heat_endpoint'] = 'http://172.16.0.201:8004/v1' defaults['base']['templates'] = '/vagrant/skyler-cli/skyler/templates' defaults['base']['docker-registry'] = 'localhost:5042' defaults['base']['neutron_endpoint'] = 'http://localhost:9696/' # defaults['base']['network'] = 'sky-net' defaults['base']['subnet'] = 'private-subnet' defaults['base']['network'] = 'private' # defaults['base']['cidr_start'] = '10.0.1.0/28' # defaults['base']['gateway'] = '10.0.1.1' # TODO: remove this from conf, read from env vars defaults['keystone']['auth_url'] = 'http://localhost:35357/v2.0' defaults['keystone']['username'] = '******' defaults['keystone']['password'] = '******' defaults['keystone']['tenant'] = 'demo' app = Skyler('skyler', config_defaults=defaults) app.setup() CONFIG = app.config app.close()
"""classes for full test""" import os from cement.core import backend, handler, output from cement.utils import test from scilifelab.pm import PmApp filedir = os.path.abspath(os.path.dirname(os.path.realpath(__file__))) config_defaults = backend.defaults('production', 'archive', 'config', 'project','log', 'runqc', 'db') config_defaults['production']['root'] = os.path.join(filedir, "data", "production") config_defaults['archive']['root'] = os.path.join(filedir, "data", "archive") config_defaults['project']['root'] = os.path.join(filedir, "data", "projects") config_defaults['project']['repos'] = os.path.join(filedir, "data", "repos") config_defaults['runqc']['root'] = os.path.join(filedir, "data", "archive") config_defaults['runqc']['production'] = os.path.join(filedir, "data", "production") config_defaults['runqc']['rsync_sample_opts'] = "-amnv --include=*/ --include='[0-9][0-9]_\*.txt' --include='bcbb_software_versions.txt' --include='*.yaml*' --include='*screen.txt' --include='*summary.txt' --include='*fastqc_data.txt' --include='*metrics' --exclude='tmp' --exclude='*'" config_defaults['config']['ignore'] = ["slurm*", "tmp*"] config_defaults['log']['level'] = "INFO" config_defaults['log']['file'] = os.path.join(filedir, "data", "log", "pm.log") config_defaults['db']['url'] = "localhost" config_defaults['db']['user'] = "******" config_defaults['db']['password'] = "******" config_defaults['db']['samples'] = "samples-test" config_defaults['db']['flowcells'] = "flowcells-test" config_defaults['db']['projects'] = "projects-test" ## Output handler for tests class PmTestOutputHandler(output.CementOutputHandler): class Meta: label = 'pmfulltest'
"""classes for full test""" import os from cement.core import backend, handler, output from cement.utils import test from scilifelab.pm import PmApp filedir = os.path.abspath(os.path.dirname(os.path.realpath(__file__))) config_defaults = backend.defaults('production', 'archive', 'config', 'project', 'log', 'runqc', 'db') config_defaults['production']['root'] = os.path.join(filedir, "data", "production") config_defaults['archive']['root'] = os.path.join(filedir, "data", "archive") config_defaults['project']['root'] = os.path.join(filedir, "data", "projects") config_defaults['project']['repos'] = os.path.join(filedir, "data", "repos") config_defaults['runqc']['root'] = os.path.join(filedir, "data", "archive") config_defaults['runqc']['production'] = os.path.join(filedir, "data", "production") config_defaults['runqc'][ 'rsync_sample_opts'] = "-amnv --include=*/ --include='[0-9][0-9]_\*.txt' --include='bcbb_software_versions.txt' --include='*.yaml*' --include='*screen.txt' --include='*summary.txt' --include='*fastqc_data.txt' --include='*metrics' --exclude='tmp' --exclude='*'" config_defaults['config']['ignore'] = ["slurm*", "tmp*"] config_defaults['log']['level'] = "INFO" config_defaults['log']['file'] = os.path.join(filedir, "data", "log", "pm.log") config_defaults['db']['url'] = "localhost" config_defaults['db']['user'] = "******" config_defaults['db']['password'] = "******" config_defaults['db']['samples'] = "samples-test" config_defaults['db']['flowcells'] = "flowcells-test" config_defaults['db']['projects'] = "projects-test"