Skip to content

Commit

Permalink
Merge branch 'develop' into feature/issue-12-array-is-a-complex-type
Browse files Browse the repository at this point in the history
  • Loading branch information
smn committed Feb 13, 2015
2 parents 239bba8 + 3fbb0a8 commit e35e781
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 7 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.3.5
0.3.7
24 changes: 18 additions & 6 deletions elasticgit/commands/resync.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ class ResyncTool(ToolCommand):
'-i', '--index-prefix',
dest='index_prefix',
help='The index prefix to use'),
CommandArgument(
'-u', '--es-host',
dest='es_host',
help='The elasticsearch url to use'),
CommandArgument(
'-p', '--git-path',
dest='git_path',
Expand All @@ -60,24 +64,27 @@ class ResyncTool(ToolCommand):

def run(self, config_file, model_class, index_prefix, git_path,
mapping_file=None, recreate_index=False,
section_name=DEFAULT_SECTION):
section_name=DEFAULT_SECTION, es_host=None):

mapping = (json.load(mapping_file)
if mapping_file is not None
else None)

# resync
if config_file is not None:
index_prefix, git_path = self.read_config_file(
index_prefix, git_path, es_host = self.read_config_file(
config_file, section_name)

es = {'urls': [es_host]} if es_host else {}

if not all([index_prefix, git_path]):
raise ToolCommandError(
'Please specify either `--config` or `--index-prefix` and '
'`--git-path`.')

return self.resync(git_path, index_prefix, model_class,
mapping=mapping, recreate_index=recreate_index)
mapping=mapping, recreate_index=recreate_index,
es=es)

def read_config_file(self, config_file, section_name):
# NOTE: ConfigParser's DEFAULT handling is kind of nuts
Expand All @@ -98,12 +105,17 @@ def read_config_file(self, config_file, section_name):

working_dir = config.get(section_name, 'git.path')
index_prefix = config.get(section_name, 'es.index_prefix')
return index_prefix, working_dir

es_host = None
if config.has_option(section_name, 'es.host'):
es_host = config.get(section_name, 'es.host')

return index_prefix, working_dir, es_host

def resync(self, working_dir, index_prefix, model_class,
mapping=None, recreate_index=False):
mapping=None, recreate_index=False, es={}):

workspace = EG.workspace(working_dir, index_prefix=index_prefix)
workspace = EG.workspace(working_dir, index_prefix=index_prefix, es=es)
branch = workspace.sm.repo.active_branch

if recreate_index and workspace.im.index_exists(branch.name):
Expand Down
36 changes: 36 additions & 0 deletions elasticgit/commands/tests/test_resync.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,3 +175,39 @@ def resync(self, workspace, models_module, mapping_file=None,
tool.run(sio, models_module, None, None, mapping_file=mapping_file,
recreate_index=recreate_index)
return tool.stdout.getvalue()


class TestResyncToolConfigFileWithEsHost(TestResyncTool):

def resync(self, workspace, models_module, mapping_file=None,
recreate_index=False):
parser = ConfigParser()
parser.add_section(DEFAULT_SECTION)
parser.set(DEFAULT_SECTION, 'git.path',
workspace.working_dir)
parser.set(DEFAULT_SECTION, 'es.index_prefix',
workspace.index_prefix)
parser.set(DEFAULT_SECTION, 'es.host', 'http://localhost:9200')
sio = StringIO()
parser.write(sio)
sio.seek(0)

tool = ResyncTool()
tool.stdout = StringIO()
tool.run(sio, models_module, None, None, mapping_file=mapping_file,
recreate_index=recreate_index)
return tool.stdout.getvalue()


class TestResyncToolWithEsHost(TestResyncTool):

def resync(self, workspace, model_class, mapping_file=None,
recreate_index=False):
tool = ResyncTool()
tool.stdout = StringIO()
tool.run(None, model_class,
workspace.index_prefix, workspace.working_dir,
mapping_file=mapping_file,
recreate_index=recreate_index,
es_host='http://localhost:9200')
return tool.stdout.getvalue()

0 comments on commit e35e781

Please sign in to comment.