Beispiel #1
0
def getversioncfg():
    import re
    from ConfigParser import RawConfigParser

    vd0 = dict(version=FALLBACK_VERSION, commit="", date="", timestamp=0)
    # first fetch data from gitarchivecfgfile, ignore if it is unexpanded
    g = vd0.copy()
    cp0 = RawConfigParser(vd0)
    cp0.read(gitarchivecfgfile)
    if "$Format:" not in cp0.get("DEFAULT", "commit"):
        g = cp0.defaults()
        mx = re.search(r"\btag: v(\d[^,]*)", g.pop("refnames"))
        if mx:
            g["version"] = mx.group(1)
    # then try to obtain version data from git.
    gitdir = os.path.join(MYDIR, ".git")
    if os.path.exists(gitdir) or "GIT_DIR" in os.environ:
        try:
            g = gitinfo()
        except OSError:
            pass
    # finally, check and update the active version file
    cp = RawConfigParser()
    cp.read(versioncfgfile)
    d = cp.defaults()
    rewrite = not d or (g["commit"] and (g["version"] != d.get("version") or g["commit"] != d.get("commit")))
    if rewrite:
        cp.set("DEFAULT", "version", g["version"])
        cp.set("DEFAULT", "commit", g["commit"])
        cp.set("DEFAULT", "date", g["date"])
        cp.set("DEFAULT", "timestamp", g["timestamp"])
        cp.write(open(versioncfgfile, "w"))
    return cp
Beispiel #2
0
def getversioncfg():
    import re
    from ConfigParser import RawConfigParser
    vd0 = dict(version=FALLBACK_VERSION, commit='', date='', timestamp=0)
    # first fetch data from gitarchivecfgfile, ignore if it is unexpanded
    g = vd0.copy()
    cp0 = RawConfigParser(vd0)
    cp0.read(gitarchivecfgfile)
    if '$Format:' not in cp0.get('DEFAULT', 'commit'):
        g = cp0.defaults()
        mx = re.search(r'\btag: v(\d[^,]*)', g.pop('refnames'))
        if mx:
            g['version'] = mx.group(1)
    # then try to obtain version data from git.
    gitdir = os.path.join(MYDIR, '.git')
    if os.path.exists(gitdir) or 'GIT_DIR' in os.environ:
        try:
            g = gitinfo()
        except OSError:
            pass
    # finally, check and update the active version file
    cp = RawConfigParser()
    cp.read(versioncfgfile)
    d = cp.defaults()
    rewrite = not d or (g['commit'] and (
        g['version'] != d.get('version') or g['commit'] != d.get('commit')))
    if rewrite:
        cp.set('DEFAULT', 'version', g['version'])
        cp.set('DEFAULT', 'commit', g['commit'])
        cp.set('DEFAULT', 'date', g['date'])
        cp.set('DEFAULT', 'timestamp', g['timestamp'])
        cp.write(open(versioncfgfile, 'w'))
    return cp
Beispiel #3
0
def getversioncfg():
    import re
    from ConfigParser import RawConfigParser
    vd0 = dict(version=FALLBACK_VERSION, commit='', date='', timestamp=0)
    # first fetch data from gitarchivecfgfile, ignore if it is unexpanded
    g = vd0.copy()
    cp0 = RawConfigParser(vd0)
    cp0.read(gitarchivecfgfile)
    if '$Format:' not in cp0.get('DEFAULT', 'commit'):
        g = cp0.defaults()
        mx = re.search(r'\btag: v(\d[^,]*)', g.pop('refnames'))
        if mx:
            g['version'] = mx.group(1)
    # then try to obtain version data from git.
    gitdir = os.path.join(MYDIR, '.git')
    if os.path.exists(gitdir) or 'GIT_DIR' in os.environ:
        try:
            g = gitinfo()
        except OSError:
            pass
    # finally, check and update the active version file
    cp = RawConfigParser()
    cp.read(versioncfgfile)
    d = cp.defaults()
    rewrite = not d or (g['commit'] and (g['version'] != d.get('version')
                                         or g['commit'] != d.get('commit')))
    if rewrite:
        cp.set('DEFAULT', 'version', g['version'])
        cp.set('DEFAULT', 'commit', g['commit'])
        cp.set('DEFAULT', 'date', g['date'])
        cp.set('DEFAULT', 'timestamp', g['timestamp'])
        cp.write(open(versioncfgfile, 'w'))
    return cp
