本文整理汇总了Python中RequestObject.RequestObject.fromFilename方法的典型用法代码示例。如果您正苦于以下问题:Python RequestObject.fromFilename方法的具体用法?Python RequestObject.fromFilename怎么用?Python RequestObject.fromFilename使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类RequestObject.RequestObject
的用法示例。
在下文中一共展示了RequestObject.fromFilename方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: from RequestObject import RequestObject [as 别名]
# 或者: from RequestObject.RequestObject import fromFilename [as 别名]
def main(argv):
"""Main method that processes the command line, loads the
request object, initializes the factory, and then starts
it up.
"""
# process the command line
shortopts = 'hdqrn:i:'
longopts = ['help','debug', 'quiet', 'threads=', 'input=', 'resume', 'serial', 'mpm', 'spm']
try:
opts, args = getopt.gnu_getopt(argv, shortopts, longopts)
except getopt.GetoptError as err:
print(unicode(err), file=sys.stderr)
print_help()
sys.exit(2)
# check that a filename was not provided
if len(args) != 1: # query_analytic.py, filename
print_help()
sys.exit(2)
# set features according to options
allowZeros = False
numThreads = 1
screenLogging = True
resumeWork = False
printTitles = False
fileStem = 'data'
holdingType = None
agtClass = AnalyticAgent
inputPath = 'hathi_inputs/'
# process the options now
for opt, arg in opts:
if opt == '-h' or opt == '--help':
print_help()
sys.exit(0)
elif opt == '-n' or opt == '--threads':
numThreads = int(arg)
if numThreads < 1:
print(u'The number of threads must be at least 1!',
file=sys.stderr)
sys.exit(2)
elif opt == '-i' or opt == '--input':
inputPath = arg.strip()
# make sure there is a slash at end of path
if inputPath[-1] != '/':
inputPath += '/'
# check directory existence
if not os.path.isdir(inputPath):
print(u'Path: ' + inputPath + u' is not a path / is inaccessible',
file=sys.stderr)
sys.exit(2)
elif opt == '-q' or opt == '--quiet':
screenLogging = False
elif opt == '-r' or opt == '--resume':
resumeWork = True
elif opt == '-d' or opt == '--debug':
printTitles = True
elif opt == '-z' or opt == '--zero':
allowZeros = True
elif opt == '--serial':
holdingType = 'serial'
agtClass = HathiSerialAgent
elif opt == '--spm':
holdingType = 'spm'
agtClass = HathiSPMAgent
elif opt == '--mpm':
holdingType = 'mpm'
agtClass = HathiMPMAgent
# check that only one holding type is given
n = 0
for opt, arg in opts:
if opt in ['--serial', '--spm', '--mpm' ]:
n = n + 1
if n == 0:
print(u'You must include a holding type: --serial, --spm, or --mpm\n',
file=sys.stderr)
print_help()
sys.exit(2)
elif n > 1:
print(u'You can only request one holding type at a time!',
file=sys.stderr)
# set various parameters based on the holding type
fileStem = holdingType
requestFile = inputPath + 'hathi_' + holdingType + 's.txt'
# check that requestFile exists
if not os.path.isfile(requestFile):
print('Unable to read input file: ' + requestFile,
file=sys.stderr)
sys.exit(2)
# attempt to load the request object
try:
request = RequestObject.fromFilename(requestFile,simpleRequest=False)
except Exception as e:
lines = unicode(e).splitlines()
if len(lines) == 1:
#.........这里部分代码省略.........