aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAaron LI <aaronly.me@outlook.com>2017-03-05 12:48:52 +0800
committerAaron LI <aaronly.me@outlook.com>2017-03-05 12:48:52 +0800
commit7941e22b66edea6f90fc1a170d0fce76b1befadb (patch)
tree915c029e58082327749f10bc6f3c9a31bbb80637
parentfd5ba7ad61a8c7c9aad6b3f1404d819ae21085d1 (diff)
downloadchandra-acis-analysis-7941e22b66edea6f90fc1a170d0fce76b1befadb.tar.bz2
manifest: Add logging support; avoid print messages
-rw-r--r--acispy/manifest.py37
-rwxr-xr-xbin/manifest.py5
-rwxr-xr-xbin/results.py5
3 files changed, 27 insertions, 20 deletions
diff --git a/acispy/manifest.py b/acispy/manifest.py
index bfdd6fd..dc83c76 100644
--- a/acispy/manifest.py
+++ b/acispy/manifest.py
@@ -17,12 +17,17 @@ and other structures in the YAML file.
"""
import os
-from collections import OrderedDict
+import sys
import argparse
+import logging
+from collections import OrderedDict
import ruamel.yaml
+logger = logging.getLogger(__name__)
+
+
class Manifest:
"""
Manage the observational products manifest.
@@ -142,6 +147,7 @@ class Manifest:
"""
self.manifest[key] = self.parse_value(value)
self.save()
+ logger.info("Set item '{0}': {1}".format(key, self.get(key)))
def setpath(self, key, path):
"""
@@ -160,6 +166,7 @@ class Manifest:
relpath = os.path.relpath(abspath, start=dirname)
self.manifest[key] = relpath
self.save()
+ logger.info("Set file item '{0}': {1}".format(key, self.get(key)))
def add(self, key, value):
"""
@@ -167,7 +174,7 @@ class Manifest:
If the specified item already exists, raise a ``KeyError``.
"""
- if key in self.manifest:
+ if self.has(key):
raise KeyError("manifest already has item: '%s'" % key)
else:
self.set(key, value)
@@ -178,7 +185,7 @@ class Manifest:
If the specified item doesn't exist, raise a ``KeyError``.
"""
- if key in self.manifest:
+ if self.has(key):
self.set(key, value)
else:
raise KeyError("manifest doesn't have item: '%s'" % key)
@@ -187,8 +194,12 @@ class Manifest:
"""
Delete the specified item from the manifest.
"""
- del self.manifest[key]
- self.save()
+ if self.has(key):
+ del self.manifest[key]
+ self.save()
+ logger.info("Deleted item: '%s'" % key)
+ else:
+ logger.warning("manifest does not have item '%s'" % key)
def rename(self, oldkey, newkey):
"""
@@ -206,6 +217,7 @@ class Manifest:
# Delete old item
del self.manifest[oldkey]
self.save()
+ logger.info("Renamed item key: '%s' -> '%s'" % (oldkey, newkey))
@classmethod
def parse_value(self, value):
@@ -344,8 +356,6 @@ def cmd_set(args, manifest):
(Will add a new item or update an existing item.)
"""
manifest.set(args.key, args.value)
- if not args.brief:
- print("Set item '{0}': {1}".format(args.key, manifest.get(args.key)))
def cmd_setpath(args, manifest):
@@ -354,9 +364,6 @@ def cmd_setpath(args, manifest):
to be the relative path of the given file w.r.t. the manifest file.
"""
manifest.setpath(args.key, args.value)
- if not args.brief:
- print("Set file item '{0}': {1}".format(args.key,
- manifest.get(args.key)))
def cmd_add(args, manifest):
@@ -364,8 +371,6 @@ def cmd_add(args, manifest):
Sub-command "add": Add a new item to the manifest.
"""
manifest.add(args.key, args.value)
- if not args.brief:
- print("Added item '{0}': {1}".format(args.key, manifest.get(args.key)))
def cmd_update(args, manifest):
@@ -373,11 +378,7 @@ def cmd_update(args, manifest):
Sub-command "update": Update the value of an existing item in the
manifest.
"""
- value_old = manifest.get(args.key)
manifest.update(args.key, args.value)
- if not args.brief:
- print("Updated item '{0}': {1} -> {2}".format(
- args.key, value_old, manifest.get(args.key)))
def cmd_delete(args, manifest):
@@ -385,8 +386,6 @@ def cmd_delete(args, manifest):
Sub-command "delete": Delete an item from the manifest.
"""
manifest.delete(args.key)
- if not args.brief:
- print("Deleted item: %s" % args.key)
def cmd_rename(args, manifest):
@@ -394,8 +393,6 @@ def cmd_rename(args, manifest):
Sub-command "rename": Rename an item in the manifest.
"""
manifest.rename(args.key, args.newkey)
- if not args.brief:
- print("Renamed item key: '%s' -> '%s'" % (args.key, args.newkey))
def main(description="Manage the observation manifest (YAML format)",
diff --git a/bin/manifest.py b/bin/manifest.py
index 6b100f0..0e56036 100755
--- a/bin/manifest.py
+++ b/bin/manifest.py
@@ -18,9 +18,14 @@ and other structures in the YAML file.
.. _`PyYAML`: http://pyyaml.org/
"""
+import logging
+
from _context import acispy
from acispy import manifest
+logging.basicConfig(level=logging.INFO)
+
+
if __name__ == "__main__":
manifest.main()
diff --git a/bin/results.py b/bin/results.py
index d325dc3..3ea7750 100755
--- a/bin/results.py
+++ b/bin/results.py
@@ -10,9 +10,14 @@
Manage the analysis results in YAML format.
"""
+import logging
+
from _context import acispy
from acispy import results
+logging.basicConfig(level=logging.INFO)
+
+
if __name__ == "__main__":
results.main()