Beispiel #4
0
    def _parse(self, path):
        cfg = RawConfigParser(allow_no_value=True)
        cfg.optionxform = str
        cfg.read(path)

        def parse_trigger(str):
            val = str.split(" ")
            args = dict(map(lambda x: (x.split("=")[0], x.split("=")[1]), val[2:]))
            trigger = Triggers().get(val[1], args)
            trigger.roxbury = Players().get(val[0])
            return trigger

        for key in cfg.defaults():
            value = cfg.defaults()[key]
            if key == "shuffle" and value == "true":
                self._shuffle = True
            if key[:7] == "trigger":
                trigger = parse_trigger(value)
                trigger.add_playlist(self)

        for section in cfg.sections():
            pl = Playlist()
            for (key, value) in cfg.items(section):
                if not value:
                    pl.add(key)
                if key == "cron":
                    pl.schedule(value)
                if key == "shuffle" and value == "true":
                    pl._shuffle = True
                if key[:7] == "trigger":
                    trigger = parse_trigger(value)
                    trigger.add_playlist(pl)

            self.add(pl)
Beispiel #5
0
    def defaults(self):
        """Gets a dict of options & values from the DEFAULT section.

        :returns: a dict of options & values from the DEFAULT section
        :rtype: dict

        """
        return dict(RCP.defaults(self).items())
Beispiel #6
0
def read_config(filename, section='kleenex'):
    """
    This looks for [kleenex] in ``filename`` such as the following:

    [kleenex]
    db = sqlite:///coverage.db
    parent = origin/master
    discover = true
    report = true
    report_output = -
    record = true
    skip_missing = true
    max_distance = 4
    test_missing = true
    max_revisions = 100
    """
    config = RawConfigParser({
        'db': 'sqlite:///coverage.db',
        'parent': 'origin/master',
        'discover': 'false',
        'report': 'true',
        'report_output': '-',
        'record': 'false',
        'skip_missing': 'true',
        'max_distance': '4',
        'test_missing': 'true',
        'max_revisions': '100',
    }, dict_type=Config)
    config.read(filename)

    if not config.has_section(section):
        return config.defaults()

    return Config({
        'db': config.get(section, 'db'),
        'parent': config.get(section, 'parent'),
        'discover': config.getboolean(section, 'discover'),
        'report': config.getboolean(section, 'report'),
        'report_output': config.get(section, 'report_output'),
        'record': config.getboolean(section, 'record'),
        'skip_missing': config.getboolean(section, 'skip_missing'),
        'max_distance': config.getint(section, 'max_distance'),
        'test_missing': config.getboolean(section, 'test_missing'),
        'max_revisions': config.getint(section, 'max_revisions'),
    })
