def setUp(self):
		yaml_file = os.path.join(os.path.dirname(__file__), '..', '..', 'config.yml')
		config.load(yaml_file)
		config.bootstrap(['-vv'])
		# make sure we're not mocking out google reader
		app_globals.OPTIONS['test'] = False
		config.parse_options(['--output-path=/tmp/gris-test', '--num-items=1'])
		config.check()
		self.reader = app_globals.READER = Reader()
Exemplo n.º 2
0
def main(wf):
    """Run workflow Script Filter.

    Args:
        wf (workflow.Workflow): Current Workflow object.

    """
    global ureg
    ureg = UnitRegistry(wf.decode(DEFAULT_UNIT_DEFINITIONS))
    ureg.default_format = 'P'

    wf.magic_arguments['appkey'] = open_currency_instructions

    if not len(wf.args):
        return

    query = wf.args[0]  # .lower()
    log.debug('query : %s', query)

    handle_update(wf)
    # Create data files if necessary
    bootstrap(wf)

    # Add workflow and user units to unit registry
    register_units()

    # Notify of available update
    if wf.update_available:
        wf.add_item('A newer version is available',
                    'Action this item to download & install the new version',
                    autocomplete='workflow:update',
                    icon=ICON_UPDATE)

    # Load cached data
    exchange_rates = wf.cached_data(CURRENCY_CACHE_NAME, max_age=0)

    if exchange_rates:  # Add exchange rates to conversion database
        register_exchange_rates(exchange_rates)

    if not wf.cached_data_fresh(CURRENCY_CACHE_NAME, CURRENCY_CACHE_AGE):
        # Update currency rates
        cmd = ['/usr/bin/python', wf.workflowfile('currency.py')]
        run_in_background('update', cmd)
        wf.rerun = 0.5

    if is_running('update'):
        wf.rerun = 0.5
        if exchange_rates is None:  # No data cached yet
            wf.add_item(u'Fetching exchange rates…',
                        'Currency conversions will be momentarily possible',
                        icon=ICON_INFO)
        else:
            wf.add_item(u'Updating exchange rates…',
                        icon=ICON_INFO)

    return convert(query)
Exemplo n.º 3
0
def main(wf):
    """Run workflow Script Filter.

    Args:
        wf (workflow.Workflow): Current Workflow object.

    """
    global ureg
    ureg = UnitRegistry(wf.decode(DEFAULT_UNIT_DEFINITIONS))
    ureg.default_format = 'P'

    wf.magic_arguments['appkey'] = open_currency_instructions

    if not len(wf.args):
        return

    query = wf.args[0]  # .lower()
    log.debug('query : %s', query)

    handle_update(wf)
    # Create data files if necessary
    bootstrap(wf)

    # Add workflow and user units to unit registry
    register_units()

    # Notify of available update
    if wf.update_available:
        wf.add_item('A newer version is available',
                    'Action this item to download & install the new version',
                    autocomplete='workflow:update',
                    icon=ICON_UPDATE)

    # Load cached data
    exchange_rates = wf.cached_data(CURRENCY_CACHE_NAME, max_age=0)

    if exchange_rates:  # Add exchange rates to conversion database
        register_exchange_rates(exchange_rates)

    if not wf.cached_data_fresh(CURRENCY_CACHE_NAME, CURRENCY_CACHE_AGE):
        # Update currency rates
        cmd = ['/usr/bin/python', wf.workflowfile('currency.py')]
        run_in_background('update', cmd)
        wf.rerun = 0.5

    if is_running('update'):
        wf.rerun = 0.5
        if exchange_rates is None:  # No data cached yet
            wf.add_item(u'Fetching exchange rates…',
                        'Currency conversions will be momentarily possible',
                        icon=ICON_INFO)
        else:
            wf.add_item(u'Updating exchange rates…',
                        icon=ICON_INFO)

    return convert(query)
Exemplo n.º 4
0
def setup(opts=None):
	"""Parse options. If none given, opts is set to sys.argv"""
	if opts is None:
		opts = sys.argv[1:]
	config.bootstrap(opts)
	config.load()
	config.parse_options(opts)
	ensure_dir_exists(app_globals.OPTIONS['output_path'])
	log_start()
	if app_globals.OPTIONS['report_pid']:
		proctl.report_pid()
		exit(0)
	config.check()
	proctl.ensure_singleton_process()
	init_signals()
	def test_should_not_fail_setting_any_options(self):
		for opt in config.all_options[1]:
			opt = '--' + opt
			args = [opt]
			if opt.endswith('='):
				args = [opt[:-1], '123']

			if opt == '--help':
				try: config.bootstrap([opt])
				except SystemExit: pass
				continue
				
			print "bootstrapping with %s" % args
			config.bootstrap(args)
			print "configging with %s" % args
			config.parse_options(args)
Exemplo n.º 6
0
def main(wf):
    """Update exchange rates from Yahoo! Finance.

    Args:
        wf (workflow.Workflow): Workflow object.

    """
    start_time = time.time()
    bootstrap(wf)

    log.info('fetching exchange rates from Yahoo! and CryptoCompare.com ...')

    rates = wf.cached_data(CURRENCY_CACHE_NAME,
                           fetch_exchange_rates,
                           CURRENCY_CACHE_AGE)

    elapsed = time.time() - start_time
    log.info('%d exchange rates updated in %0.2f seconds.',
             len(rates), elapsed)

    for currency, rate in sorted(rates.items()):
        log.debug('1 EUR = %s %s', rate, currency)
