Exemple #1
0
    def add_provider(self, name, provider_type, **config):
        """Adds a provider by name, type and configuration.
        Storea provider indexed by name.
        """

        self._providers[name] = get_provider(provider_type, self.output,
                                             **config)
def main(args=None):
    """The main routine."""
    if args is None:
        args = sys.argv[1:]

    setup_logging()

    parser = _create_parser()
    args = parser.parse_args()

    if args.version:
        print __version__
        sys.exit()

    # provider selection: prioritize args over over E=CUCLOUD_PROVIDER
    if args.provider:
        provider_name = args.provider
    elif os.environ.has_key('CUCLOUD_PROVIDER'):
        provider_name = os.environ.get('CUCLOUD_PROVIDER')
    else:
        provider_name = 'aws'

    # profile selection: prioritize args over E=CUCLOUD_PROFILE
    if args.profile:
        profile_name = args.profile
        logging.info('Using cloud profile "%s" set via arguments',
                     profile_name)
    elif os.environ.has_key('CUCLOUD_PROFILE'):
        profile_name = os.environ.get('CUCLOUD_PROFILE')
        logging.info('Using cloud profile "%s" set in env', profile_name)
    else:
        logging.fatal('No cloud profile selected')
        raise Exception(
            'Cloud profile must be configured or set via command line')

    # env selection: prioritize args over E=CUCLOUD_ENV
    if args.env:
        env_name = args.env
        logging.info('Using profile environment "%s" set via arguments',
                     env_name)
    elif os.environ.has_key('CUCLOUD_ENV'):
        env_name = os.environ.get('CUCLOUD_ENV')
        logging.info('Using profile environment "%s" set via arguments',
                     env_name)
    else:
        logging.fatal('No profile environment selected')
        raise Exception(
            'Cloud profile environment must be configured or set via command line'
        )

    provider = providers.get_provider(provider_name, profile_name, env_name)

    return provider.handle_args(args)
Exemple #3
0
def main():
    gpus_to_check_stock = ['rtx_3060_ti', 'rx_6900_xt', 'rx_5700_xt']
    for gpu in gpus_to_check_stock:
        providers = get_providers_for_gpu(gpu)
        for provider in providers:
            _provider = get_provider(provider)
            _provider.name = provider
            _provider.iid = get_gpu_iid(gpu, _provider.name)
            Pipeline('gpu').send(_provider)

            for _gpu in _provider.normalized:
                print(_gpu.__dict__)
            print('-------')
def main(args=None):
    """The main routine."""
    if args is None:
        args = sys.argv[1:]

    setup_logging()

    parser = _create_parser()
    args = parser.parse_args()

    if args.version:
        print __version__
        sys.exit()

    # provider selection: prioritize args over over E=CUCLOUD_PROVIDER
    if args.provider:
        provider_name = args.provider
    elif os.environ.has_key('CUCLOUD_PROVIDER'):
        provider_name = os.environ.get('CUCLOUD_PROVIDER')
    else:
        provider_name = 'aws'

    # profile selection: prioritize args over E=CUCLOUD_PROFILE
    if args.profile:
        profile_name = args.profile
        logging.info('Using cloud profile "%s" set via arguments', profile_name)
    elif os.environ.has_key('CUCLOUD_PROFILE'):
        profile_name = os.environ.get('CUCLOUD_PROFILE')
        logging.info('Using cloud profile "%s" set in env', profile_name)
    else:
        logging.fatal('No cloud profile selected')
        raise Exception('Cloud profile must be configured or set via command line')

    # env selection: prioritize args over E=CUCLOUD_ENV
    if args.env:
        env_name = args.env
        logging.info('Using profile environment "%s" set via arguments', env_name)
    elif os.environ.has_key('CUCLOUD_ENV'):
        env_name = os.environ.get('CUCLOUD_ENV')
        logging.info('Using profile environment "%s" set via arguments', env_name)
    else:
        logging.fatal('No profile environment selected')
        raise Exception('Cloud profile environment must be configured or set via command line')

    provider = providers.get_provider(provider_name, profile_name, env_name)

    return provider.handle_args(args)
