File: advene-convert

package info (click to toggle)
advene 1.1-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 10,588 kB
  • ctags: 6,326
  • sloc: xml: 56,303; python: 50,385; perl: 741; sh: 186; makefile: 83; ansic: 18
file content (102 lines) | stat: -rwxr-xr-x 3,516 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#! /usr/bin/python
#
# This file is part of Advene.
#
# Advene is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# Advene is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Foobar; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
#

import sys
import os
import StringIO

# Magic stuff before the instanciation of Advene : we set the
# sys.path and the various config.data.path

def fix_paths(path):
  # We override any modification that could have been made in
  # .advenerc. Rationale: if the .advenerc was really correct, it
  # would have set the correct package path in the first place.
  config.data.path['resources']=os.path.sep.join((maindir, 'share'))
  config.data.path['locale']=os.path.sep.join( (maindir, 'locale') )
  config.data.path['web']=os.path.sep.join((maindir, 'share', 'web'))
  config.data.path['advene']=maindir
  config.data.path['plugins']=os.path.sep.join( (maindir, 'vlc') )


# Try to find if we are in a development tree.
(maindir, subdir) = os.path.split(os.path.dirname(os.path.abspath(sys.argv[0])))
if subdir == 'bin' and  os.path.exists(os.sep.join((maindir, "setup.py"))):
  # Chances are that we were in a development tree...
  libpath=os.sep.join((maindir, "lib"))
  print "You seem to have a development tree at:\n%s." % libpath
  sys.path.insert (0, libpath)

  import advene.core.config as config
  fix_paths(maindir)
else:
  try:
    import advene.core.config as config
  except ImportError:
    print """Cannot guess a valid directory.
    Please check your installation or set the PYTHONPATH environment variable."""
    sys.exit(1)

# Maybe we are running from a pyinstaller version
if not os.path.exists(config.data.path['resources']):
  maindir=os.path.abspath(os.path.dirname(sys.executable))
  if os.path.exists(os.path.join( maindir, 'share' )):
    # There is a 'share' directory at the same level as the executable
    # This can mean that we are in a pyinstaller version
    print "Seemingly running from a pyinstaller version in\n%s" % maindir
    fix_paths(maindir)

if config.data.os == 'win32':
  import _winreg

  # Encoding stuff, to please py2exe
  if hasattr(sys, 'setdefaultencoding'):
    import locale
    loc = locale.getdefaultlocale()
    if loc[1]:
      encoding = loc[1]
      sys.setdefaultencoding(encoding)

  #win32 platform, add the "lib" folder to the system path
  os.environ['PATH'] += ";lib;"

import advene.util.importer

if __name__ == '__main__':

    if config.data.args != 2:
        print "Should provide a file name and a package name"
        sys.exit(1)

    fname, pname = config.data.args

    i = advene.util.importer.get_importer(fname)
    if i is None:
        print "No importer for %s" % fname
        sys.exit(1)

    # FIXME: i.process_options()
    # i.process_options(sys.argv[1:])
    # (for .sub conversion for instance, --fps, --offset)
    print "Converting %s to %s using %s..." % (fname, pname, i.name)
    p=i.process_file(fname)
    p.save(pname)
    print "done."
    print i.statistics_formatted()