Beispiel #7
0
    def __init__(self):
        self.request_in = ''
        self.request_out = {}
        self.response_out = {}

        # Config
        configFile = r'/etc/swift/object-server.conf'
        self.conf = readconf(configFile)
        # readconf does not load the [DEFAULT] section, adding that manually
        rcp = RawConfigParser()
        cf = open(configFile, 'r')
        rcp.readfp(cf)
        full_conf = self.conf.copy()
        full_conf.update(rcp.defaults())
        cf.close()
        self.conf = full_conf

        # Logging
        hlm_stor_node_config = self.conf.get('hlm', None)
        if hlm_stor_node_config:
            hlm_stor_node_log_level = hlm_stor_node_config.get(
                'set log_level', None)
        if hlm_stor_node_log_level:
            self.conf['log_level'] = hlm_stor_node_log_level
        self.logger = get_logger(self.conf,
                                 name='hlm-handler',
                                 log_route='swifthlm',
                                 fmt="%(server)s: %(msecs)03d "
                                 "[%(filename)s:%(funcName)20s():%(lineno)s] "
                                 "%(message)s")

        self.logger.info('info: Initialized Handler')
        self.logger.debug('dbg: Initialized Handler')
        # self.logger.info('conf: %s', self.conf)

        # Generic backend interface (GBI) configuration options
        self.gbi_provide_dirpaths_instead_of_filepaths = False
        conf_gbi_provide_dirpaths_instead_of_filepaths = \
            hlm_stor_node_config.get(
                'gbi_provide_dirpaths_instead_of_filepaths',
                'False')
        if conf_gbi_provide_dirpaths_instead_of_filepaths == 'True':
            self.gbi_provide_dirpaths_instead_of_filepaths = True

        # Backend connector (directory and .py filename) can be configured in
        # /etc/swift/object-server.conf
        # If nothing is configured a dummy backend connector, that is provided
        # and installed with SwiftHLM is used by default
        swifthlm_connector_module = hlm_stor_node_config.get(
            'swifthlm_connector_module', '')
        swifthlm_connector_dir = hlm_stor_node_config.get(
            'swifthlm_connector_dir', '')
        swifthlm_connector_filename = hlm_stor_node_config.get(
            'swifthlm_connector_filename', '')
        swifthlm_connector_path = swifthlm_connector_dir + '/' + \
            swifthlm_connector_filename
        if swifthlm_connector_module:
            self.logger.debug('swifthlm_connector_module: %s',
                              swifthlm_connector_module)
            self.swifthlm_connector_mod = \
                importlib.import_module(swifthlm_connector_module,
                                        package=None)
        elif swifthlm_connector_filename:
            swifthlm_connector_module = swifthlm_connector_filename[:-3]
            self.logger.debug('swifthlm_connector_path: %s',
                              swifthlm_connector_path)
            self.swifthlm_connector_mod = imp.load_source(
                swifthlm_connector_module, swifthlm_connector_path)
        else:
            self.logger.debug('Using default swifthlm_connector_module: %s',
                              'swifthlm.dummy_connector')
            self.swifthlm_connector_mod = swifthlm.dummy_connector
