From 0af569acff92768d4228540c2e14e7ec04fd22e8 Mon Sep 17 00:00:00 2001 From: Arinerron Date: Fri, 4 May 2018 00:14:27 -0700 Subject: [PATCH] Move config to static-data --- onionr/onionr.py | 11 +++++++---- onionr/static-data/default_config.json | 16 ++++++++++++++++ .../{default_plugin.txt => default_plugin.py} | 0 3 files changed, 23 insertions(+), 4 deletions(-) create mode 100644 onionr/static-data/default_config.json rename onionr/static-data/{default_plugin.txt => default_plugin.py} (100%) diff --git a/onionr/onionr.py b/onionr/onionr.py index 9a5619c8..213d5d6e 100755 --- a/onionr/onionr.py +++ b/onionr/onionr.py @@ -59,8 +59,11 @@ class Onionr: if not data_exists: os.mkdir('data/') - exists = os.path.exists(config.get_config_file()) - config.set_config({'devmode': True, 'log': {'file': {'output': True, 'path': 'data/output.log'}, 'console': {'output': True, 'color': True}}}) # this is the default config, it will be overwritten if a config file already exists. Else, it saves it + if os.path.exists('static-data/default_config.json'): + config.set_config(json.loads(open('static-data/default_config.json').read())) # this is the default config, it will be overwritten if a config file already exists. Else, it saves it + else: + # the default config file doesn't exist, try hardcoded config + config.set_config({'devmode': True, 'log': {'file': {'output': True, 'path': 'data/output.log'}, 'console': {'output': True, 'color': True}}}) if not exists: config.save() config.reload() # this will read the configuration file into memory @@ -454,7 +457,7 @@ class Onionr: os.makedirs(plugins.get_plugins_folder(plugin_name)) with open(plugins.get_plugins_folder(plugin_name) + '/main.py', 'a') as main: - main.write(open('static-data/default_plugin.txt').read().replace('$user', os.getlogin()).replace('$date', datetime.datetime.now().strftime('%Y-%m-%d'))) + main.write(open('static-data/default_plugin.py').read().replace('$user', os.getlogin()).replace('$date', datetime.datetime.now().strftime('%Y-%m-%d'))) logger.info('Enabling plugin "%s"...' % plugin_name) plugins.enable(plugin_name, self) @@ -546,7 +549,7 @@ class Onionr: ''' Displays statistics and exits ''' - + logger.info('Our pubkey: ' + self.onionrCore._crypto.pubKey) logger.info('Our address: ' + self.get_hostname()) return diff --git a/onionr/static-data/default_config.json b/onionr/static-data/default_config.json new file mode 100644 index 00000000..020107ce --- /dev/null +++ b/onionr/static-data/default_config.json @@ -0,0 +1,16 @@ +{ + "devmode": true, + "dc_response": true, + + "log": { + "file": { + "output": true, + "path": "data/output.log" + }, + + "console": { + "output": true, + "color": true + } + } +} diff --git a/onionr/static-data/default_plugin.txt b/onionr/static-data/default_plugin.py similarity index 100% rename from onionr/static-data/default_plugin.txt rename to onionr/static-data/default_plugin.py