Print

Print


Commit in java/sandbox/data-cat/src/main/python/hpsdatacat on MAIN
find.py+100added 650
find_files.py-87649 removed
register.py+123added 650
register_file.py-123649 removed
+223-210
2 added + 2 removed, total 4 files
Change script names.

java/sandbox/data-cat/src/main/python/hpsdatacat
find.py added at 650
--- java/sandbox/data-cat/src/main/python/hpsdatacat/find.py	                        (rev 0)
+++ java/sandbox/data-cat/src/main/python/hpsdatacat/find.py	2014-06-02 20:04:49 UTC (rev 650)
@@ -0,0 +1,100 @@
+#!/usr/bin/env python2.7
+
+""" 
+Script wrapper for finding files in the data catalog.
+
+author: Jeremy McCormick <[log in to unmask]> 
+"""
+
+# Python lib imports
+import argparse, os.path, subprocess, socket, getpass
+
+# import utility stuff from hpsdatacat
+from util import *
+
+# get connection_string string
+connection_string = get_ssh_connection_string()
+
+# get the command to use
+script_cmd = get_datacat_command( 'find' )
+
+# default options for search command
+script_options = '--search-groups --recurse'
+
+# default path in the data catalog
+default_path = get_default_search_path()
+
+# site
+site = get_default_site()
+
+#def escape_characters(raw_string):
+#    escaped_string = raw_string.replace('"', '\\"').replace(' ', '\\ ')
+#    return escaped_string 
+
+parser = argparse.ArgumentParser(description='Search for files in HPS data catalog')
+parser.add_argument('-p', '--path', help='root path for search')
+parser.add_argument('-s', '--site', help='dataset site')
+parser.add_argument('-c', '--connection_string', help='SSH connection_string')
+parser.add_argument('-o', '--output', help='save results to output file')
+parser.add_argument('-q', '--query', help='data query for filtering results')
+
+args = vars(parser.parse_args())
+    
+if args['path'] != None:
+    path = args['path']
+else:
+    path = default_path
+    
+if args['site'] != None:
+    site = args['site']
+    if site != 'SLAC' and site != 'JLAB':
+        raise Exception("Unrecognized site argument!")
+    
+if args['connection_string'] != None:
+    connection_string = args['connection_string']
+    
+if connection_string == None:
+    raise Exception("Could not determine connection_string string!")    
+    
+output = None
+if args['output'] != None:
+    output = args['output']
+    if os.path.isfile(output):
+        raise Exception('The output file already exists!')
+    
+query = ''    
+if args['query'] != None:
+    #print args['query']
+    query = '--filter \'%s\'' % args['query']
+    query = escape_characters(query)
+    print query
+                
+cmd = 'ssh %s %s %s --site %s %s %s' % (connection_string, script_cmd, script_options, site, query, path)
+
+print "Executing query ..."
+print cmd
+
+if output != None:
+    output_file = open(output, 'w')
+
+process = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
+errors = []
+lines = []
+for line in process.stdout.readlines():
+    lines.append(line)
+    if 'Exception' in line:
+        errors.append(line)        
+        
+retval = process.wait()
+
+if (retval == 0 and len(errors) == 0):
+    if output != None:
+        for line in lines:
+            output_file.write(line)
+        output_file.close()       
+    else:
+        for line in lines:
+            print line,
+else:
+    print 'The find command failed with errors!'
+    print errors
\ No newline at end of file

java/sandbox/data-cat/src/main/python/hpsdatacat
find_files.py removed after 649
--- java/sandbox/data-cat/src/main/python/hpsdatacat/find_files.py	2014-06-02 20:04:23 UTC (rev 649)
+++ java/sandbox/data-cat/src/main/python/hpsdatacat/find_files.py	2014-06-02 20:04:49 UTC (rev 650)
@@ -1,87 +0,0 @@
-#!/usr/bin/env python2.7
-
-""" 
-Script wrapper for updating HPS data catalog via SSH connection to SLAC.
-
-author: Jeremy McCormick <[log in to unmask]> 
-"""
-
-import argparse, os.path, subprocess
-
-# path to script at SLAC
-script_cmd = '~srs/datacat/prod/datacat-hps find'
-
-# default options for search command
-script_options = '--search-groups --recurse'
-
-# default SLAC account for SSH connection
-connection = [log in to unmask]
-
-# default path in the data catalog
-default_path = '/HPS'
-
-# site
-site = 'SLAC'
-
-parser = argparse.ArgumentParser(description='Search for files in HPS data catalog')
-parser.add_argument('-p', '--path', help='root path for search')
-parser.add_argument('-s', '--site', help='dataset site')
-parser.add_argument('-c', '--connection', help='SSH connection')
-parser.add_argument('-o', '--output', help='save results to output file')
-parser.add_argument('-q', '--query', help='data query for filtering results')
-
-args = vars(parser.parse_args())
-    
-if args['path'] != None:
-    path = args['path']
-else:
-    path = default_path
-    
-if args['site'] != None:
-    site = args['site']
-    if site != 'SLAC' and site != 'JLAB':
-        raise Exception("Unrecognized site argument!")
-    
-if args['connection'] != None:
-    connection = args['connection']
-    
-output = None
-if args['output'] != None:
-    output = args['output']
-    if os.path.isfile(output):
-        raise Exception('The output file already exists!')
-    
-query = ''    
-if args['query'] != None:
-    #print args['query']
-    query = '--filter \'%s\'' % args['query'] 
-    print query
-                
-cmd = 'ssh %s %s %s --site %s %s %s' % (connection, script_cmd, script_options, site, query, path)
-
-print cmd
-
-if output != None:
-    output_file = open(output, 'w')
-
-process = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
-errors = []
-lines = []
-for line in process.stdout.readlines():
-    lines.append(line)
-    if 'Exception' in line:
-        errors.append(line)        
-        
-retval = process.wait()
-
-if (retval == 0 and len(errors) == 0):
-    if output != None:
-        for line in lines:
-            output_file.write(line)
-        output_file.close()       
-    else:
-        for line in lines:
-            print line,
-else:
-    print 'The find command failed with errors!'
-    print errors
\ No newline at end of file

