Skip to content

Commit

Permalink
bug fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
EricWang committed Apr 6, 2017
1 parent 09df03f commit 8315e25
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
14 changes: 7 additions & 7 deletions rqalpha/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import ruamel.yaml as yaml

from .utils.click_helper import Date
from .utils.config import parse_config, get_mod_config_path, load_config, dump_config
from .utils.config import parse_config, get_mod_config_path, dump_config, load_mod_config


@click.group()
Expand All @@ -38,7 +38,7 @@ def entry_point():
from rqalpha.mod import SYSTEM_MOD_LIST
from rqalpha.utils.package_helper import import_mod
mod_config_path = get_mod_config_path()
mod_config = load_config(mod_config_path, loader=yaml.RoundTripLoader)
mod_config = load_mod_config(mod_config_path, loader=yaml.RoundTripLoader)

for mod_name, config in six.iteritems(mod_config['mod']):
lib_name = "rqalpha_mod_{}".format(mod_name)
Expand Down Expand Up @@ -183,7 +183,7 @@ def list(params):
from tabulate import tabulate
init()
mod_config_path = get_mod_config_path(generate=True)
mod_config = load_config(mod_config_path, loader=yaml.RoundTripLoader)
mod_config = load_mod_config(mod_config_path, loader=yaml.RoundTripLoader)

table = []

Expand Down Expand Up @@ -231,7 +231,7 @@ def install(params):

# Export config
mod_config_path = get_mod_config_path(generate=True)
mod_config = load_config(mod_config_path, loader=yaml.RoundTripLoader)
mod_config = load_mod_config(mod_config_path, loader=yaml.RoundTripLoader)

for mod_name in mod_list:
mod_config['mod'][mod_name] = {}
Expand Down Expand Up @@ -270,7 +270,7 @@ def uninstall(params):

# Remove Mod Config
mod_config_path = get_mod_config_path(generate=True)
mod_config = load_config(mod_config_path, loader=yaml.RoundTripLoader)
mod_config = load_mod_config(mod_config_path, loader=yaml.RoundTripLoader)

for mod_name in mod_list:
if "rqalpha_mod_" in mod_name:
Expand All @@ -297,7 +297,7 @@ def enable(params):
install([module_name])

mod_config_path = get_mod_config_path(generate=True)
mod_config = load_config(mod_config_path, loader=yaml.RoundTripLoader)
mod_config = load_mod_config(mod_config_path, loader=yaml.RoundTripLoader)

mod_config['mod'][mod_name]['enabled'] = True
dump_config(mod_config_path, mod_config)
Expand All @@ -313,7 +313,7 @@ def disable(params):
mod_name = mod_name.replace("rqalpha_mod_", "")

mod_config_path = get_mod_config_path(generate=True)
mod_config = load_config(mod_config_path, loader=yaml.RoundTripLoader)
mod_config = load_mod_config(mod_config_path, loader=yaml.RoundTripLoader)

mod_config['mod'][mod_name]['enabled'] = False
dump_config(mod_config_path, mod_config)
Expand Down
11 changes: 11 additions & 0 deletions rqalpha/utils/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,17 @@ def dump_config(config_path, config, dumper=yaml.RoundTripDumper):
stream.write(to_utf8(yaml.dump(config, Dumper=dumper)))


def load_mod_config(config_path, loader=yaml.Loader):
mod_config = load_config(config_path, loader)
if mod_config is None or "mod" not in mod_config:
import os
os.remove(config_path)
config_path = get_mod_config_path()
return load_mod_config(config_path, loader)
else:
return mod_config


def get_mod_config_path(generate=False):
mod_config_path = os.path.abspath(os.path.expanduser("~/.rqalpha/mod_config.yml"))
mod_template_path = os.path.abspath(os.path.join(os.path.dirname(os.path.realpath(__file__)), "../mod_config_template.yml"))
Expand Down

0 comments on commit 8315e25

Please sign in to comment.