Skip to content

Commit

Permalink
adding logging
Browse files Browse the repository at this point in the history
  • Loading branch information
toumorokoshi committed Feb 1, 2015
1 parent 858b8f6 commit 4e8f312
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 6 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
packages=find_packages(),
install_requires=install_requires,
classifiers=[
'Development Status :: 1 - Planning',
'Development Status :: 3 - Alpha',
'Operating System :: MacOS',
'Operating System :: POSIX :: Linux',
'Topic :: System :: Software Distribution',
Expand Down
18 changes: 13 additions & 5 deletions uranium/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,20 @@ def _activate_virtualenv(uranium_dir):
# when activating a sandbox.
pkg_resources.working_set.entries = sys.path

LOGGING_NAMES = [__name__]


def _create_stdout_logger():
""" create a logger to stdout """
log = logging.getLogger(__name__)
"""
create a logger to stdout. This creates logger for a series
of module we would like to log information on.
"""
out_hdlr = logging.StreamHandler(sys.stdout)
out_hdlr.setFormatter(logging.Formatter('%(message)s'))
out_hdlr.setFormatter(logging.Formatter(
'[%(asctime)s] %(message)s', "%H:%M:%S"
))
out_hdlr.setLevel(logging.INFO)
log.addHandler(out_hdlr)
log.setLevel(logging.INFO)
for name in LOGGING_NAMES:
log = logging.getLogger(name)
log.addHandler(out_hdlr)
log.setLevel(logging.INFO)
11 changes: 11 additions & 0 deletions uranium/messages.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
START_URANIUM = [
'================',
'STARTING URANIUM',
'================'
]

END_URANIUM = [
'================',
'URANIUM FINISHED',
'================'
]
17 changes: 17 additions & 0 deletions uranium/pip_manager/req_set.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import logging
from pip.req import RequirementSet
from collections import Callable

LOGGER = logging.getLogger(__name__)


class UraniumRequirementSet(RequirementSet):
"""
Expand All @@ -11,6 +14,7 @@ class UraniumRequirementSet(RequirementSet):
def add_requirement(self, install_req):
if not install_req.editable:
self._uranium_rectify_versions(install_req)
_log_requirement_added(install_req)
super(UraniumRequirementSet, self).add_requirement(install_req)

def _uranium_rectify_versions(self, install_req):
Expand All @@ -36,3 +40,16 @@ def uranium_versions(self):
@uranium_versions.setter
def uranium_versions(self, val):
self._uranium_versions = val


def _log_requirement_added(install_req):
if install_req.editable:
msg = "Adding develop-egg {0}".format(install_req.source_dir)
else:
msg = "Adding requirement {0}".format(
install_req.req.project_name
)
if install_req.req.specifier:
msg += str(install_req.req.specifier)

LOGGER.info(msg + "...")
8 changes: 8 additions & 0 deletions uranium/uranium.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from .buildout_adapter import BuildoutAdapter
from .isotope_runner import IsotopeRunner
from .phases import (AFTER_EGGS, BEFORE_EGGS)
from .messages import START_URANIUM, END_URANIUM

LOGGER = logging.getLogger(__name__)

Expand Down Expand Up @@ -45,12 +46,18 @@ def root(self):
return self._root

def run(self):
[LOGGER.info(l) for l in START_URANIUM]

self._create_bin_directory()
self.run_phase(BEFORE_EGGS)
LOGGER.info("installing eggs...")
self._install_eggs()
self.run_phase(AFTER_EGGS)

[LOGGER.info(l) for l in END_URANIUM]

def run_part(self, name):
LOGGER.info("running part {0}...".format(name))
part = self._config.get_part(name)

runner = self._buildout if part.is_recipe else self._isotope
Expand All @@ -59,6 +66,7 @@ def run_part(self, name):
runner.install_part(part_instance)

def run_phase(self, phase):
LOGGER.debug("running phase {0}...".format(phase.key))
part_names = self._config.phases.get(phase.key, [])
for name in part_names:
self.run_part(name)
Expand Down

0 comments on commit 4e8f312

Please sign in to comment.