Beispiel #8
0
def configure_forge():
    """configures service definitions in forge configuration file"""
    # read forge configuration
    config = RawConfigParser()
    config.read(FORGE_CONFIG_TEMPLATE)
    # merge COMMON definitions (if any) into application section
    copy_section(config, "COMMON", FORGE_CONFIG_SECTION)
    # configure data services using private IP address
    for service in DATA_SERVICES:
        try:
            value = DATA_SERVICES_DEFAULT_LOCATION
            msg = "Configuring service '{}' at IP address {}."
            LOG.info(msg.format(service, value))
            defn = FORGE_CONFIG_DATA[service]
            if "template" in defn:
                value = defn["template"].format(value)
            for idef in defn['items']:
                section, items = idef[0], idef[1:]
                for item in items:
                    config.set(section, item, value)
        except Exception as e:
            LOG.exception("Unable to configure service '{}'.".format(service))
    # miscellaneous settings for quick start development deployment
    config.set("DEFAULT", "static_recipes_dir", FORGE_STATIC_RESOURCES)
    config.set("DEFAULT", "static_resources_dir", FORGE_STATIC_RESOURCES)
    config.set("DEFAULT", "smtp_port", "25")
    config.set("DEFAULT", 'auth.ws.token', random_hexstring(40))
    if 'DOCKER_HOST' in os.environ:
        dh = urlparse(os.environ['DOCKER_HOST']).netloc.split(':')[0]
        url = "http://{}:8080".format(dh)
        config.set(FORGE_CONFIG_SECTION, "base_url", url)
    config.set(FORGE_CONFIG_SECTION, "s3.port", "4569")
    config.set(FORGE_CONFIG_SECTION, "s3.ssl", "false")
    config.set(FORGE_CONFIG_SECTION, "templates.login",
               "jinja:vehicleforge:templates/auth/login-brochure.html")
    config.set(FORGE_CONFIG_SECTION, "visibility_mode", "closed")
    config.set(FORGE_CONFIG_SECTION, "moderate_registration", "false")
    config.set(FORGE_CONFIG_SECTION, 'site_issues_url',
               "/projects/helpdesk/tickets")
    for key in ('validate', 'encrypt'):
        setting = "beaker.session.{}_key".format(key)
        config.set(FORGE_CONFIG_SECTION, setting, random_hexstring())
    log_path = join(FORGE_CONFIG_LOGS, 'rtstats.log')
    config.set("handler_stats", "args",
               "('{}', 'vehicleforge', 1)".format(log_path))
    config.set(FORGE_CONFIG_SECTION, "scm.repos.root", "/")
    # configure repository services
    for service in REPO_SERVICES:
        try:
            section = FORGE_CONFIG_SECTION
            service_host = "localhost"
            if 'DOCKER_HOST' in os.environ:
                dh = urlparse(os.environ['DOCKER_HOST']).netloc.split(':')[0]
                service_host = dh
            msg = "Configuring repository service '{}' at IP address {}."
            LOG.info(msg.format(service, service_host))
            config.set(section, "scm.domain." + service, service_host)
            template = "scm.port.{}." + service
            for access in REPO_SERVICES[service]:
                try:
                    port = REPO_SERVICES[service][access]
                    msg = "Configuring {} access for service '{}' on port {}."
                    LOG.info(msg.format(access.upper(), service, port))
                    config.set(section, template.format(access), port)
                except Exception as e:
                    pass
            os.symlink(FORGE_CONFIG_REPOSITORIES, "/" + service)
        except Exception as e:
            pass
    # setup bootstrap
    config.set(FORGE_CONFIG_SECTION, "load_initial_data", FORGE_BOOTSTRAP_DATA)
    # save configuration
    with open(FORGE_CONFIG_PATH, "w") as f:
        config.write(f)
    return config.defaults()['auth.ws.token']
Beispiel #9
0
def get_options():
    """
    Read options from command line or from configuration file.
    """
    default_database = rel('%s.db' % __script__)
    names = ('database', 'password', 'username')
    result = {}

    # At first, read options from command line
    args = sys.argv[1:]
    description = 'Script to check who of your Facebook friends were removed '\
                  'from FB or unfriend you.'

    parser = ArgumentParser(description=description)
    add_argument(parser,
                 '-u',
                 '--username',
                 default=None,
                 dest='username',
                 metavar='FACEBOOK_USERNAME')
    add_argument(parser,
                 '-p',
                 '--password',
                 default=None,
                 dest='password',
                 metavar='FACEBOOK_PASSWORD')
    add_argument(parser,
                 '-d',
                 '--database',
                 default=None,
                 dest='database',
                 help='Path to database. By default: %s' % default_database)

    try:
        options, _ = parser.parse_args(args)
    except TypeError:
        options = parser.parse_args(args)

    for name in names:
        result.update({name: getattr(options, name, None)})

    # Next, check for configuration file values
    if not result['password'] or not result['username']:
        config_file = rel('%s.conf' % __script__)
        config_parser = RawConfigParser()

        try:
            config_parser.read(config_file)
        except ConfigParserError:
            pass
        else:
            values = config_parser.defaults()

            for name in names:
                if name == 'database' and result['database']:
                    continue
                result.update({name: values.get(name)})

    # Finally, get ability to input configuration
    for name in ('username', 'password'):
        if result[name]:
            continue
        func = getpass.getpass if name == 'password' else raw_input
        result.update({name: func('Facebook %s: ' % name)})

    if not result['database']:
        result['database'] = default_database

    return result.copy()