tools: adding error and warning calls
authorFredrik Unger <fred@tree.se>
Tue, 31 Mar 2015 12:25:54 +0000 (14:25 +0200)
committerFredrik Unger <fred@tree.se>
Tue, 31 Mar 2015 12:25:54 +0000 (14:25 +0200)
Adding calls to error and warning to simplify error reporting
to standard error.

treecutter/docbook.py
treecutter/tools.py

index a143487f7c071a2d8ed23805f56797bcac88beaa..e7b6e9f6d833099ca504276a24970c3cb4d94447 100644 (file)
@@ -11,6 +11,7 @@ from time import time
 
 import treecutter.constants as const
 from treecutter.image import Image
+from treecutter.tools import warning
 
 class Docbook():
     """Class representing a docbook document"""
@@ -82,7 +83,8 @@ class Docbook():
                 (stdout, stderr) = xml.communicate()
                 #print xml.returnvalue
                 if stderr:
-                    print " ".join(exe)+" ERROR : [ "+stderr+" ]"
+                    warning("%s : %s" % (" ".join(exe),stderr))
+                    warning(stdout)
                     exit
                 os.chdir(cwd)
                 te = time()
index 62cb32a71943c6cdf3aa19bd59f20ef8bfd2c398..fa06a6d1272ab2e2abf757177098462b5ecdf366 100644 (file)
@@ -1,7 +1,9 @@
 #!/usr/bin/python
+from __future__ import print_function
 import os
 import subprocess
 import errno
+import sys
 
 def mkdir_p(path):
     try:
@@ -15,7 +17,7 @@ def publish(src,target):
     cmd = ["rsync","-a","--delete",src,target]
     retcode = subprocess.call(cmd)
     if retcode:
-        print 'Error: '+' '.join(cmd)+' Returncode ['+str(retcode)+']'
+        error('%s : retruncode %s' % (' '.join(cmd),str(retcode)))
 
 def ssh_cmd(target, command):
     t = target.split(":")
@@ -26,7 +28,7 @@ def ssh_cmd(target, command):
         cmd = ["ssh",t[0],c[0],c[1],t[1]]
     retcode = subprocess.call(cmd)
     if retcode:
-        print 'Error: '+' '.join(cmd)+' Returncode ['+str(retcode)+']'
+        error('%s : retruncode %s' % (' '.join(cmd),str(retcode)))
 
 def sizeof_fmt(num, suffix='B'):
     for unit in ['','Ki','Mi','Gi','Ti','Pi','Ei','Zi']:
@@ -44,3 +46,9 @@ def get_folder_size(folder):
         elif os.path.isdir(itempath):
             total_size += get_folder_size(itempath)
     return total_size
+
+def warning(*objs):
+    print("WARNING: ", *objs, file=sys.stderr)
+
+def error(*objs):
+    print("ERROR: ", *objs, file=sys.stderr)