java/sandbox/data-cat/src/main/python/hpsdatacat
register.py added at 650
--- java/sandbox/data-cat/src/main/python/hpsdatacat/register.py	                        (rev 0)
+++ java/sandbox/data-cat/src/main/python/hpsdatacat/register.py	2014-06-02 20:04:49 UTC (rev 650)
@@ -0,0 +1,123 @@
+#!/usr/bin/env python2.7
+
+""" 
+Script wrapper for updating HPS data catalog via SSH connection_string to SLAC.
+
+author: Jeremy McCormick <[log in to unmask]> 
+"""
+
+import argparse, os.path, subprocess, socket, getpass
+
+# path to script at SLAC
+script_cmd = '~srs/datacat/prod/datacat-hps registerDataset'
+
+# setup default connection_string
+connection_string = None
+domainname = socket.getfqdn()
+username = getpass.getuser()
+
+# FIXME: Make something like this work so JLAB users can connect to a generic account at SLAC.
+#if 'jlab' in domainname:
+#    if 'clashps' in username:
+#        connection_string = [log in to unmask]
+#elif 'slac' in domainname:
+if 'slac' in domainname:
+    connection_string = [log in to unmask] % getpass.getuser()
+
+# lowest level node in directory hierarchy
+group = 'HPS'
+
+# site
+site = 'SLAC'
+
+parser = argparse.ArgumentParser(description='Register file in HPS data catalog')
+parser.add_argument('-p', '--path', help='destination path in data catalog')
+parser.add_argument('-d', '--dataset', help='input physical dataset')
+parser.add_argument('-m', '--metadata', nargs='*', help='define meta data')
+parser.add_argument('-g', '--group', help='dataset group')
+parser.add_argument('-s', '--site', help='dataset site')
+parser.add_argument('-c', '--connection_string', help='SSH connection_string')
+parser.add_argument('-v', '--verbose', help='turn verbose mode on', action='store_true')
+parser.add_argument('-D', '--dry-run', help='dry run only', action='store_true')
+args = vars(parser.parse_args())
+
+verbose = False
+if args['verbose'] != None:
+    verbose = True    
+
+if verbose:
+    print args
+    
+if args['path'] != None:
+    path = args['path']
+else:
+    raise Exception('path is required!')
+
+if args['dataset'] != None:
+    dataset = args['dataset']
+else:    
+    raise Exception('dataset is required!')
+
+ext = os.path.splitext(dataset)[1][1:]
+
+if args['group'] != None:
+    group = args['group']
+    
+metadata = ''
+if args['metadata'] != None:
+    print args['metadata']
+    for var in args['metadata']:
+        equals = var.find('=')
+        if (len(var) < 3 or equals < 0):
+            raise Exception("Bad meta data variable format!")
+        metadata += '--define %s ' % (var)
+
+if args['site'] != None:
+    site = args['site']
+    if site != 'SLAC' and site != 'JLAB':
+        raise Exception("Unrecognized site!")
+    
+if args['connection_string'] != None:
+    connection_string = args['connection_string']
+    
+if connection_string == None:
+    raise Exception("Couldn't figure out a connection_string to use!")    
+    
+dry_run = False
+if args['dry_run']:
+    dry_run = True
+                
+cmd = 'ssh %s %s --group %s --site %s %s %s %s %s' % (connection_string, script_cmd, group, site, metadata, ext, path, dataset)
+
+if verbose:
+    print "Executing command ..."
+    print cmd 
+
+if dry_run:
+    print 'Configured for dry run, so command will not be executed.'
+else:
+    process = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
+    errors = []
+    for line in process.stdout.readlines():
+        if verbose:
+            print line,
+        if 'Exception' in line:
+            errors.append(line)              
+        
+    retval = process.wait()
+        
+    if len(errors) != 0 or retval != 0:
+        print 'The registration failed with errors!'
+        print errors            
+    else:
+        print 'Added data to catalog ...'
+        print '  dataset: %s' % dataset
+        print '  path: %s' % path
+        print '  group: %s' % group
+        print '  site: %s' % site
+        
+        #print '  metadata: ' % str(args['metadata'])
+    
+    print 'return value: %d' % retval
+    
+print 'Done!'    
\ No newline at end of file

