Skip to content

Commit

Permalink
- Moved cli & gui modules inside dexbot package
Browse files Browse the repository at this point in the history
- created separate console entrypoints for cli & gui dexbot versions: dexbot-cli & dexbot-gui
- Create default config.yml file initially at the user's default config directory and load it from here everywhere.
- Fix for #57 : config.yml is created automatically in case it does not exist
  • Loading branch information
svdev committed Apr 12, 2018
1 parent c3f8899 commit 871137e
Show file tree
Hide file tree
Showing 10 changed files with 51 additions and 31 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ install:
- make install
script:
- echo "@TODO - Running tests..."
- pyinstaller --distpath dist/$TRAVIS_OS_NAME app.spec
- pyinstaller --distpath dist/$TRAVIS_OS_NAME gui.spec
- pyinstaller --distpath dist/$TRAVIS_OS_NAME cli.spec
before_deploy:
- git config --local user.name "Travis"
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ check: pip
python3 setup.py check

package: build
pyinstaller app.spec
pyinstaller gui.spec
pyinstaller cli.spec

dist: build
Expand Down
5 changes: 0 additions & 5 deletions cli.py

This file was deleted.

2 changes: 1 addition & 1 deletion cli.spec
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ hiddenimports_packaging = [
'packaging', 'packaging.version', 'packaging.specifiers', 'packaging.requirements'
]

a = Analysis(['cli.py'],
a = Analysis(['dexbot/cli.py'],
binaries=[],
datas=[],
hiddenimports=hiddenimports_packaging + hiddenimports_strategies,
Expand Down
25 changes: 24 additions & 1 deletion dexbot/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,24 @@
__version__ = '0.1.12'
import pathlib
import os
from appdirs import user_config_dir

APP_NAME = "dexbot"
VERSION = '0.1.12'
AUTHOR = "codaone"
__version__ = VERSION


config_dir = user_config_dir(APP_NAME, appauthor=AUTHOR)
config_file = config_dir + "/config.yml"

default_config = """
node: wss://bitshares.openledger.info/ws
workers: {}
"""

if not os.path.isfile(config_file):
pathlib.Path(config_dir).mkdir(parents=True, exist_ok=True)
with open(config_file, 'w') as f:
f.write(default_config)
print("Created default config file at {}".format(config_file))

5 changes: 3 additions & 2 deletions dexbot/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
import signal
import sys

from .ui import (
from dexbot import config_file
from dexbot.ui import (
verbose,
chain,
unlock,
Expand All @@ -26,7 +27,7 @@
@click.group()
@click.option(
"--configfile",
default="config.yml",
default=config_file,
)
@click.option(
'--verbose',
Expand Down
19 changes: 10 additions & 9 deletions dexbot/controllers/main_controller.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import logging

from dexbot import config_file
from dexbot.worker import WorkerInfrastructure

from ruamel.yaml import YAML
Expand Down Expand Up @@ -53,15 +54,15 @@ def remove_worker(self, worker_name):
@staticmethod
def load_config():
yaml = YAML()
with open('config.yml', 'r') as f:
with open(config_file, 'r') as f:
return yaml.load(f)

@staticmethod
def get_workers_data():
"""
Returns dict of all the workers data
"""
with open('config.yml', 'r') as f:
with open(config_file, 'r') as f:
yaml = YAML()
return yaml.load(f)['workers']

Expand All @@ -70,7 +71,7 @@ def get_worker_config(worker_name):
"""
Returns config file data with only the data from a specific worker
"""
with open('config.yml', 'r') as f:
with open(config_file, 'r') as f:
yaml = YAML()
config = yaml.load(f)
config['workers'] = {worker_name: config['workers'][worker_name]}
Expand All @@ -79,29 +80,29 @@ def get_worker_config(worker_name):
@staticmethod
def remove_worker_config(worker_name):
yaml = YAML()
with open('config.yml', 'r') as f:
with open(config_file, 'r') as f:
config = yaml.load(f)

config['workers'].pop(worker_name, None)

with open("config.yml", "w") as f:
with open(config_file, "w") as f:
yaml.dump(config, f)

@staticmethod
def add_worker_config(worker_name, worker_data):
yaml = YAML()
with open('config.yml', 'r') as f:
with open(config_file, 'r') as f:
config = yaml.load(f)

config['workers'][worker_name] = worker_data

with open("config.yml", "w") as f:
with open(config_file, "w") as f:
yaml.dump(config, f)

@staticmethod
def replace_worker_config(worker_name, new_worker_name, worker_data):
yaml = YAML()
with open('config.yml', 'r') as f:
with open(config_file, 'r') as f:
config = yaml.load(f)

workers = config['workers']
Expand All @@ -113,5 +114,5 @@ def replace_worker_config(worker_name, new_worker_name, worker_data):
else:
workers[key] = value

with open("config.yml", "w") as f:
with open(config_file, "w") as f:
yaml.dump(config, f)
6 changes: 5 additions & 1 deletion app.py → dexbot/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ def __init__(self, sys_argv):
sys.exit()


if __name__ == '__main__':
def main():
app = App(sys.argv)
sys.exit(app.exec_())


if __name__ == '__main__':
main()
2 changes: 1 addition & 1 deletion app.spec → gui.spec
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ hiddenimports_packaging = [
'packaging', 'packaging.version', 'packaging.specifiers', 'packaging.requirements'
]

a = Analysis(['app.py'],
a = Analysis(['dexbot/gui.py'],
binaries=[],
datas=[],
hiddenimports=hiddenimports_packaging + hiddenimports_strategies,
Expand Down
14 changes: 5 additions & 9 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
#!/usr/bin/env python
#!/usr/bin/env python3

from setuptools import setup, find_packages
from distutils.command import build as build_module
from distutils.util import convert_path
from pyqt_distutils.build_ui import build_ui

main_ns = {}
ver_path = convert_path('dexbot/__init__.py')
with open(ver_path) as ver_file:
exec(ver_file.read(), main_ns)
VERSION = main_ns['__version__']
from dexbot import VERSION, APP_NAME


class BuildCommand(build_module.build):
Expand All @@ -19,7 +14,7 @@ def run(self):


setup(
name='dexbot',
name=APP_NAME,
version=VERSION,
description='Trading bot for the DEX (BitShares)',
long_description=open('README.md').read(),
Expand All @@ -43,7 +38,8 @@ def run(self):
},
entry_points={
'console_scripts': [
'dexbot = dexbot.cli:main',
'dexbot-cli = dexbot.cli:main',
'dexbot-gui = dexbot.gui:main',
],
},
install_requires=[
Expand Down

0 comments on commit 871137e

Please sign in to comment.