Permalink
Browse files

Folder with jar and jar build files

  • Loading branch information...
1 parent 41aee08 commit d8a7ce66e43128efb12d14cd82922bf21fa9415b techmaurice committed with Maurice de Rooij Mar 3, 2011
Showing with 67 additions and 54 deletions.
  1. +16 −15 LICENSE.txt
  2. +27 −15 fido/fido.py
  3. +24 −24 setup.py
View
@@ -1,15 +1,16 @@
-FIDO: Format Identifier for Digital Objects
-
-Copyright 2010 The Open Planets Foundation
-
-Licensed under the Apache License, Version 2.0 (the "License");
-you may not use this file except in compliance with the License.
-You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
-Unless required by applicable law or agreed to in writing, software
-distributed under the License is distributed on an "AS IS" BASIS,
-WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-See the License for the specific language governing permissions and
-limitations under the License.
+FIDO: Format Identifier for Digital Objects
+
+Copyright 2010 The Open Planets Foundation
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+
View
@@ -1,12 +1,17 @@
#!python
+# -*- coding: utf-8 -*-
import sys, re, os, time
-import hashlib, urllib, urlparse, csv
+import hashlib, urllib, urlparse, csv, getopt
from xml.etree import cElementTree as ET
-version = '0.9.4'
+# needed for jarring
+import __builtin__
+
+version = '0.9.5'
defaults = {'bufsize': 128 * 1024,
'regexcachesize' : 2084,
'conf_dir' : os.path.join(os.path.dirname(__file__), 'conf'),
+ 'jar_conf_dir' : './conf',
'printmatch': "OK,%(info.time)s,%(info.puid)s,%(info.formatname)s,%(info.signaturename)s,%(info.filesize)s,\"%(info.filename)s\"\n",
'printnomatch' : "KO,%(info.time)s,,,,%(info.filesize)s,\"%(info.filename)s\"\n",
'format_files': ['formats.xml', 'format_extensions.xml'],
@@ -379,7 +384,7 @@ def convert_pronom_pattern_to_regex(pronom_pat, pos=None, offset=None, maxoffset
class Fido:
def __init__(self, quiet=False, bufsize=None, printnomatch=None, printmatch=None,
- extension=False, zip=False, handle_matches=None, conf_dir=None, format_files=None):
+ extension=False, zip=False, handle_matches=None, conf_dir=None, jar_conf_dir=None, format_files=None):
global defaults
self.quiet = quiet
self.bufsize = (defaults['bufsize'] if bufsize == None else bufsize)
@@ -389,12 +394,16 @@ def __init__(self, quiet=False, bufsize=None, printnomatch=None, printmatch=None
self.zip = zip
self.extension = extension
self.conf_dir = defaults['conf_dir'] if conf_dir == None else conf_dir
+ self.jar_conf_dir = defaults['jar_conf_dir'] #if jar_conf_dir == None else jar_conf_dir
self.format_files = defaults['format_files'] if format_files == None else format_files
self.formats = []
self.puid_format_map = {}
self.puid_has_priority_over_map = {}
for file in self.format_files:
- self.load_fido_xml(os.path.join(os.path.abspath(self.conf_dir), file))
+ if 'jar_argv' in vars(__builtin__):
+ self.load_fido_xml(os.path.join(self.jar_conf_dir, file))
+ else:
+ self.load_fido_xml(os.path.join(os.path.abspath(self.conf_dir), file))
self.current_file = ''
self.current_filesize = 0
self.current_format = None
@@ -1032,10 +1041,13 @@ def list_files(roots, recurse=False):
def main(arglist=None):
# The argparse package was introduced in 2.7
t0 = time.clock()
- from argparselocal import ArgumentParser
+ from argparselocal import ArgumentParser
if arglist == None:
- arglist = sys.argv[1:]
-
+ # jar_argv is only present when jarred
+ if 'jar_argv' in vars(__builtin__):
+ arglist = jar_argv
+ else:
+ arglist = sys.argv[1:]
parser = ArgumentParser(description=defaults['description'], epilog=defaults['epilog'], fromfile_prefix_chars='@')
parser.add_argument('-v', default=False, action='store_true', help='show version information')
parser.add_argument('-q', default=False, action='store_true', help='run (more) quietly')
@@ -1077,11 +1089,11 @@ def main(arglist=None):
if args.v :
print "fido/" + version
- exit(0)
+ sys.exit(0)
if args.show == 'defaults':
for (k, v) in defaults.iteritems():
print k, '=', repr(v)
- exit(0)
+ sys.exit(0)
if args.matchprintf != None:
args.matchprintf = args.matchprintf.decode('string_escape')
if args.nomatchprintf != None:
@@ -1105,12 +1117,12 @@ def main(arglist=None):
if args.show == 'useformats':
for format in fido.formats:
print ET.tostring(format, encoding='UTF-8')
- exit(0)
+ sys.exit(0)
# Test the format signature set
if args.checkformats:
fido.check_formats();
- exit(0)
+ sys.exit(0)
# Set up to use stdin, or open input files:
if args.input == '-':
@@ -1123,7 +1135,7 @@ def main(arglist=None):
if (not args.input) and len(args.files) == 1 and args.files[0] == '-':
if fido.zip == True:
raise RuntimeError("Multiple content read from stdin not yet supported.")
- exit(1)
+ sys.exit(1)
fido.identify_multi_object_stream(sys.stdin)
else:
fido.identify_stream(sys.stdin)
@@ -1134,12 +1146,12 @@ def main(arglist=None):
# MdR: this seems to be broken?
msg = "FIDO: Interrupt during:\n File: {0}\n Format: Puid={1.Identifier} [{1.FormatName}]\n Sig: ID={2.SignatureID} [{2.SignatureName}]\n Pat={3.ByteSequenceID} {3.regexstring!r}"
print >> sys.stderr, msg.format(fido.current_file, fido.current_format, fido.current_sig, fido.current_pat)
- exit(1)
+ sys.exit(1)
if not args.q:
sys.stdout.flush()
fido.print_summary(time.clock() - t0)
-if __name__ == '__main__':
+# 'jar_argv' is in vars(__builtin__) when jarred
+if __name__ == '__main__' or 'jar_argv' in vars(__builtin__):
main()
-
View
@@ -1,24 +1,24 @@
-#!/bin/env -e python
-from distutils.core import setup
-import fido.fido
-
-setup(name='fido',
- version=fido.fido.version,
- scripts=['fido/fido.bat', 'fido/fido.sh'],
- url="http://github.com/openplanets/fido",
- packages=['fido'],
- #package_dir={'fido':'fido'},
- package_data={'fido':['conf/formats.xml', 'conf/format_extensions.xml']},
- #py_modules=['fido.fido','fido.testfido', 'fido.argparselocal'],
- description='Format Identification for Digital Objects (FIDO).',
- author='Adam Farquhar',
- author_email='adam.farquhar@bl.uk',
- license='Apache 2.0 - See License.txt',
- classifiers=[
- "Programming Language :: Python :: 2.7",
- "Development Status :: 4 - Beta",
- "Environment :: Console",
- "Intended Audience :: System Administrators",
- "License :: OSI Approved :: Apache Software License"
- ]
- )
+#!/bin/env -e python
+from distutils.core import setup
+import fido.fido
+
+setup(name='fido',
+ version=fido.fido.version,
+ scripts=['fido/fido.bat', 'fido/fido.sh'],
+ url="http://github.com/openplanets/fido",
+ packages=['fido'],
+ #package_dir={'fido':'fido'},
+ package_data={'fido':['fido/conf/formats.xml', 'fido/conf/format_extensions.xml']},
+ #py_modules=['fido.fido','fido.testfido', 'fido.argparselocal'],
+ description='Format Identification for Digital Objects (FIDO).',
+ author='Adam Farquhar',
+ author_email='adam.farquhar@bl.uk',
+ license='Apache 2.0 - See License.txt',
+ classifiers=[
+ "Programming Language :: Python :: 2.7",
+ "Development Status :: 4 - Beta",
+ "Environment :: Console",
+ "Intended Audience :: System Administrators",
+ "License :: OSI Approved :: Apache Software License"
+ ]
+ )

0 comments on commit d8a7ce6

Please sign in to comment.