|
[Rivet-svn] r3730 - trunk/binblackhole at projects.hepforge.org blackhole at projects.hepforge.orgThu May 17 13:12:41 BST 2012
Author: buckley Date: Thu May 17 13:12:40 2012 New Revision: 3730 Log: Renaming rivet-find-id to the one-hyphen convention used for the other rivet- scripts, and modifying to use optparse Added: trunk/bin/rivet-findid - copied, changed from r3729, trunk/bin/rivet-find-id Deleted: trunk/bin/rivet-find-id Modified: trunk/bin/Makefile.am Modified: trunk/bin/Makefile.am ============================================================================== --- trunk/bin/Makefile.am Tue May 15 17:07:29 2012 (r3729) +++ trunk/bin/Makefile.am Thu May 17 13:12:40 2012 (r3730) @@ -9,7 +9,7 @@ rivet \ rivet-mkanalysis rivet-buildplugin \ rivet-chopbins rivet-rmgaps rivet-rescale \ - rivet-mergeruns rivet-mkhtml rivet-find-id + rivet-mergeruns rivet-mkhtml rivet-findid if ENABLE_PYEXT dist_bin_SCRIPTS += $(RIVETPROGS) Copied and modified: trunk/bin/rivet-findid (from r3729, trunk/bin/rivet-find-id) ============================================================================== --- trunk/bin/rivet-find-id Tue May 15 17:07:29 2012 (r3729, copy source) +++ trunk/bin/rivet-findid Thu May 17 13:12:40 2012 (r3730) @@ -1,7 +1,17 @@ #! /usr/bin/env python -import sys, re -import urllib2 -import rivet + +"""%prog ID [ID ...] + +%prog -- ID lookup helper for Rivet + +Looks up the Rivet analysis and other ID formats matching the given ID. + +Arguments: + ID A paper ID in one of the following formats + - arXiv: yymm.nnnn + - arXiv: foo-bar/yymmnnn + - SPIRES: [S]nnnnnnn + - Inspire: [I]nnnnnn[n]""" try: import xml.etree.cElementTree as ET @@ -15,34 +25,28 @@ sys.stderr.write("Can't load the ElementTree XML parser\n") sys.exit(1) -ALL_ANALYSES = rivet.AnalysisLoader.analysisNames() - -arxiv_pattern = re.compile('^\d\d[01]\d\.\d{4}$|^(hep-(ex|ph|th)|nucl-ex)/\d\d[01]\d{4}$') -spires_pattern = re.compile('^(S|I)?(\d{6}\d?)$') - def main(): - if len(sys.argv) < 2: - sys.stderr.write("""\ -Usage: %s ID [ID ...] + ## Handle command line args + import optparse + op = optparse.OptionParser(usage=__doc__) + opts, args = op.parse_args() + if not args: + op.print_help() + exit(1) -ID lookup helper for Rivet. -Looks up the Rivet analysis and other ID formats matching the given ID. - -Arguments: - ID A paper ID in one of the following formats - - arXiv: yymm.nnnn - - arXiv: foo-bar/yymmnnn - - SPIRES: [S]nnnnnnn - - Inspire: [I]nnnnnn[n] + ## Set up some variables before the loop over args + import re + arxiv_pattern = re.compile('^\d\d[01]\d\.\d{4}$|^(hep-(ex|ph|th)|nucl-ex)/\d\d[01]\d{4}$') + spires_pattern = re.compile('^(S|I)?(\d{6}\d?)$') + import rivet + ALL_ANALYSES = rivet.AnalysisLoader.analysisNames() -""" % sys.argv[0]) - exit(1) - - for N,id in enumerate(sys.argv[1:]): + ## Loop over requested IDs + for N, id in enumerate(args): a_match = arxiv_pattern.match(id) s_match = spires_pattern.match(id) @@ -62,11 +66,11 @@ if len(number) == 7: RESULT = try_spires(number) RESULT.update( try_inspire(number) ) - else: sys.stderr.write('error Pattern %s does not match any known ID pattern.\n' % id) continue + rivet_candidates = [] if 'inspire' in RESULT: rivet_candidates += try_rivet('I'+RESULT['inspire']) @@ -75,11 +79,9 @@ if rivet_candidates: RESULT['rivet'] = rivet_candidates[0] - if N > 0: print + if N > 0: + print "" output(RESULT) - - - @@ -110,8 +112,6 @@ - - def try_arxiv(id): url = 'http://inspirehep.net/search?p=eprint+%s&of=xm' % id ret = _search_inspire(url) @@ -149,6 +149,7 @@ def _search_inspire(url): result = {} + import urllib2 urlstream = urllib2.urlopen(url) tree = ET.parse(urlstream) for i in tree.getiterator('{http://www.loc.gov/MARC21/slim}controlfield'): @@ -177,5 +178,6 @@ return result + if __name__ == "__main__": main()
More information about the Rivet-svn mailing list |