Exemple #5
0
def main():
    logging.root.setLevel(logging.INFO)
    logging.info("Starting up email queue")

    session = database.get_session(config.database)
    provider = providers.get_provider(config.provider)
    processor = queue.QueueProcessor(config, session, provider)

    try:
        while not interrupted:
            logging.debug("checking email queue")
            processor.process()
            time.sleep(config.queue.getfloat('sleep_seconds', 10))
    except Exception as e:
        logging.critical(e.message)
    finally:
        database.close_connection()
Exemple #6
0
async def fetch_data(url: str) -> None:
    provider: BaseProvider = get_provider(url)
    await provider.fetch()
Exemple #7
0
def update():
    parser = OptionParser()
    parser.add_option('-p', '--project', dest='project',
                      help='Path to the Trac project.')
    (options, args) = parser.parse_args(sys.argv[1:])

    if not options.project:
        print "Must specify path to Trac project (environment)."
        return 1

    if not 'PYTHON_EGG_CACHE' in os.environ:
        os.environ['PYTHON_EGG_CACHE'] = os.path.join(options.project, '.egg-cache')

    from trac.env import open_environment
    env = open_environment(options.project)
    config = {}
    ttl = 7 # only show a mention again after 7 days
    for i in env.config.options('tracmentions'):
        if i[0]=='ttl':
            ttl = int(i[1])
        bits = i[0].split('.')
        if bits[0]=='provider':
            if len(bits)==2:
                __import__(i[1])
                providers.register_provider(bits[1], sys.modules[i[1]].Provider)
        else:
            cur = config
            last = None
            for b in bits:
                if not cur.has_key(b):
                    cur[b] = {}
                last = cur
                cur = cur[b]
            last[b] = i[1]
            
    db = env.get_db_cnx()
    cursor = db.cursor()

    for pname in config.keys():
        try:
            conf = config[pname]
            provider = providers.get_provider(pname)
            if provider==None:
                print "%s doesn't match a provider; skipping." % pname
            else:
                p = provider(conf)
                mentions = p.get_mentions(cursor)
                for mention in mentions:
                    # if the uri is new or hasn't been seen in <ttl> days
                    print unicode(mention).encode('utf-8')
                    cursor.execute("SELECT at FROM mentions WHERE uri=%s", (mention.uri,))
                    row = cursor.fetchone()
                    if row!=None:
                        # when did we see it before?
                        #then = datetime.fromtimestamp(row[0])
                        then = row[0]
                        if (mention.at - then) < 86400 * ttl or mention.at==then:
                            # either identical (ie we've already go this), or
                            # not long enough ago to repost, so skip this
                            #
                            # (note that the or leg of that conditional will never be evaluated,
                            # because it's true only if the first leg is true. however this makes
                            # intent clearer)
                            print "(Skipping.)"
                            continue
                    cursor.execute(
                        "INSERT INTO mentions (mentioned, location, uri, text, at) VALUES (%s, %s, %s, %s, %s)",
                        (
                            mention.mentioned,
                            pname,
                            mention.uri,
                            mention.text,
                            mention.at,
                        )
                    )
        except:
            print "%s failed, skipping. Backtrace:" % pname
            import traceback
            traceback.print_exc()
    db.commit()
    return 0
Exemple #8
0
def get_driver(provider):
    if type(provider) is str:
        return Driver(providers.get_provider(provider))
    else:
        return Driver(provider())
def test__get_provider__raises_exception_on_invalid(invalid_repo_strings):
    for repo in invalid_repo_strings:
        with pytest.raises(NoProviderFound):
            get_provider(repo)
def test__get_provider__returns_provider(repo_strings):
    for repo in repo_strings:
        provider = get_provider(repo)
        assert isinstance(provider, BaseProvider)