Python ConfigParser.RawConfigParser() Examples

The following are 30 code examples of ConfigParser.RawConfigParser(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module ConfigParser , or try the search function .
Example #1
Source Project: vt-ida-plugin   Author: VirusTotal   File: plugin_loader.py    License: Apache License 2.0 6 votes vote down vote up
def read_config(self):
    """Read the user's configuration file."""

    logging.debug('[VT Plugin] Reading user config file: %s', self.vt_cfgfile)
    config_file = configparser.RawConfigParser()
    config_file.read(self.vt_cfgfile)

    try:
      if config_file.get('General', 'auto_upload') == 'True':
        self.auto_upload = True
      else:
        self.auto_upload = False
      return True
    except:
      logging.error('[VT Plugin] Error reading the user config file.')
      return False 
Example #2
Source Project: recruit   Author: Frank-qlu   File: system_info.py    License: Apache License 2.0 6 votes vote down vote up
def __init__(self,
                  default_lib_dirs=default_lib_dirs,
                  default_include_dirs=default_include_dirs,
                  verbosity=1,
                  ):
        self.__class__.info = {}
        self.local_prefixes = []
        defaults = {'library_dirs': os.pathsep.join(default_lib_dirs),
                    'include_dirs': os.pathsep.join(default_include_dirs),
                    'runtime_library_dirs': os.pathsep.join(default_runtime_dirs),
                    'rpath': '',
                    'src_dirs': os.pathsep.join(default_src_dirs),
                    'search_static_first': str(self.search_static_first),
                    'extra_compile_args': '', 'extra_link_args': ''}
        self.cp = ConfigParser(defaults)
        self.files = []
        self.files.extend(get_standard_file('.numpy-site.cfg'))
        self.files.extend(get_standard_file('site.cfg'))
        self.parse_config_files()

        if self.section is not None:
            self.search_static_first = self.cp.getboolean(
                self.section, 'search_static_first')
        assert isinstance(self.search_static_first, int) 
Example #3
Source Project: genmon   Author: jgyates   File: myconfig.py    License: GNU General Public License v2.0 6 votes vote down vote up
def __init__(self, filename = None, section = None, simulation = False, log = None):

        super(MyConfig, self).__init__()
        self.log = log
        self.FileName = filename
        self.Section = section
        self.Simulation = simulation
        self.CriticalLock = threading.Lock()        # Critical Lock (writing conf file)
        self.InitComplete = False
        try:
            self.config = RawConfigParser()
            self.config.read(self.FileName)

            if self.Section == None:
                SectionList = self.GetSections()
                if len(SectionList):
                    self.Section = SectionList[0]

        except Exception as e1:
            self.LogErrorLine("Error in MyConfig:init: " + str(e1))
            return
        self.InitComplete = True
    #---------------------MyConfig::HasOption----------------------------------- 
Example #4
Source Project: rucio   Author: rucio   File: srmdumps.py    License: Apache License 2.0 6 votes vote down vote up
def generate_url(rse, config):
    '''
    :param rse: Name of the endpoint.
    :param config: RawConfigParser instance which may have configuration
    related to the endpoint.
    :returns: Tuple with the URL where the links can be queried to find new
    dumps and the pattern used to parse the date of the dump of the files/directories
    listed..
    '''
    site = rse.split('_')[0]
    if site not in config.sections():
        base_url = ddmendpoint_url(rse) + 'dumps'
        url_pattern = 'dump_%Y%m%d'
    else:
        url_components = config.get(site, rse).split('/')
        # The pattern may not be the last component
        pattern_index = next(idx for idx, comp in enumerate(url_components) if '%m' in comp)
        base_url = '/'.join(url_components[:pattern_index])
        url_pattern = '/'.join(url_components[pattern_index:])

    return base_url, url_pattern 
Example #5
Source Project: mysql_utils   Author: pinterest   File: mysql_cnf_builder.py    License: GNU General Public License v2.0 6 votes vote down vote up
def create_skip_replication_cnf(override_dir=None):
    """ Create a secondary cnf file that will allow for mysql to skip
        replication start. Useful for running mysql upgrade, etc...

    Args:
    override_dir - Write to this directory rather than CNF_DIR
    """
    skip_replication_parser = ConfigParser.RawConfigParser(allow_no_value=True)
    skip_replication_parser.add_section(MYSQLD_SECTION)
    skip_replication_parser.set(MYSQLD_SECTION, 'skip_slave_start', None)
    if override_dir:
        skip_slave_path = os.path.join(override_dir,
                                       os.path.basename(host_utils.MYSQL_NOREPL_CNF_FILE))
    else:
        skip_slave_path = host_utils.MYSQL_NOREPL_CNF_FILE
    log.info('Writing file {skip_slave_path}'
             ''.format(skip_slave_path=skip_slave_path))
    with open(skip_slave_path, "w") as skip_slave_handle:
            skip_replication_parser.write(skip_slave_handle) 
Example #6
Source Project: lambda-packs   Author: ryfeus   File: system_info.py    License: MIT License 6 votes vote down vote up
def __init__(self,
                  default_lib_dirs=default_lib_dirs,
                  default_include_dirs=default_include_dirs,
                  verbosity=1,
                  ):
        self.__class__.info = {}
        self.local_prefixes = []
        defaults = {'library_dirs': os.pathsep.join(default_lib_dirs),
                    'include_dirs': os.pathsep.join(default_include_dirs),
                    'runtime_library_dirs': os.pathsep.join(default_runtime_dirs),
                    'rpath': '',
                    'src_dirs': os.pathsep.join(default_src_dirs),
                    'search_static_first': str(self.search_static_first),
                    'extra_compile_args': '', 'extra_link_args': ''}
        self.cp = ConfigParser(defaults)
        self.files = []
        self.files.extend(get_standard_file('.numpy-site.cfg'))
        self.files.extend(get_standard_file('site.cfg'))
        self.parse_config_files()

        if self.section is not None:
            self.search_static_first = self.cp.getboolean(
                self.section, 'search_static_first')
        assert isinstance(self.search_static_first, int) 
Example #7
Source Project: lambda-packs   Author: ryfeus   File: system_info.py    License: MIT License 6 votes vote down vote up
def __init__(self,
                  default_lib_dirs=default_lib_dirs,
                  default_include_dirs=default_include_dirs,
                  verbosity=1,
                  ):
        self.__class__.info = {}
        self.local_prefixes = []
        defaults = {'library_dirs': os.pathsep.join(default_lib_dirs),
                    'include_dirs': os.pathsep.join(default_include_dirs),
                    'runtime_library_dirs': os.pathsep.join(default_runtime_dirs),
                    'rpath': '',
                    'src_dirs': os.pathsep.join(default_src_dirs),
                    'search_static_first': str(self.search_static_first),
                    'extra_compile_args': '', 'extra_link_args': ''}
        self.cp = ConfigParser(defaults)
        self.files = []
        self.files.extend(get_standard_file('.numpy-site.cfg'))
        self.files.extend(get_standard_file('site.cfg'))
        self.parse_config_files()

        if self.section is not None:
            self.search_static_first = self.cp.getboolean(
                self.section, 'search_static_first')
        assert isinstance(self.search_static_first, int) 
Example #8
Source Project: auto-alt-text-lambda-api   Author: abhisuri97   File: system_info.py    License: MIT License 6 votes vote down vote up
def __init__(self,
                  default_lib_dirs=default_lib_dirs,
                  default_include_dirs=default_include_dirs,
                  verbosity=1,
                  ):
        self.__class__.info = {}
        self.local_prefixes = []
        defaults = {'library_dirs': os.pathsep.join(default_lib_dirs),
                    'include_dirs': os.pathsep.join(default_include_dirs),
                    'runtime_library_dirs': os.pathsep.join(default_runtime_dirs),
                    'rpath': '',
                    'src_dirs': os.pathsep.join(default_src_dirs),
                    'search_static_first': str(self.search_static_first),
                    'extra_compile_args': '', 'extra_link_args': ''}
        self.cp = ConfigParser(defaults)
        self.files = []
        self.files.extend(get_standard_file('.numpy-site.cfg'))
        self.files.extend(get_standard_file('site.cfg'))
        self.parse_config_files()
        if self.section is not None:
            self.search_static_first = self.cp.getboolean(
                self.section, 'search_static_first')
        assert isinstance(self.search_static_first, int) 
Example #9
Source Project: faces   Author: skarlekar   File: frontend.py    License: GNU General Public License v2.0 6 votes vote down vote up
def read(self, filenames, option_parser):
        if type(filenames) in (str, unicode):
            filenames = [filenames]
        for filename in filenames:
            try:
                # Config files must be UTF-8-encoded:
                fp = codecs.open(filename, 'r', 'utf-8')
            except IOError:
                continue
            try:
                if sys.version_info < (3,2):
                    CP.RawConfigParser.readfp(self, fp, filename)
                else:
                    CP.RawConfigParser.read_file(self, fp, filename)
            except UnicodeDecodeError:
                self._stderr.write(self.not_utf8_error % (filename, filename))
                fp.close()
                continue
            fp.close()
            self._files.append(filename)
            if self.has_section('options'):
                self.handle_old_config(filename)
            self.validate_settings(filename, option_parser) 
Example #10
Source Project: vnpy_crypto   Author: birforce   File: system_info.py    License: MIT License 6 votes vote down vote up
def __init__(self,
                  default_lib_dirs=default_lib_dirs,
                  default_include_dirs=default_include_dirs,
                  verbosity=1,
                  ):
        self.__class__.info = {}
        self.local_prefixes = []
        defaults = {'library_dirs': os.pathsep.join(default_lib_dirs),
                    'include_dirs': os.pathsep.join(default_include_dirs),
                    'runtime_library_dirs': os.pathsep.join(default_runtime_dirs),
                    'rpath': '',
                    'src_dirs': os.pathsep.join(default_src_dirs),
                    'search_static_first': str(self.search_static_first),
                    'extra_compile_args': '', 'extra_link_args': ''}
        self.cp = ConfigParser(defaults)
        self.files = []
        self.files.extend(get_standard_file('.numpy-site.cfg'))
        self.files.extend(get_standard_file('site.cfg'))
        self.parse_config_files()

        if self.section is not None:
            self.search_static_first = self.cp.getboolean(
                self.section, 'search_static_first')
        assert isinstance(self.search_static_first, int) 
Example #11
Source Project: xuebao   Author: niutool   File: pluginstore.py    License: MIT License 6 votes vote down vote up
def parse_info_file(infofile_path):
    logger = logging.getLogger(__name__)
    cp = configparser.RawConfigParser()
    cp.read(infofile_path)

    options_missing = False
    for option in MANDATORY_OPTIONS:
        if not cp.has_option(*option):
            options_missing = True
            logger.debug("Plugin info file '%s' missing value '%s'", infofile_path, option)
    
    if options_missing:
        raise PluginError("Info file is missing values!")
    
    logger.debug("Plugin info file '%s' parsed successfully!", infofile_path)
    return cp 
Example #12
Source Project: origin-ci-tool   Author: openshift   File: openshift_facts.py    License: Apache License 2.0 6 votes vote down vote up
def get_hosted_registry_insecure():
    """ Parses OPTIONS from /etc/sysconfig/docker to determine if the
        registry is currently insecure.
    """
    hosted_registry_insecure = None
    if os.path.exists('/etc/sysconfig/docker'):
        try:
            ini_str = unicode('[root]\n' + open('/etc/sysconfig/docker', 'r').read(), 'utf-8')
            ini_fp = io.StringIO(ini_str)
            config = ConfigParser.RawConfigParser()
            config.readfp(ini_fp)
            options = config.get('root', 'OPTIONS')
            if 'insecure-registry' in options:
                hosted_registry_insecure = True
        except:
            pass
    return hosted_registry_insecure 
Example #13
Source Project: origin-ci-tool   Author: openshift   File: openshift_facts.py    License: Apache License 2.0 6 votes vote down vote up
def get_hosted_registry_insecure():
    """ Parses OPTIONS from /etc/sysconfig/docker to determine if the
        registry is currently insecure.
    """
    hosted_registry_insecure = None
    if os.path.exists('/etc/sysconfig/docker'):
        try:
            ini_str = unicode('[root]\n' + open('/etc/sysconfig/docker', 'r').read(), 'utf-8')
            ini_fp = io.StringIO(ini_str)
            config = ConfigParser.RawConfigParser()
            config.readfp(ini_fp)
            options = config.get('root', 'OPTIONS')
            if 'insecure-registry' in options:
                hosted_registry_insecure = True
        except:
            pass
    return hosted_registry_insecure 
Example #14
Source Project: origin-ci-tool   Author: openshift   File: openshift_facts.py    License: Apache License 2.0 6 votes vote down vote up
def get_hosted_registry_insecure():
    """ Parses OPTIONS from /etc/sysconfig/docker to determine if the
        registry is currently insecure.
    """
    hosted_registry_insecure = None
    if os.path.exists('/etc/sysconfig/docker'):
        try:
            ini_str = unicode('[root]\n' + open('/etc/sysconfig/docker', 'r').read(), 'utf-8')
            ini_fp = io.StringIO(ini_str)
            config = ConfigParser.RawConfigParser()
            config.readfp(ini_fp)
            options = config.get('root', 'OPTIONS')
            if 'insecure-registry' in options:
                hosted_registry_insecure = True
        except:
            pass
    return hosted_registry_insecure 
Example #15
Source Project: Mastering-Elasticsearch-7.0   Author: PacktPublishing   File: system_info.py    License: MIT License 6 votes vote down vote up
def __init__(self,
                  default_lib_dirs=default_lib_dirs,
                  default_include_dirs=default_include_dirs,
                  verbosity=1,
                  ):
        self.__class__.info = {}
        self.local_prefixes = []
        defaults = {'library_dirs': os.pathsep.join(default_lib_dirs),
                    'include_dirs': os.pathsep.join(default_include_dirs),
                    'runtime_library_dirs': os.pathsep.join(default_runtime_dirs),
                    'rpath': '',
                    'src_dirs': os.pathsep.join(default_src_dirs),
                    'search_static_first': str(self.search_static_first),
                    'extra_compile_args': '', 'extra_link_args': ''}
        self.cp = ConfigParser(defaults)
        self.files = []
        self.files.extend(get_standard_file('.numpy-site.cfg'))
        self.files.extend(get_standard_file('site.cfg'))
        self.parse_config_files()

        if self.section is not None:
            self.search_static_first = self.cp.getboolean(
                self.section, 'search_static_first')
        assert isinstance(self.search_static_first, int) 
Example #16
Source Project: QMusic   Author: dragondjf   File: config.py    License: GNU Lesser General Public License v2.1 6 votes vote down vote up
def __init__(self, config_file, default_config=None):
        '''
        Init config module.

        @param config_file: Config filepath.
        @param default_config: Default config value use when config file is empty.
        '''
        gobject.GObject.__init__(self)
        self.config_parser = ConfigParser()
        self.remove_option = self.config_parser.remove_option
        self.has_option = self.config_parser.has_option
        self.add_section = self.config_parser.add_section
        self.getboolean = self.config_parser.getboolean
        self.getint = self.config_parser.getint
        self.getfloat = self.config_parser.getfloat
        self.options = self.config_parser.options
        self.items = self.config_parser.items
        self.config_file = config_file
        self.default_config = default_config

        # Load default configure.
        self.load_default() 
Example #17
Source Project: hubic-wrapper-to-swift   Author: puzzle1536   File: hubic.py    License: GNU General Public License v3.0 5 votes vote down vote up
def __del__(self):
        if self.config_file:
            if options.verbose:
                print "-- Write config file back : %s " % self.config_file
            self.hubic_config = ConfigParser.RawConfigParser()

            self.hubic_config.add_section('hubic')
            if self.client_id:
                self.hubic_config.set('hubic', 'client_id', self.client_id)
            if self.client_secret:
                self.hubic_config.set('hubic', 'client_secret', self.client_secret)
            if self.redirect_uri:
                self.hubic_config.set('hubic', 'redirect_uri', self.redirect_uri)
            if self.username:
                self.hubic_config.set('hubic', 'username', self.username)
            if self.password:
                self.hubic_config.set('hubic', 'password', self.password)
            if self.refresh_token:
                self.hubic_config.set('hubic', 'refresh_token', self.refresh_token)
            if self.access_token:
                self.hubic_config.set('hubic', 'access_token', self.access_token)
            if self.token_expire:
                self.hubic_config.set('hubic', 'token_expire', self.token_expire)

            self.hubic_config.add_section('openstack')
            if self.os_auth_token:
                self.hubic_config.set('openstack', 'os_auth_token', self.os_auth_token)
            if self.os_storage_url:
                self.hubic_config.set('openstack', 'os_storage_url', self.os_storage_url)
            if self.os_token_expire:
                self.hubic_config.set('openstack', 'os_token_expire', self.os_token_expire)

            with open(self.config_file, 'wb') as configfile:
                self.hubic_config.write(configfile)
            os.chmod(self.config_file, 0600) 
Example #18
Source Project: python_labview_automation   Author: ni   File: labview.py    License: MIT License 5 votes vote down vote up
def create_temp_ini(self, options={}):
        ini = ConfigParser.RawConfigParser()
        # iterate over sections
        for section, tokens in options.iteritems():
            ini.add_section(section)
            for key, value in tokens.iteritems():
                ini.set(section, key, value)

        fd, path = tempfile.mkstemp(suffix=".ini")
        with os.fdopen(fd, 'w') as f:
            ini.write(f)
        return path 
Example #19
Source Project: Radium   Author: mehulj94   File: Mozilla.py    License: Apache License 2.0 5 votes vote down vote up
def get_firefox_profiles(self, directory):
        cp = RawConfigParser()
        cp.read(os.path.join(directory, 'profiles.ini'))
        profile_list = []
        for section in cp.sections():
            if section.startswith('Profile'):
                if cp.has_option(section, 'Path'):
                    profile_list.append(os.path.join(directory, cp.get(section, 'Path').strip()))
        return profile_list 
Example #20
Source Project: easygui_qt   Author: aroberge   File: easygui_qt.py    License: BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def save_config(self):
        config = configparser.RawConfigParser()
        config.add_section('Configuration')
        config.set('Configuration', 'locale', self.config['locale'])
        config.set('Configuration', 'font-size', self.config['font-size'])
        with open(self.config_path, 'w') as configfile:
            config.write(configfile) 
Example #21
Source Project: easygui_qt   Author: aroberge   File: easygui_qt.py    License: BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def load_config(self):
        # Todo: make more robust
        config = configparser.RawConfigParser()
        self.config = {}
        try:
            config.read(self.config_path)
            self.config['locale'] = config.get('Configuration', 'locale')
            self.set_locale(self.config['locale'], save=False)
            self.config['font-size'] = config.getint('Configuration', 'font-size')
            self.set_font_size(self.config['font-size'], save=False)
        except:
            print("Problem encountered in load_config.")
            self.config = {'locale': 'default', 'font-size': 12}
            return 
Example #22
Source Project: llvm-zorg   Author: llvm   File: util.py    License: Apache License 2.0 5 votes vote down vote up
def __init__(self, path):
        self.path = path
        self.config_path = os.path.join(path, "config")
        self.options = ConfigParser.RawConfigParser()

        # Load the config file, if present.
        if os.path.exists(self.config_path):
            self.options.read(self.config_path) 
Example #23
Source Project: JetPack   Author: dsp-jetpack   File: db_cleanup.py    License: Apache License 2.0 5 votes vote down vote up
def _init_db_conf(self):
        """Create default db config file."""
        LOG.debug("Initialize database configuration")
        config = ConfigParser.RawConfigParser()

        secs = ['cinder', 'keystone', 'heat', 'nova', 'swift']
        for sec in secs:
            config.add_section(sec)
            config.set(sec, 'host', 'localhost')
            config.set(sec, 'db', sec)
            config.set(sec, 'user', sec)
            config.set(sec, 'passwd', 'foreman')

        with open(CLEANUP_DB_CONF, 'wb') as config_file:
            config.write(config_file) 
Example #24
Source Project: ServerlessCrawler-VancouverRealState   Author: MarcelloLins   File: optionfile.py    License: MIT License 5 votes vote down vote up
def get(self, section, option):
        value = configparser.RawConfigParser.get(self, section, option)
        return self.__remove_quotes(value) 
Example #25
Source Project: recruit   Author: Frank-qlu   File: npy_pkg_config.py    License: Apache License 2.0 5 votes vote down vote up
def parse_config(filename, dirs=None):
    if dirs:
        filenames = [os.path.join(d, filename) for d in dirs]
    else:
        filenames = [filename]

    config = RawConfigParser()

    n = config.read(filenames)
    if not len(n) >= 1:
        raise PkgNotFound("Could not find file(s) %s" % str(filenames))

    # Parse meta and variables sections
    meta = parse_meta(config)

    vars = {}
    if config.has_section('variables'):
        for name, value in config.items("variables"):
            vars[name] = _escape_backslash(value)

    # Parse "normal" sections
    secs = [s for s in config.sections() if not s in ['meta', 'variables']]
    sections = {}

    requires = {}
    for s in secs:
        d = {}
        if config.has_option(s, "requires"):
            requires[s] = config.get(s, 'requires')

        for name, value in config.items(s):
            d[name] = value
        sections[s] = d

    return meta, vars, sections, requires 
Example #26
Source Project: mysql_utils   Author: pinterest   File: mysql_cnf_builder.py    License: GNU General Public License v2.0 5 votes vote down vote up
def create_root_cnf(cnf_parser, override_dir):
    """ Create a .my.cnf file to setup defaults for username/password

    Args:
    cnf_parser - A ConfigParser object of mysqld settings
    override_dir - Write to this directory rather than default
    """
    admin_user, admin_password = mysql_lib.get_mysql_user_for_role('admin')
    dump_user, dump_password = mysql_lib.get_mysql_user_for_role('mysqldump')
    parser = ConfigParser.RawConfigParser(allow_no_value=True)
    parser.add_section('mysql')
    parser.set('mysql', 'user', admin_user)
    parser.set('mysql', 'password', admin_password)
    parser.set('mysql', 'socket', cnf_parser.get(MYSQLD_SECTION, 'socket'))
    parser.add_section('mysqladmin')
    parser.set('mysqladmin', 'user', admin_user)
    parser.set('mysqladmin', 'password', admin_password)
    parser.set('mysqladmin', 'socket', cnf_parser.get(MYSQLD_SECTION, 'socket'))
    parser.add_section('mysqldump')
    parser.set('mysqldump', 'user', dump_user)
    parser.set('mysqldump', 'password', dump_password)
    parser.set('mysqldump', 'socket', cnf_parser.get(MYSQLD_SECTION, 'socket'))

    if override_dir:
        root_cnf_path = os.path.join(override_dir, os.path.basename(ROOT_CNF))
    else:
        root_cnf_path = ROOT_CNF
    log.info('Writing file {root_cnf_path}'
             ''.format(root_cnf_path=root_cnf_path))
    with open(root_cnf_path, "w") as root_cnf_handle:
        parser.write(root_cnf_handle) 
Example #27
Source Project: mysql_utils   Author: pinterest   File: host_utils.py    License: GNU General Public License v2.0 5 votes vote down vote up
def get_cnf_setting(variable, port):
    """ Get the value of a variab from a mysql cnf

    Args:
    variable - a MySQL variable located in configuration file
    port - Which instance of mysql, ie 3306.

    Returns:
    The value of the variable in the configuration file
    """
    if get_hiera_role() in MASTERFUL_PUPPET_ROLES:
        cnf = OLD_CONF_ROOT.format(port=str(port))
        group = 'mysqld'
    else:
        cnf = MYSQL_CNF_FILE
        group = 'mysqld{port}'.format(port=port)
    parser = ConfigParser.RawConfigParser(allow_no_value=True)
    if not os.path.exists(cnf):
        raise Exception("MySQL conf {cnf} does not exist".format(cnf=cnf))
    parser.read(cnf)

    try:
        value = parser.get(group, variable)
    except ConfigParser.NoOptionError:
        if '_' in variable:
            variable = variable.replace('_', '-')
            value = parser.get(group, variable)
        else:
            raise
    return value 
Example #28
Source Project: Faraday-Software   Author: FaradayRF   File: aprs.py    License: GNU General Public License v3.0 5 votes vote down vote up
def configureAPRS(args):
    '''
    Configure aprs configuration file from command line

    :param args: argparse arguments
    :return: None
    '''

    config = ConfigParser.RawConfigParser()
    config.read(os.path.join(faradayHelper.path, configFile))

    if args.callsign is not None:
        config.set('APRSIS', 'CALLSIGN', args.callsign)
    if args.server is not None:
        config.set('APRSIS', 'SERVER', args.server)
    if args.port is not None:
        config.set('APRSIS', 'PORT', args.port)
    if args.rate is not None:
        config.set('APRSIS', 'RATE', args.rate)
    if args.stationsage is not None:
        config.set('APRSIS', 'STATIONSAGE', args.stationsage)
    if args.comment is not None:
        config.set('APRS', 'COMMENT', args.comment[:43])
    if args.altcomment is not None:
        config.set('APRS', 'ALTCOMMENT', args.altcomment[:43])

    filename = os.path.join(faradayHelper.path, configFile)
    with open(filename, 'wb') as configfile:
        config.write(configfile) 
Example #29
Source Project: Faraday-Software   Author: FaradayRF   File: data.py    License: GNU General Public License v3.0 5 votes vote down vote up
def configureData(args, dataConfigPath):
    '''
    Configure Data configuration file from command line

    :param args: argparse arguments
    :param dataConfigPath: Path to data.ini file
    :return: None
    '''

    config = ConfigParser.RawConfigParser()
    config.read(os.path.join(path, "data.ini"))

    if args.flaskhost is not None:
        config.set('FLASK', 'HOST', args.flaskhost)
    if args.flaskport is not None:
        config.set('FLASK', 'PORT', args.flaskport)
    if args.proxyhost is not None:
        config.set('PROXY', 'HOST', args.proxyhost)
    if args.proxyport is not None:
        config.set('PROXY', 'PORT', args.proxyport)

    with open(dataConfigPath, 'wb') as configfile:
        config.write(configfile)


# Now act upon the command line arguments
# Initialize and configure Data 
Example #30
Source Project: Faraday-Software   Author: FaradayRF   File: deviceconfiguration.py    License: GNU General Public License v3.0 5 votes vote down vote up
def programFaraday(deviceConfigurationConfigPath):
    '''
    Programs Faraday by generating a HTTP POST query that Proxy uses to send data to the CC430 FLASH memory.

    :param deviceConfigurationConfigPath: Path to deviceconfiguration.ini file
    :return: None
    '''

    config = ConfigParser.RawConfigParser()
    config.read(deviceConfigPath)

    # Variables
    local_device_callsign = config.get("DEVICES", "CALLSIGN")
    local_device_node_id = config.get("DEVICES", "NODEID")
    local_device_callsign = str(local_device_callsign).upper()

    hostname = config.get("PROXY", "HOST")
    port = config.get("PROXY", "PORT")
    cmdPort = config.get("PROXY", "CMDPORT")

    # Send POST data to Proxy to configure unit
    try:
        r = requests.post('http://{0}:{1}'.format(hostname, port),
                          params={'callsign': str(local_device_callsign), 'nodeid': int(local_device_node_id), 'port': cmdPort})
        logger.info(r.url)
        logger.info("Sent Programming Request")

    except requests.exceptions.RequestException as e:
        # Some error occurred
        logger.error(e)
        logger.error(r.text)