Exemplo n.º 7
0
def main(wf):
    """Update exchange rates.

    Args:
        wf (workflow.Workflow): Workflow object.

    """
    start_time = time.time()
    bootstrap(wf)

    site = 'OpenExchangeRates.org' if OPENX_APP_KEY else 'ExchangeRate-API.com'

    log.info('fetching exchange rates from %s and CryptoCompare.com ...', site)

    rates = wf.cached_data(CURRENCY_CACHE_NAME, fetch_exchange_rates,
                           CURRENCY_CACHE_AGE)

    elapsed = time.time() - start_time
    log.info('%d exchange rates updated in %0.2f seconds.', len(rates),
             elapsed)

    for currency, rate in sorted(rates.items()):
        log.debug('1 %s = %s %s', REFERENCE_CURRENCY, rate, currency)
Exemplo n.º 8
0
def bootstrap():
    """Deploy, configure, and start Fridge on hosts"""
    install.bootstrap()
    config.bootstrap()
    service.start_all()
Exemplo n.º 9
0
def main(wf):
    """Run Script Filter.

    Args:
        wf (workflow.Workflow): Workflow object.

    """
    args = docopt(__doc__, wf.args)

    log.debug('args : {!r}'.format(args))

    query = args.get('<query>')

    bootstrap(wf)

    # Alternative actions ----------------------------------------------

    if args.get('--openapi'):
        subprocess.call(['open', SIGNUP_URL])
        return

    if args.get('--openhelp'):
        subprocess.call(['open', README_URL])
        return

    if args.get('--openunits'):
        path = wf.datafile(CUSTOM_DEFINITIONS_FILENAME)
        subprocess.call(['open', path])
        return

    if args.get('--openactive'):
        path = wf.datafile(ACTIVE_CURRENCIES_FILENAME)
        subprocess.call(['open', path])
        return

    # Parse query ------------------------------------------------------

    if DELIMITER in query:
        return handle_delimited_query(query)

    # Filter options ---------------------------------------------------

    query = query.strip()

    options = [
        dict(title='View Help File',
             subtitle='Open help file in your browser',
             valid=True,
             arg='--openhelp',
             icon=ICON_HELP),

        dict(title='View All Supported Currencies',
             subtitle='View and search list of supported currencies',
             autocomplete=u'currencies {} '.format(DELIMITER),
             icon=ICON_CURRENCY),

        dict(title='Edit Active Currencies',
             subtitle='Edit the list of active currencies',
             valid=True,
             arg='--openactive',
             icon='icon.png'),

        dict(title='Edit Custom Units',
             subtitle='Add and edit your own custom units',
             valid=True,
             arg='--openunits',
             icon='icon.png'),

        dict(title='Get API key',
             subtitle='Sign up for free openexchangerates.org account',
             valid=True,
             arg='--openapi',
             icon=ICON_WEB),
    ]

    if query:
        options = wf.filter(query, options, key=lambda d: d['title'],
                            min_score=30)

    if not options:
        wf.add_item('No matching options', 'Try a different query?',
                    icon=ICON_WARNING)

    for d in options:
        wf.add_item(**d)

    wf.send_feedback()
    return
Exemplo n.º 10
0
def main(wf):
    """Run Script Filter.

    Args:
        wf (workflow.Workflow): Workflow object.

    """
    args = docopt(__doc__, wf.args)

    log.debug('args : {!r}'.format(args))

    query = args.get('<query>')

    bootstrap(wf)

    # Alternative actions ----------------------------------------------

    if args.get('--openhelp'):
        subprocess.call(['open', README_URL])
        return

    if args.get('--openunits'):
        path = wf.datafile(CUSTOM_DEFINITIONS_FILENAME)
        subprocess.call(['open', path])
        return 0

    if args.get('--openactive'):
        path = wf.datafile(ACTIVE_CURRENCIES_FILENAME)
        subprocess.call(['open', path])
        return 0

    # Parse query ------------------------------------------------------

    if DELIMITER in query:
        return handle_delimited_query(query)

    # Filter options ---------------------------------------------------

    query = query.strip()

    options = [
        dict(title='View Help File',
             subtitle='Open help file in your browser',
             valid=True,
             arg='--openhelp',
             icon=ICON_HELP),
        dict(title='View All Supported Currencies',
             subtitle='View and search list of supported currencies',
             autocomplete=u'currencies {} '.format(DELIMITER),
             icon=ICON_CURRENCY),
        dict(title='Edit Active Currencies',
             subtitle='Edit the list of active currencies',
             valid=True,
             arg='--openactive',
             icon='icon.png'),
        dict(title='Edit Custom Units',
             subtitle='Add and edit your own custom units',
             valid=True,
             arg='--openunits',
             icon='icon.png')
    ]

    if query:
        options = wf.filter(query,
                            options,
                            key=lambda d: d['title'],
                            min_score=30)

    if not options:
        wf.add_item('No matching options',
                    'Try a different query?',
                    icon=ICON_WARNING)

    for d in options:
        wf.add_item(**d)

    wf.send_feedback()
    return