Python ConfigParser.ConfigParser() Examples
The following are 30
code examples of ConfigParser.ConfigParser().
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 File: test_smb.py From CVE-2017-7494 with GNU General Public License v3.0 | 7 votes |
def setUp(self): SMBTests.setUp(self) # Put specific configuration for target machine with SMB1 configFile = ConfigParser.ConfigParser() configFile.read('dcetests.cfg') self.username = configFile.get('SMBTransport', 'username') self.domain = configFile.get('SMBTransport', 'domain') self.serverName = configFile.get('SMBTransport', 'servername') self.password = configFile.get('SMBTransport', 'password') self.machine = configFile.get('SMBTransport', 'machine') self.hashes = configFile.get('SMBTransport', 'hashes') self.aesKey = configFile.get('SMBTransport', 'aesKey128') self.share = 'C$' self.file = '/TEST' self.directory= '/BETO' self.upload = '../../nt_errors.py' self.flags2 = smb.SMB.FLAGS2_NT_STATUS | smb.SMB.FLAGS2_EXTENDED_SECURITY | smb.SMB.FLAGS2_LONG_NAMES self.dialects = smb.SMB_DIALECT
Example #2
Source File: project.py From apio with GNU General Public License v2.0 | 6 votes |
def _read_board(self): board = '' # -- Read config file: old JSON format with open(PROJECT_FILENAME, 'r') as f: try: data = json.loads(f.read()) board = data.get('board') except Exception: pass # -- Read config file: new CFG format if board == '': try: config = ConfigParser.ConfigParser() config.read(PROJECT_FILENAME) board = config.get('env', 'board') except Exception: print('Error: invalid {} project file'.format( PROJECT_FILENAME)) sys.exit(1) return board
Example #3
Source File: config.py From CAMISIM with Apache License 2.0 | 6 votes |
def __init__(self, openedConfigFile, section, defaultDict=None): """ @param openedConfigFile: @param section: @param defaultDict: if mapping not present in the config file, this mapping is used @return: """ self._config = ConfigParser.ConfigParser() self._config.readfp(openedConfigFile) self._section = section self._configFilePath = openedConfigFile.name if defaultDict is not None: self._defaultDict = defaultDict else: self._defaultDict = dict()
Example #4
Source File: test_smb.py From CVE-2017-7494 with GNU General Public License v3.0 | 6 votes |
def setUp(self): SMBTests.setUp(self) # Put specific configuration for target machine with SMB1 configFile = ConfigParser.ConfigParser() configFile.read('dcetests.cfg') self.username = configFile.get('SMBTransport', 'username') self.domain = configFile.get('SMBTransport', 'domain') self.serverName = configFile.get('SMBTransport', 'servername') self.password = configFile.get('SMBTransport', 'password') self.machine = configFile.get('SMBTransport', 'machine') self.hashes = configFile.get('SMBTransport', 'hashes') self.aesKey = configFile.get('SMBTransport', 'aesKey128') self.share = 'C$' self.file = '/TEST' self.directory= '/BETO' self.upload = '../../nt_errors.py' self.flags2 = smb.SMB.FLAGS2_UNICODE | smb.SMB.FLAGS2_NT_STATUS | smb.SMB.FLAGS2_EXTENDED_SECURITY | smb.SMB.FLAGS2_LONG_NAMES self.dialects = smb.SMB_DIALECT
Example #5
Source File: plugin_loader.py From vt-ida-plugin with Apache License 2.0 | 6 votes |
def write_config(self): """Write user's configuration file.""" logging.debug('[VT Plugin] Writing user config file: %s', self.vt_cfgfile) try: parser = configparser.ConfigParser() config_file = open(self.vt_cfgfile, 'w') parser.add_section('General') parser.set('General', 'auto_upload', str(self.auto_upload)) parser.write(config_file) config_file.close() except: logging.error('[VT Plugin] Error while creating the user config file.') return False return True
Example #6
Source File: test_smb.py From CVE-2017-7494 with GNU General Public License v3.0 | 6 votes |
def setUp(self): # Put specific configuration for target machine with SMB_002 SMBTests.setUp(self) configFile = ConfigParser.ConfigParser() configFile.read('dcetests.cfg') self.username = configFile.get('SMBTransport', 'username') self.domain = configFile.get('SMBTransport', 'domain') self.serverName = configFile.get('SMBTransport', 'servername') self.password = configFile.get('SMBTransport', 'password') self.machine = configFile.get('SMBTransport', 'machine') self.hashes = configFile.get('SMBTransport', 'hashes') self.aesKey = configFile.get('SMBTransport', 'aesKey128') self.share = 'C$' self.file = '/TEST' self.directory= '/BETO' self.upload = '../../nt_errors.py' self.dialects = SMB2_DIALECT_002
Example #7
Source File: test_smb.py From CVE-2017-7494 with GNU General Public License v3.0 | 6 votes |
def setUp(self): # Put specific configuration for target machine with SMB 2.1 SMBTests.setUp(self) configFile = ConfigParser.ConfigParser() configFile.read('dcetests.cfg') self.username = configFile.get('SMBTransport', 'username') self.domain = configFile.get('SMBTransport', 'domain') self.serverName = configFile.get('SMBTransport', 'servername') self.password = configFile.get('SMBTransport', 'password') self.machine = configFile.get('SMBTransport', 'machine') self.hashes = configFile.get('SMBTransport', 'hashes') self.aesKey = configFile.get('SMBTransport', 'aesKey128') self.share = 'C$' self.file = '/TEST' self.directory= '/BETO' self.upload = '../../nt_errors.py' self.dialects = SMB2_DIALECT_21
Example #8
Source File: optionparser.py From securityheaders with Apache License 2.0 | 6 votes |
def parse(self, filepath=None): result = dict() result['errors'] = list() if filepath: appconf = filepath else: appconf =None if appconf: try: appconfig = ConfigParser.ConfigParser() appconfig.readfp(open(appconf)) self.__add_checks__(appconfig, result) self.__read_config__(appconfig, result) except Exception: raise Exception('Cannot read config file ' + str(appconf)) self.options = result return self
Example #9
Source File: firefox_decrypt.py From firefox_decrypt with GNU General Public License v3.0 | 6 votes |
def read_profiles(basepath, list_profiles): """ Parse Firefox profiles in provided location. If list_profiles is true, will exit after listing available profiles. """ profileini = os.path.join(basepath, "profiles.ini") LOG.debug("Reading profiles from %s", profileini) if not os.path.isfile(profileini): LOG.warning("profile.ini not found in %s", basepath) raise Exit(Exit.MISSING_PROFILEINI) # Read profiles from Firefox profile folder profiles = ConfigParser() profiles.read(profileini) LOG.debug("Read profiles %s", profiles.sections()) if list_profiles: LOG.debug("Listing available profiles...") print_sections(get_sections(profiles), sys.stdout) raise Exit(0) return profiles
Example #10
Source File: ConfigEmailLookup.py From llvm-zorg with Apache License 2.0 | 6 votes |
def __init__(self, author_filename, default_address, only_addresses = None, update_interval=timedelta(hours=1)): from ConfigParser import ConfigParser self.author_filename = author_filename self.default_address = default_address self.only_addresses = only_addresses self.update_interval = update_interval self.config_parser = ConfigParser() self.config_parser.read(self.author_filename) self.time_checked = datetime.utcnow() self.time_loaded = datetime.utcfromtimestamp(os.path.getmtime(self.author_filename)) if only_addresses: import re self.address_match_p = re.compile(only_addresses).match else: self.address_match_p = lambda addr: True
Example #11
Source File: SaveData.py From Pansidong with GNU General Public License v3.0 | 6 votes |
def __init__(self, results_queue, thread_pool, use_file=True, use_database=True, filename="proxy-ip-list.csv"): self.use_file = use_file self.use_database = use_database self.filename = filename self.results_queue = results_queue self.thread_pool = thread_pool if use_database: try: cf = ConfigParser.ConfigParser() cf.read("config.ini") db_name = cf.get("Pansidong", "database") username = cf.get(db_name, "username") password = cf.get(db_name, "password") host = cf.get(db_name, "host") database = cf.get(db_name, "database") except AttributeError, e: logger.fatal(e.message) sys.exit(1) self.engine = create_engine("mysql://" + username + ":" + password + "@" + host + "/" + database + "?charset=utf8") self.db_session = sessionmaker(bind=self.engine) self.session = self.db_session()
Example #12
Source File: test_wmi.py From CVE-2017-7494 with GNU General Public License v3.0 | 6 votes |
def setUp(self): WMITests.setUp(self) configFile = ConfigParser.ConfigParser() configFile.read('dcetests.cfg') self.username = configFile.get('TCPTransport', 'username') self.domain = configFile.get('TCPTransport', 'domain') self.serverName = configFile.get('TCPTransport', 'servername') self.password = configFile.get('TCPTransport', 'password') self.machine = configFile.get('TCPTransport', 'machine') self.hashes = configFile.get('TCPTransport', 'hashes') self.stringBinding = r'ncacn_ip_tcp:%s' % self.machine self.ts = ('8a885d04-1ceb-11c9-9fe8-08002b104860', '2.0') if len(self.hashes) > 0: self.lmhash, self.nthash = self.hashes.split(':') else: self.lmhash = '' self.nthash = ''
Example #13
Source File: pipeline.py From EvalNE with MIT License | 6 votes |
def __init__(self, configpath): # Import config parser try: from ConfigParser import ConfigParser except ImportError: from configparser import ConfigParser # Read the configuration file config = ConfigParser() config.read(configpath) self._config = config self._check_inpaths() self._check_methods('opne') self._check_methods('other') self._checkparams() self._check_edges() self._check_task()
Example #14
Source File: metrics.py From openSUSE-release-tools with GNU General Public License v2.0 | 6 votes |
def dashboard_at(api, filename, datetime=None, revision=None): if datetime: revision = revision_at(api, datetime) if not revision: return revision content = api.pseudometa_file_load(filename, revision) if filename in ('ignored_requests'): if content: return yaml.safe_load(content) return {} elif filename in ('config'): if content: # TODO re-use from osclib.conf. from ConfigParser import ConfigParser import io cp = ConfigParser() config = '[remote]\n' + content cp.readfp(io.BytesIO(config)) return dict(cp.items('remote')) return {} return content
Example #15
Source File: config.py From rucio with Apache License 2.0 | 6 votes |
def config_get(section, option, raise_exception=True, default=None): """ Return the string value for a given option in a section :param section: the named section. :param option: the named option. :param raise_exception: Boolean to raise or not NoOptionError or NoSectionError. :param default: the default value if not found. . :returns: the configuration value. """ try: return get_config().get(section, option) except (ConfigParser.NoOptionError, ConfigParser.NoSectionError) as err: if raise_exception and default is None: raise err return default
Example #16
Source File: test_server.py From maintainer-quality-tools with GNU Affero General Public License v3.0 | 6 votes |
def create_server_conf(data, version): """Create (or edit) default configuration file of odoo :params data: Dict with all info to save in file""" fname_conf = os.path.expanduser('~/.openerp_serverrc') if not os.path.exists(fname_conf): # If not exists the file then is created fconf = open(fname_conf, "w") fconf.close() config = ConfigParser.ConfigParser() config.read(fname_conf) if not config.has_section('options'): config.add_section('options') for key, value in data.items(): config.set('options', key, value) with open(fname_conf, 'w') as configfile: config.write(configfile)
Example #17
Source File: hook.py From linter-pylama with MIT License | 6 votes |
def install_hg(path): """ Install hook in Mercurial repository. """ hook = op.join(path, 'hgrc') if not op.isfile(hook): open(hook, 'w+').close() c = ConfigParser() c.readfp(open(hook, 'r')) if not c.has_section('hooks'): c.add_section('hooks') if not c.has_option('hooks', 'commit'): c.set('hooks', 'commit', 'python:pylama.hooks.hg_hook') if not c.has_option('hooks', 'qrefresh'): c.set('hooks', 'qrefresh', 'python:pylama.hooks.hg_hook') c.write(open(hook, 'w+'))
Example #18
Source File: config.py From rucio with Apache License 2.0 | 6 votes |
def __init__(self): if sys.version_info < (3, 2): self.parser = ConfigParser.SafeConfigParser(os.environ) else: self.parser = ConfigParser.ConfigParser(defaults=os.environ) if 'RUCIO_CONFIG' in os.environ: self.configfile = os.environ['RUCIO_CONFIG'] else: configs = [os.path.join(confdir, 'rucio.cfg') for confdir in get_config_dirs()] self.configfile = next(iter(filter(os.path.exists, configs)), None) if self.configfile is None: raise RuntimeError('Could not load Rucio configuration file. ' 'Rucio looked in the following paths for a configuration file, in order:' '\n\t' + '\n\t'.join(configs)) if not self.parser.read(self.configfile) == [self.configfile]: raise RuntimeError('Could not load Rucio configuration file. ' 'Rucio tried loading the following configuration file:' '\n\t' + self.configfile)
Example #19
Source File: generateconfig.py From nukemyluks with Apache License 2.0 | 6 votes |
def main(): if len(sys.argv) < 2: usage() hashed_password = hashpw(sys.argv[1], gensalt(log_rounds=DEFAULT_ROUNDS)) configparser = ConfigParser.ConfigParser() configparser.add_section('config') configparser.set('config', 'password_hash', hashed_password) try: config_file = open('config.ini', 'w') configparser.write(config_file) except Exception as err: print "[!] Error creating config file: %s" % err sys.exit() print "[+] Configuration file created successfully." config_file.close()
Example #20
Source File: config.py From rucio with Apache License 2.0 | 5 votes |
def config_get_float(section, option, raise_exception=True, default=None): """Return the floating point value for a given option in a section""" try: return get_config().getfloat(section, option) except (ConfigParser.NoOptionError, ConfigParser.NoSectionError) as err: if raise_exception and default is None: raise err return default
Example #21
Source File: test_auditor_srmdumps.py From rucio with Apache License 2.0 | 5 votes |
def test_with_configuration_file(): """ test_generate_url_returns_custom_url_for_sites_with_configuration_file""" config = ConfigParser() config.add_section('SITE') config.set('SITE', 'SITE_DATADISK', 'http://example.com/pattern-%%Y-%%m-%%d/dumps') base_url, pattern = srmdumps.generate_url('SITE_DATADISK', config) eq_(base_url, 'http://example.com') eq_(pattern, 'pattern-%Y-%m-%d/dumps')
Example #22
Source File: config.py From rucio with Apache License 2.0 | 5 votes |
def config_get_int(section, option, raise_exception=True, default=None): """Return the integer value for a given option in a section""" try: return get_config().getint(section, option) except (ConfigParser.NoOptionError, ConfigParser.NoSectionError) as err: if raise_exception and default is None: raise err return default
Example #23
Source File: test_wkst.py From CVE-2017-7494 with GNU General Public License v3.0 | 5 votes |
def setUp(self): WKSTTests.setUp(self) configFile = ConfigParser.ConfigParser() configFile.read('dcetests.cfg') self.username = configFile.get('SMBTransport', 'username') self.domain = configFile.get('SMBTransport', 'domain') self.serverName = configFile.get('SMBTransport', 'servername') self.password = configFile.get('SMBTransport', 'password') self.machine = configFile.get('SMBTransport', 'machine') self.hashes = configFile.get('SMBTransport', 'hashes') self.stringBinding = r'ncacn_np:%s[\PIPE\wkssvc]' % self.machine self.ts = ('8a885d04-1ceb-11c9-9fe8-08002b104860', '2.0')
Example #24
Source File: test_nmb.py From CVE-2017-7494 with GNU General Public License v3.0 | 5 votes |
def setUp(self): NMBTests.setUp(self) # Put specific configuration for target machine with SMB1 configFile = ConfigParser.ConfigParser() configFile.read('dcetests.cfg') self.serverName = configFile.get('SMBTransport', 'servername') self.machine = configFile.get('SMBTransport', 'machine')
Example #25
Source File: psm.py From psm with MIT License | 5 votes |
def show(): conf = configparser.ConfigParser() path = os.path.expanduser("~/.pip/pip.conf") conf.read(path) index_url = conf.get("global", "index-url") for key in sources: if index_url == sources[key]: print("\nCurrent source is %s\n"%key) break else: print("\nUnknown source\n")
Example #26
Source File: plugin_base.py From jbox with MIT License | 5 votes |
def read_config(): global file_config file_config = configparser.ConfigParser() file_config.read(['setup.cfg', 'test.cfg'])
Example #27
Source File: pasterapp.py From jbox with MIT License | 5 votes |
def _has_logging_config(paste_file): cfg_parser = ConfigParser.ConfigParser() cfg_parser.read([paste_file]) return cfg_parser.has_section('loggers')
Example #28
Source File: pasterapp.py From jbox with MIT License | 5 votes |
def load_config(self): super(PasterBaseApplication, self).load_config() # reload logging conf if hasattr(self, "cfgfname"): parser = ConfigParser.ConfigParser() parser.read([self.cfgfname]) if parser.has_section('loggers'): from logging.config import fileConfig config_file = os.path.abspath(self.cfgfname) fileConfig(config_file, dict(__file__=config_file, here=os.path.dirname(config_file)))
Example #29
Source File: test_wkst.py From CVE-2017-7494 with GNU General Public License v3.0 | 5 votes |
def setUp(self): WKSTTests.setUp(self) configFile = ConfigParser.ConfigParser() configFile.read('dcetests.cfg') self.username = configFile.get('SMBTransport', 'username') self.domain = configFile.get('SMBTransport', 'domain') self.serverName = configFile.get('SMBTransport', 'servername') self.password = configFile.get('SMBTransport', 'password') self.machine = configFile.get('SMBTransport', 'machine') self.hashes = configFile.get('SMBTransport', 'hashes') self.stringBinding = r'ncacn_np:%s[\PIPE\wkssvc]' % self.machine self.ts = ('71710533-BEBA-4937-8319-B5DBEF9CCC36', '1.0') # Process command-line arguments.
Example #30
Source File: test_auditor_srmdumps.py From rucio with Apache License 2.0 | 5 votes |
def test_sites_no_configuration_file(mock_ddmendpoint): """ test_generate_url_returns_standard_url_for_sites_with_no_configuration_file""" config = ConfigParser() mock_ddmendpoint.return_value = 'srm://example.com/atlasdatadisk/' base_url, pattern = srmdumps.generate_url('SITE_DATADISK', config) eq_(base_url, 'srm://example.com/atlasdatadisk/dumps') eq_(pattern, 'dump_%Y%m%d')