java/sandbox/data-cat/src/main/python/hpsdatacat
register_file.py removed after 649
--- java/sandbox/data-cat/src/main/python/hpsdatacat/register_file.py	2014-06-02 20:04:23 UTC (rev 649)
+++ java/sandbox/data-cat/src/main/python/hpsdatacat/register_file.py	2014-06-02 20:04:49 UTC (rev 650)
@@ -1,123 +0,0 @@
-#!/usr/bin/env python2.7
-
-""" 
-Script wrapper for updating HPS data catalog via SSH connection to SLAC.
-
-author: Jeremy McCormick <[log in to unmask]> 
-"""
-
-import argparse, os.path, subprocess, socket, getpass
-
-# path to script at SLAC
-script_cmd = '~srs/datacat/prod/datacat-hps registerDataset'
-
-# setup default connection
-connection = None
-domainname = socket.getfqdn()
-username = getpass.getuser()
-
-# FIXME: Make something like this work so JLAB users can connect to a generic account at SLAC.
-#if 'jlab' in domainname:
-#    if 'clashps' in username:
-        # FIXME: In fact this account sucks for this purpose!
-#        connection = [log in to unmask]
-#        connection = [log in to unmask]
-#elif 'slac' in domainname:
-if 'slac' in domainname:
-    connection = 'ssh [log in to unmask] % getpass.getuser()
-
-# lowest level node in directory hierarchy
-group = 'HPS'
-
-# site
-site = 'SLAC'
-
-parser = argparse.ArgumentParser(description='Register file in HPS data catalog')
-parser.add_argument('-p', '--path', help='destination path in data catalog')
-parser.add_argument('-d', '--dataset', help='input physical dataset')
-parser.add_argument('-m', '--metadata', nargs='*', help='define meta data')
-parser.add_argument('-g', '--group', help='dataset group')
-parser.add_argument('-s', '--site', help='dataset site')
-parser.add_argument('-c', '--connection', help='SSH connection')
-parser.add_argument('-v', '--verbose', help='turn verbose mode on', action='store_true')
-parser.add_argument('-D', '--dry-run', help='dry run only', action='store_true')
-args = vars(parser.parse_args())
-
-verbose = False
-if args['verbose'] != None:
-    verbose = True    
-
-if verbose:
-    print args
-    
-if args['path'] != None:
-    path = args['path']
-else:
-    raise Exception('path is required!')
-
-if args['dataset'] != None:
-    dataset = args['dataset']
-else:    
-    raise Exception('dataset is required!')
-
-ext = os.path.splitext(dataset)[1][1:]
-
-if args['group'] != None:
-    group = args['group']
-    
-metadata = ''
-if args['metadata'] != None:
-    print args['metadata']
-    for var in args['metadata']:
-        equals = var.find('=')
-        if (len(var) < 3 or equals < 0):
-            raise Exception("Bad meta data variable format!")
-        metadata += '--define %s ' % (var)
-
-if args['site'] != None:
-    site = args['site']
-    if site != 'SLAC' and site != 'JLAB':
-        raise Exception("Unrecognized site!")
-    
-if args['connection'] != None:
-    connection = args['connection']
-    
-if connection == None:
-    raise Exception("Couldn't figure out a connection to use!")    
-    
-dry_run = False
-if args['dry_run']:
-    dry_run = True
-                
-cmd = 'ssh %s %s --group %s --site %s %s %s %s %s' % (connection, script_cmd, group, site, metadata, ext, path, dataset)
-
-if verbose:
-    print cmd 
-
-if dry_run:
-    print 'Configured for dry run so command will not be executed.'
-else:
-    process = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
-    errors = []
-    for line in process.stdout.readlines():
-        if verbose:
-            print line,
-        if 'Exception' in line:
-            errors.append(line)
-        
-    retval = process.wait()
-        
-    if len(errors) != 0 or retval != 0:
-        print 'The registration failed with errors!'
-        print errors            
-    else:
-        print 'Added data to catalog ...'
-        print '  dataset: %s' % dataset
-        print '  path: %s' % path
-        print '  group: %s' % group
-        #print '  metadata: ' % str(args['metadata'])
-        print '  site: ' % site
-    
-    print 'return value: %d' % retval
-    
-print 'Done!'    
\ No newline at end of file
SVNspam 0.1