~nhomar/pysrttranslator/trunk

« back to all changes in this revision

Viewing changes to pysrttranslator/pysrttranslator.py

  • Committer: Nhomar - Vauxoo
  • Date: 2014-01-05 04:53:52 UTC
  • Revision ID: nhomar@gmail.com-20140105045352-eq6m80wwx4ua28in
[IMP] Working stand alone, added file to test always

Show diffs side-by-side

added added

removed removed

Lines of Context:
51
51
    result = {}
52
52
    scp = parser.SchemaConfigParser(MyAppConfig())
53
53
    scp.read(Application.config.get_config_files(app))
54
 
    #logging.basicConfig(format='%(levelname)s:%(name)s:%(asctime)s %(message)s',
55
 
    #    filename=args.log_file, level=logging.DEBUG)
56
54
    # read the configuration files
57
55
    # support command-line integration
58
56
    op, opts, args = glue.schemaconfigglue(scp)
66
64
        option = scp.schema.section('__main__').option(opt)
67
65
        value = values.get(opt)
68
66
        result[opt] = value
 
67
    if args: 
 
68
        result['input_file'] = args[0]
 
69
        result['output_file'] = len(args)>=2 and args[1] or 'output.srt'
 
70
    else:
 
71
        raise ValueError('You must provide at least the input srt file, see program --help for options')
69
72
    return result
70
73
 
71
74
class MyAppConfig(schema.Schema):
78
81
        ./local.cfg
79
82
    '''
80
83
    input_lang = schema.StringOption(short_name='i', default='en',
81
 
               help='ISO Code for input  lang i.e: "en" for english')
 
84
               help='ISO Code for input file  lang i.e: "en" for english')
82
85
    output_lang = schema.StringOption(short_name='o', default='es',
83
 
               help='ISO Code for output lang i.e: "es" for spanish')
 
86
               help='ISO Code for output file lang i.e: "es" for spanish')
84
87
    log_file = schema.StringOption(short_name='l', default='pysrttranslator.log',
85
88
               help='Set the log file by default in the folder you are running'
86
89
                    'the script you will have a translate.log')
87
90
    google_api_key = schema.StringOption(short_name='A', default=False,
88
91
               help='Set your google api key, read the doc for more information')
89
92
 
90
 
pa = OptionParser()
 
93
pa = OptionParser(usage='%prog input.srt [optional| output.srt] [options]')
91
94
#TODO: This options will be necesary to autocreate the config file on installation process.
92
95
#pa.add_option('-s', '--save-config', help="Generate and save arguments in config file.")
93
96
#pa.add_option('-f', '--input-file', help="Input file to translate ie.: examplesubtitle.srt.")
95
98
app = app.App(MyAppConfig, parser=pa, name='pysrttranslator')
96
99
 
97
100
if __name__ == '__main__':
98
 
    get_options(app)
 
101
    o = get_options(app)
 
102
    logging.basicConfig(format='%(levelname)s:%(name)s:%(asctime)s %(message)s',
 
103
        filename=o['log_file'], level=logging.DEBUG)
 
104
    translate_srt_file(o['input_file'], o['output_file'], o['input_lang'], o['output_lang'])
99
105