~domy/corpusfiltergraph/old-main

« back to all changes in this revision

Viewing changes to trunk/lib/corpusfg/corpusfg.py

  • Committer: tahoar
  • Date: 2012-10-26 14:59:20 UTC
  • Revision ID: svn-v4:bc069b21-dff4-4e29-a776-06a4e04bad4e::331
Changes supporting DoMT release

Show diffs side-by-side

added added

removed removed

Lines of Context:
6
6
#===============================================================================
7
7
 
8
8
#version:
9
 
#4.5.319 - bugfix getgraph() to support graphname lists on command line
 
9
#4.5.331 - added --pause command line option
10
10
 
11
11
import sys
12
12
import os
285
285
        cfg['manager']['resetreadonly'] = options.markreadonly if options.markreadonly else cfg['manager']['resetreadonly']
286
286
        cfg['manager']['versions'] = options.versions if options.versions else cfg['manager']['versions']
287
287
 
 
288
def _exit(returncode=0,pause=False):
 
289
        try:
 
290
                while pause:
 
291
                        x = raw_input('Type "Ctrl-C" or "exit" <enter> to continue.\n')
 
292
                        if x.lower().strip() == 'exit': pause = False
 
293
        except KeyboardInterrupt:
 
294
                pass
 
295
        sys.exit(returncode)
 
296
 
288
297
licensetxt=u'''CorpusFiltergraph™ v4.5
289
298
Copyright © 2010-2012 Precision Translation Tools Co., Ltd.
290
299
 
335
344
                optparser.add_option("-r","--run",              action="store_const",   const="run",                    dest="command", default="run",  help="run GRAPH(s), default")
336
345
                optparser.add_option("-s","--stop",             action="store_const",   const="stop",                   dest="command", default="run",  help="stop GRAPH(s)")
337
346
                optparser.add_option("-f","--file",             action="append",                dest="filename",                                                default=[],             help="run input file(s) FILENAME")
 
347
                optparser.add_option("-p","--pause",    action="store_true",    dest="pause",                                                   default=False,  help="pause to review results after all graphs finish")
338
348
                optparser.add_option("-q","--queue",    action="store_true",    dest="queue",                                                   default=False,  help="build file queue and stop")
339
349
                optparser.add_option("-R","--restart",  action="store_true",    dest="restart",                                                 default=False,  help="restart GRAPH(s) from previous queue")
340
350
                optparser.add_option("-m","--mark",             action="store_true",    dest="markreadonly",                                    default=False,  help="mark completed files read-only")
349
359
 
350
360
                if options.license:
351
361
                        sys.stderr.write(licensetxt.encode('utf8')+'\n')
352
 
                        sys.exit(0)
 
362
                        _exit(0,options.pause)
353
363
 
354
364
                defaults = runsetup()
355
365
                if options.setup:
356
366
                        sys.stdout.write("Setup complete.\n")
357
 
                        sys.exit(0)
 
367
                        _exit(0,options.pause)
358
368
 
359
369
                if os.name == 'posix' and  os.geteuid() == 0:
360
370
                        sys.stderr.write(abortmsg)
361
 
                        sys.exit(1)
 
371
                        _exit(1,options.pause)
362
372
 
363
373
                # validate graphnames were requested
364
374
                graphnames = [graphname.strip('\\/,.') for graphname in graphnames]
365
375
 
366
376
                if options.versions:
367
 
                        sys.stderr.write('%s: %s\n'%(os.path.basename(sys.argv[0]),cfgparser.iniFileGet(defaults['setup']['config-setup'],'Do Moses Yourself','version',value='')))
368
 
                        if not graphnames: exit(1)
 
377
                        sys.stderr.write('%s: %s\n'%(os.path.basename(sys.argv[0]),cfgparser.iniFileGet(defaults['setup']['config-setup'],'setup','version',value='')))
 
378
                        if not graphnames: _exit(1,options.pause)
369
379
 
370
380
                if not graphnames:
371
381
                        optparser.error('\"%s\" missing operand: GRAPH1\n'%(os.path.basename(sys.argv[0])))
410
420
                except:
411
421
                        pass
412
422
 
413
 
        sys.exit(result[0])
 
423
        _exit(result[0],options.pause)
 
 
b'\\ No newline at end of file'