Print

Print


Commit in java/trunk/datacat/src/main/python/hpsdatacat on MAIN
add_location.py+3-3736 -> 737
add_metadata.py+3-3736 -> 737
crawler.py+16-10736 -> 737
delete.py+3-3736 -> 737
extract_metadata.py+7-3736 -> 737
find.py+5-2736 -> 737
register.py+3-3736 -> 737
util.py+18-8736 -> 737
+58-35
8 modified files
Add verbosity setting.  Some other small changes.

java/trunk/datacat/src/main/python/hpsdatacat
add_location.py 736 -> 737
--- java/trunk/datacat/src/main/python/hpsdatacat/add_location.py	2014-06-24 23:17:29 UTC (rev 736)
+++ java/trunk/datacat/src/main/python/hpsdatacat/add_location.py	2014-06-25 22:42:54 UTC (rev 737)
@@ -19,7 +19,7 @@
 args = vars(parser.parse_args())
 
 # process command line arguments
-connection, dry_run, mode = handle_standard_arguments(args)
+connection, dry_run, mode, verbose = handle_standard_arguments(args)
 if connection == None:    
     connection = get_ssh_connection_string()    
     if connection == None:
@@ -45,7 +45,7 @@
 command_line += ' %s %s %s' % (dataset_name, logical_folder, file_path)
 
 # run the command
-lines, errors, return_value = run_process(command_line)
+lines, errors, return_value = run_process(command_line, verbose)
 
 # print results
-print_result(__command, return_value, errors)
\ No newline at end of file
+print_result(__command, return_value, errors, True)
\ No newline at end of file

java/trunk/datacat/src/main/python/hpsdatacat
add_metadata.py 736 -> 737
--- java/trunk/datacat/src/main/python/hpsdatacat/add_metadata.py	2014-06-24 23:17:29 UTC (rev 736)
+++ java/trunk/datacat/src/main/python/hpsdatacat/add_metadata.py	2014-06-25 22:42:54 UTC (rev 737)
@@ -19,7 +19,7 @@
 args = vars(parser.parse_args())
 
 # handle standard arguments
-connection, dry_run, mode = handle_standard_arguments(args)
+connection, dry_run, mode, verbose = handle_standard_arguments(args)
   
 # file_path
 file_path = args['name']
@@ -48,7 +48,7 @@
 command_line += ' %s' % logical_folder
 
 # run the command
-lines, errors, return_value = run_process(command_line)
+lines, errors, return_value = run_process(command_line, verbose)
 
 # print end message
-print_result(__command, return_value, errors)
\ No newline at end of file
+print_result(__command, return_value, errors, True)
\ No newline at end of file

java/trunk/datacat/src/main/python/hpsdatacat
crawler.py 736 -> 737
--- java/trunk/datacat/src/main/python/hpsdatacat/crawler.py	2014-06-24 23:17:29 UTC (rev 736)
+++ java/trunk/datacat/src/main/python/hpsdatacat/crawler.py	2014-06-25 22:42:54 UTC (rev 737)
@@ -39,7 +39,7 @@
 parser.add_argument('-p', '--path', help='path in the data catalog')
 args = vars(parser.parse_args())
 
-connection_string, dry_run, mode = handle_standard_arguments(args)
+connection, dry_run, mode, verbose = handle_standard_arguments(args)
 
 # Try to figure out a default connection string if none was supplied.    
 if connection_string == None:    
@@ -85,6 +85,8 @@
     # only look at files with extension matching argument
     handle_extensions = (args['extension'])
 
+print "crawling from root dir %s" % base_directory
+
 # walk the directory tree
 for dirname, dirnames, filenames in os.walk(base_directory):
     # ignore directories starting with a '.'
@@ -142,15 +144,19 @@
                 command_line += '%s' % metadata
                  
                 # run the register command and print results
-                print "Registering new file with command ..."
-                print command_line                                                                        
-                lines, errors, return_value = run_process(command_line, False)                
-                if len(errors) > 0 or return_value != 0:
-                    print "Command returned with an error!"                    
-                    # just print the first error
-                    print errors[0]
-                else:
-                    print "File successfully registered!"
+                if verbose:
+                    print "Registering new file with command ..."
+                    print command_line
 
+                # only run sub-command if dry-run is off                    
+                if not dry_run:                    
+                    lines, errors, return_value = run_process(command_line, False)
+                    if len(errors) > 0 or return_value != 0:
+                        print "Command returned with an error!" 
+                        # just print the first error
+                        print errors[0]
+                    else:
+                        print "File successfully registered!"
+
 # touch the timestamp file to update its modification time
 os.utime(timestamp_file_path, None)
\ No newline at end of file

java/trunk/datacat/src/main/python/hpsdatacat
delete.py 736 -> 737
--- java/trunk/datacat/src/main/python/hpsdatacat/delete.py	2014-06-24 23:17:29 UTC (rev 736)
+++ java/trunk/datacat/src/main/python/hpsdatacat/delete.py	2014-06-25 22:42:54 UTC (rev 737)
@@ -14,7 +14,7 @@
 args = vars(parser.parse_args())
 
 # process command line arguments
-connection, dry_run, mode = handle_standard_arguments(args)
+connection, dry_run, mode, verbose = handle_standard_arguments(args)
 logical_folder = args['path']
     
 # build command line
@@ -22,7 +22,7 @@
 command_line += ' --force %s' % logical_folder
 
 # run command line
-lines, errors, return_value = run_process(command_line)
+lines, errors, return_value = run_process(command_line, verbose)
 
 # print the result
-print_result(__command, return_value, errors) 
\ No newline at end of file
+print_result(__command, return_value, errors, True)
\ No newline at end of file

