Skip to content

Commit

Permalink
Refactoring echomesh.base.
Browse files Browse the repository at this point in the history
  • Loading branch information
rec committed Jan 3, 2015
1 parent 0fe41bc commit 10103c7
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 39 deletions.
2 changes: 1 addition & 1 deletion code/python/echomesh/Main.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def p(msg=''):
from echomesh.base import Settings
p()

Settings.reconfigure(sys.argv[1:])
Settings.read_settings(sys.argv[1:])
p()

if Settings.get('execution', 'autostart') and not Settings.get(
Expand Down
32 changes: 0 additions & 32 deletions code/python/echomesh/base/Reconfigure.py

This file was deleted.

40 changes: 34 additions & 6 deletions code/python/echomesh/base/Settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,47 @@
except:
from weakrefset import WeakSet

from echomesh.base import DataFile
from echomesh.base import Join
from echomesh.base import Reconfigure
from echomesh.base import MergeSettings
from echomesh.base import Name
from echomesh.base import Path

_MERGE_SETTINGS = None
_CLIENTS = WeakSet()
_NONE = object()
_ARGS = []

def reconfigure(args=None):
global _ARGS, MERGE_SETTINGS
if args:
def read_settings(args=None):
global _ARGS
if args is not None:
_ARGS = args
MERGE_SETTINGS = Reconfigure.reconfigure(_ARGS)

def _make(name, tags, project, show_error):
Name.set_name(name)
Name.set_tags(tags)
Path.set_project_path(project_path=project, show_error=show_error)

DataFile.compute_command_path(force=True)
return MergeSettings.MergeSettings(args)

# Read a settings file with a given name, tags, and project.
# First, make a settings with the default information.
merge_settings = _make(None, [], None, False)

# Now, use the name, tags and project to get the correct configuration.
get = merge_settings.settings.get

name = get('name') or Name.lookup(get('map', {}).get('name', {}))
tags = get('tag') or Name.lookup(get('map', {}).get('tag', {})) or []
project = get('project')

if not isinstance(tags, (list, tuple)):
tags = [tags]

prompt = not get('execution', 'autostart')
global MERGE_SETTINGS
MERGE_SETTINGS = _make(name, tags, project, prompt)

def add_client(client):
if not client in _CLIENTS:
Expand All @@ -31,7 +59,7 @@ def update_clients():

def get_settings():
if not MERGE_SETTINGS:
reconfigure()
read_settings()
return MERGE_SETTINGS.settings

def get(*parts):
Expand Down

0 comments on commit 10103c7

Please sign in to comment.