Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def init():
"""Load the config file."""
global config
config_file = os.path.join(appdirs.site_config_dir('reviewbot'),
'config.py')
print('Loading config file %s' % config_file)
try:
with open(config_file) as f:
config_module = imp.load_module('config', f, config_file,
('py', 'r', imp.PY_SOURCE))
for key in list(config.keys()):
if hasattr(config_module, key):
value = getattr(config_module, key)
config[key] = value
except:
print('Unable to load config, using defaults')
def site_config_dir(self):
"""Return ``site_config_dir``."""
directory = appdirs.site_config_dir(self.appname, self.appauthor,
version=self.version, multipath=self.multipath)
if self.create:
self._ensure_directory_exists(directory)
return directory
def main():
parser = argparse.ArgumentParser(description="Blinktrade")
parser.add_argument('-c',
"--config",
action="store",
dest="config",
help='Configuration file', type=str)
arguments = parser.parse_args()
candidates = [ os.path.join(site_config_dir('blinktrade'), 'bitex.ini'),
os.path.expanduser('~/.blinktrade/bitex.ini'),
arguments.config ]
config = ConfigParser.SafeConfigParser()
config.read( candidates )
processes = []
for section_name in config.sections():
project_options = ProjectOptions(config, section_name)
if section_name[:5] == 'trade':
p = multiprocessing.Process(name=section_name, target=partial(trade_instance,section_name, project_options ) )
elif section_name[:10] == 'ws_gateway':
p = multiprocessing.Process(name=section_name, target=partial(ws_gateway_instance,section_name, project_options ) )
elif section_name[:6] == 'mailer':
p = multiprocessing.Process(name=section_name, target=partial(mailer_instance,section_name, project_options ) )
else:
# 7) environment variables
# 8) given on the command line
# These variables are settable to assist writing tests
if user_config_dir is None:
user_config_dir = appdirs.user_config_dir(appname="ct")
system_dirs = []
if system_config_dir is not None:
system_dirs.append(system_config_dir)
else:
for python_config_dir in sys.path[::-1]:
trialpath = os.path.join(python_config_dir, "etc/xdg/ct")
if ct.wrappedos.isdir(trialpath) and trialpath not in system_dirs:
system_dirs.append(trialpath)
system_dirs.append(appdirs.site_config_dir(appname="ct"))
if exedir is None:
exedir = ct.wrappedos.dirname(ct.wrappedos.realpath(sys.argv[0]))
executable_config_dir = os.path.join(exedir, "ct.conf.d")
gitroot = ct.git_utils.find_git_root()
results = ct.utils.OrderedSet(
[os.getcwd(), gitroot, os.path.join(gitroot, "ct.conf.d")]
)
if not repoonly:
results.append([user_config_dir] + system_dirs + [executable_config_dir])
if verbose >= 9:
print(" ".join(["Default config directories"] + list(results)))
return results
def get_config():
APP = "liteshort"
AUTHOR = "132ikl"
paths = [
Path("/etc/liteshort"),
Path(site_config_dir(APP, AUTHOR)),
Path(user_config_dir(APP, AUTHOR)),
Path(),
]
for path in paths:
f = path / "config.yml"
if f.exists():
LOGGER.info(f"Selecting config file {f}")
return open(f, "r")
for path in paths:
try:
path.mkdir(exist_ok=True)
template = resource_filename(__name__, "config.template.yml")
copyfile(template, (path / "config.template.yml"))
copyfile(template, (path / "config.yml"))
def main():
parser = argparse.ArgumentParser(description="Bitex Api Receive application")
parser.add_argument('-c', "--config",
action="store",
dest="config",
default=os.path.expanduser('~/.bitex/api_receive.ini'),
help='Configuration file', type=str)
arguments = parser.parse_args()
if not arguments.config:
parser.print_help()
return
candidates = [ os.path.join(site_config_dir('bitex'), 'api_receive.ini'),
arguments.config ]
config = configparser.SafeConfigParser()
config.read( candidates )
# Validate the whole file
for section_name in config.sections():
options = ProjectOptions(config, section_name)
if not options.log or \
not options.port or \
not options.rpc_url or \
not options.db_engine:
raise RuntimeError("Invalid configuration file")
# Start all applications
applications = []
for section_name in config.sections():
def get_config_path():
os.environ["XDG_CONFIG_DIRS"] = "/etc"
CONFIG_DIRS = (
appdirs.user_config_dir(_release_name),
appdirs.site_config_dir(_release_name),
)
CONFIG_FILENAME = "config.py"
for d in CONFIG_DIRS:
config_path = os.path.join(d, CONFIG_FILENAME)
if os.path.isfile(config_path):
return config_path
raise FileNotFoundError
dest="instance",
help='Instance name',
type=str)
parser.add_argument('-c', "--config",
action="store",
dest="config",
default=os.path.expanduser('~/.blinktrade/bitex.ini'),
help='Configuration file', type=str)
arguments = parser.parse_args()
if not arguments.instance:
parser.print_help()
return
candidates = [ os.path.join(site_config_dir('blinktrade'), 'bitex.ini'),
os.path.expanduser('~/.blinktrade/bitex.ini'),
arguments.config]
config = ConfigParser.SafeConfigParser()
config.read( candidates )
options = ProjectOptions(config, arguments.instance)
if not options.trade_in or \
not options.trade_pub or \
not options.trade_log or \
not options.global_email_language or \
not options.sqlalchemy_connection_string or \
not options.sqlalchemy_engine:
raise RuntimeError("Invalid configuration file")
application = TradeApplication.instance()