1 # Copyright(C) 2008, David Aguilar <davvid@gmail.com>
8 from cola
import version
11 parser
= optparse
.OptionParser(usage
='%prog [options]')
13 parser
.add_option('-v', '--version',
14 help='Show cola version',
18 parser
.add_option('-s', '--style',
19 help='Applies an alternate stylesheet. '
20 'The allowed values are: "dark" or a file path.',
22 metavar
='PATH or STYLE',
24 parser
.add_option('-r', '--repo',
25 help='Specifies the path to a git repository.',
29 opts
, args
= parser
.parse_args()
31 if opts
.version
or 'version' in args
:
32 print "cola version", version
.version
35 repo
= os
.path
.realpath(opts
.repo
)
36 if not os
.path
.isdir(repo
):
37 print >> sys
.stderr
, "fatal: '%s' is not a directory. Consider supplying -r <path>.\n" % repo
42 # Defer these imports to allow git cola --version without pyqt installed
43 from PyQt4
import QtCore
44 from PyQt4
import QtGui
46 print >> sys
.stderr
, 'Sorry, you do not seem to have PyQt4 installed.'
47 print >> sys
.stderr
, 'Please install it before using cola.'
48 print >> sys
.stderr
, 'e.g.: sudo apt-get install python-qt4'
50 from cola
import qtutils
52 class ColaApplication(QtGui
.QApplication
):
53 """This makes translation work by throwing out the context."""
54 wrapped
= QtGui
.QApplication
.translate
56 trtxt
= unicode(ColaApplication
.wrapped('', *args
[2:]))
57 if trtxt
[-6:-4] == '@@': # handle @@verb / @@noun
61 app
= ColaApplication(sys
.argv
)
62 QtGui
.QApplication
.translate
= app
.translate
63 app
.setWindowIcon(QtGui
.QIcon(utils
.get_icon('git.png')))
64 locale
= str(QtCore
.QLocale().system().name())
65 qmfile
= utils
.get_qm_for_locale(locale
)
66 if os
.path
.exists(qmfile
):
67 translator
= QtCore
.QTranslator(app
)
68 translator
.load(qmfile
)
69 app
.installTranslator(translator
)
72 # This loads the built-in and user-specified stylesheets.
73 # We allows absolute and relative paths to a stylesheet
74 # by assuming that non-file arguments refer to a built-in style.
75 if os
.path
.isabs(opts
.style
) or os
.path
.isfile(opts
.style
):
78 filename
= utils
.get_stylesheet(opts
.style
)
81 # Automatically register each subdirectory in the style dir
82 # as a Qt resource directory.
83 dirname
= os
.path
.dirname(filename
)
85 resource_paths
.extend(utils
.get_resource_dirs(dirname
))
86 for r
in resource_paths
:
87 basename
= os
.path
.basename(r
)
88 QtCore
.QDir
.setSearchPaths(basename
, [r
])
89 stylesheet
= open(filename
, 'r')
90 style
= stylesheet
.read()
92 app
.setStyleSheet(style
)
94 print >> sys
.stderr
, ("warn: '%s' is not a valid style."
97 from cola
.models
import Model
98 from cola
.views
import View
99 from cola
.controllers
import Controller
102 view
= View(app
.activeWindow())
104 valid
= model
.use_worktree(repo
)
106 gitdir
= qtutils
.opendir_dialog(view
, 'Open Git Repository...', os
.getcwd())
109 valid
= model
.use_worktree(gitdir
)
111 os
.chdir(model
.git
.get_work_tree())
113 ctl
= Controller(model
, view
)
114 sys
.exit(app
.exec_())