java/trunk/datacat/src/main/python/hpsdatacat
extract_metadata.py 736 -> 737
--- java/trunk/datacat/src/main/python/hpsdatacat/extract_metadata.py	2014-06-24 23:17:29 UTC (rev 736)
+++ java/trunk/datacat/src/main/python/hpsdatacat/extract_metadata.py	2014-06-25 22:42:54 UTC (rev 737)
@@ -25,9 +25,13 @@
 import sys, os, ast
 from util import *
 
-suppress_print()
-from pyLCIO import IOIMPL
-restore_print()
+#suppress_print()
+try:
+    from pyLCIO import IOIMPL
+except ImportError:
+    fatal_error("Failed to import pyLCIO.")        
+    
+#restore_print()
 
 import ROOT
 

java/trunk/datacat/src/main/python/hpsdatacat
find.py 736 -> 737
--- java/trunk/datacat/src/main/python/hpsdatacat/find.py	2014-06-24 23:17:29 UTC (rev 736)
+++ java/trunk/datacat/src/main/python/hpsdatacat/find.py	2014-06-25 22:42:54 UTC (rev 737)
@@ -22,7 +22,7 @@
 args = vars(parser.parse_args())
 
 # get standard arguments
-connection, dry_run, mode = handle_standard_arguments(args)    
+connection, dry_run, mode, verbose = handle_standard_arguments(args)    
 logical_folder = args['path']
 site = args['site']
 check_valid_site(site)
@@ -50,8 +50,11 @@
         raise Exception('The output file already exists!')
     output_file = open(output, 'w')
 
+# print to screen if no output file
+printOutput = (output == None)
+
 # run the command
-lines, errors, return_value = run_process(command_line)
+lines, errors, return_value = run_process(command_line, verbose, printOutput)
 
 # print or save the output if command was successful
 if (return_value == 0 and len(errors) == 0):

java/trunk/datacat/src/main/python/hpsdatacat
register.py 736 -> 737
--- java/trunk/datacat/src/main/python/hpsdatacat/register.py	2014-06-24 23:17:29 UTC (rev 736)
+++ java/trunk/datacat/src/main/python/hpsdatacat/register.py	2014-06-25 22:42:54 UTC (rev 737)
@@ -20,7 +20,7 @@
 args = vars(parser.parse_args())
 
 # process command line arguments
-connection, dry_run, mode = handle_standard_arguments(args)            
+connection, dry_run, mode, verbose = handle_standard_arguments(args)
 logical_folder = args['path']
 file_path = args['file']
 file_extension = os.path.splitext(file_path)[1][1:]
@@ -42,7 +42,7 @@
 command_line += ' %s %s %s' % (file_extension, logical_folder, file_path)
 
 # run the command
-lines, errors, return_value = run_process(command_line)
+lines, errors, return_value = run_process(command_line, verbose, verbose)
 
 # print file_path information for new dataset
 if return_value == 0:
@@ -54,4 +54,4 @@
     print '  metadata: %s' % str(raw_metadata)
 
 # print command result
-print_result(__command, return_value, errors)
\ No newline at end of file
+print_result(__command, return_value, errors, verbose)
\ No newline at end of file

java/trunk/datacat/src/main/python/hpsdatacat
util.py 736 -> 737
--- java/trunk/datacat/src/main/python/hpsdatacat/util.py	2014-06-24 23:17:29 UTC (rev 736)
+++ java/trunk/datacat/src/main/python/hpsdatacat/util.py	2014-06-25 22:42:54 UTC (rev 737)
@@ -81,9 +81,9 @@
 """
 Run a process in a shell and return the output lines, errors, and return value (in that order). 
 """
-def run_process(command, printToScreen=True):
+def run_process(command, verbose=True, printOutput=True):
     
-    if printToScreen:
+    if verbose:
         print "Executing command ..."
         print command
     
@@ -91,8 +91,8 @@
     errors = []
     lines = []
     for line in process.stdout.readlines():
-        if printToScreen:
-            print line,            
+        if printOutput:
+            print line,
         if 'Exception' in line:
             errors.append(line)
         lines.append(line)
@@ -126,7 +126,7 @@
 
 """
 Create the basic argparser for data catalog commands which includes handling
-of dry run, mode and connection settings.  These are all optional.
+of dry run, mode, verbosity and connection settings.  These are all optional.
 """
 def create_base_argparser(command):
     if command not in __valid_commands:
@@ -135,6 +135,7 @@
     parser.add_argument('-D', '--dry-run', help='perform dry run only with no database commits', action='store_true')
     parser.add_argument('-M', '--mode', help='set data source as PROD, DEV, or TEST')
     parser.add_argument('-c', '--connection', help='SSH connection string in form user@host', default=get_ssh_connection_string())
+    parser.add_argument('-v', '--verbose', help='run in verbose mode', action='store_true')
     return parser
 
 """
@@ -144,10 +145,11 @@
     if args['connection'] != None:
         connection = args['connection']
     else:
-        raise Exception("Could not figure out SSH connection!")
+        raise Exception("Could not figure out an SSH connection!")
     dry_run = args['dry_run']        
     mode = args['mode']
-    return connection, dry_run, mode
+    verbose = args['verbose']
+    return connection, dry_run, mode, verbose
 
 """
 Print the results of running a command.
@@ -194,4 +196,12 @@
 """    
 def restore_print():    
     sys.stdout = sys.__stdout__
-    sys.stderr = sys.__stderr__
\ No newline at end of file
+    sys.stderr = sys.__stderr__
+    
+"""
+Raise a fatal error.
+"""
+def fatal_error(message, return_value=1):
+    print "Fatal error: %s" % message
+    sys.exit(return_value)
+    
\ No newline at end of file
SVNspam 0.1