java/sandbox/data-cat/scripts
--- java/sandbox/data-cat/scripts/hps_datacat_find.py 2014-05-30 22:00:04 UTC (rev 640)
+++ java/sandbox/data-cat/scripts/hps_datacat_find.py 2014-05-30 22:01:20 UTC (rev 641)
@@ -1,84 +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]
-
-# 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:
- raise Exception('path is required!')
-
-if args['site'] != None:
- site = args['site']
- if site != 'SLAC' and site != 'JLAB':
- raise Exception("Unrecognized site!")
-
-if args['connection'] != None:
- connection = args['connection']
-
-output = None
-if args['output'] != None:
- output = args['output']
- if os.path.isfile(output):
- raise Exception('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/scripts
--- java/sandbox/data-cat/scripts/hps_datacat_register_file.py 2014-05-30 22:00:04 UTC (rev 640)
+++ java/sandbox/data-cat/scripts/hps_datacat_register_file.py 2014-05-30 22:01:20 UTC (rev 641)
@@ -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