Skip to content

Commit

Permalink
working on the update process
Browse files Browse the repository at this point in the history
  • Loading branch information
toumorokoshi committed Feb 15, 2015
1 parent 35ecf76 commit 7cf6f23
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 18 deletions.
8 changes: 7 additions & 1 deletion uranium/buildout_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
from .compat import DictMixin
import zc.buildout
import logging
import os

LOGGER = logging.getLogger(__name__)

Expand All @@ -40,6 +39,13 @@ def install_part(part):
except zc.buildout.UserError as e:
LOGGER.error(str(e))

@staticmethod
def update_part(part):
try:
part.update()
except zc.buildout.UserError as e:
LOGGER.error(str(e))

def _get_recipe_class(self, recipe_name):
return self._classloader.get_entry_point(recipe_name, "zc.buildout")

Expand Down
2 changes: 1 addition & 1 deletion uranium/plugin_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def install_part(isotope):

@staticmethod
def update_part(isotope):
pass
isotope.update()

@staticmethod
def remove_part(isotope):
Expand Down
18 changes: 12 additions & 6 deletions uranium/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,26 @@ class State(object):
A class to abstract the storage and retrieval of state information,
which affect the behaviour of subsequent uranium runs.
"""
def __init__(self, state_file_path):
def __init__(self, state_file_path=None):
self._state_file_path = state_file_path
self._state = {
PART_STATE_KEY: {}
}

def store(self):
with open(self._state_file_path, 'w+') as fh:
fh.write(yaml.dump(self._state,
default_flow_style=False))
if hasattr(self, '_state_file_path'):
with open(self._state_file_path, 'w+') as fh:
fh.write(yaml.dump(self._state,
default_flow_style=False))
return True
return False

def retrieve(self):
with open(self._state_file_path, 'r') as fh:
self._state = yaml.load(fh.read())
if hasattr(self, '_state_file_path'):
with open(self._state_file_path, 'r') as fh:
self._state = yaml.load(fh.read())
return True
return False

def set_is_installed(self, part):
""" let state know the part is installed """
Expand Down
30 changes: 20 additions & 10 deletions uranium/uranium.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import logging
import os
from .bin import BinDirectory
from .buildout_adapter import BuildoutAdapter
from .classloader import ClassLoader
from .pip_manager import PipManager
from .config import Config
from .buildout_adapter import BuildoutAdapter
from .plugin_runner import PluginRunner
from .phases import (AFTER_EGGS, BEFORE_EGGS)
from .messages import START_URANIUM, END_URANIUM
from .bin import BinDirectory
from .phases import (AFTER_EGGS, BEFORE_EGGS)
from .pip_manager import PipManager
from .plugin_runner import PluginRunner
from .store import Store
LOGGER = logging.getLogger(__name__)

PARTS_DIRECTORY = "parts"
Expand All @@ -21,24 +22,22 @@ class UraniumException(Exception):

class Uranium(object):

def __init__(self, config, root):
def __init__(self, config, root, store_file=None):
# well cast the dict to a config for people
# to make it easier
if type(config) == dict:
config = Config(config)

self._root = root
self._config = config

self._pip = PipManager(index_urls=self._config.indexes,
# this is a lambda to ensure we always
# pick up a newly resolved version
versions=lambda: self.config.resolved_versions)
self._classloader = ClassLoader(self._pip)

self._buildout = BuildoutAdapter(self, self._classloader)
self._plugin_runner = PluginRunner(self, self._classloader)

self._store = Store(store_file)
self._validate_config()

@property
Expand Down Expand Up @@ -78,7 +77,18 @@ def run_part(self, name):
runner = self._buildout if part.type == "recipe" else self._plugin_runner

part_instance = runner.get_part_instance(part)
runner.install_part(part_instance)

if self._store.is_part_installed(name):
runner.install_part(part_instance)

else:
part_info = self._store.get_installed_part(name)
if part_info['type'] == part.type and \
part_info['entry_point'] == part.entry_point:
runner.update_part(part_instance)
else:
# todo: add a delete part
runner.install_part(part_instance)

def run_phase(self, phase):
LOGGER.debug("running phase {0}...".format(phase.key))
Expand Down

0 comments on commit 7cf6f23

Please sign in to comment.