use "git ugit" when spawning ugit sessions
[git-cola.git] / ugit / git-ugit
blob4512a2e50753e56733044fdd0ada14a6c2d8141e
1 #!/usr/bin/env python
2 # Copyright(C) 2007, David Aguilar <davvid@gmail.com>
3 # License: GPL v2 or later
4 import os
5 import sys
6 import optparse
7 from os.path import join
8 from os.path import dirname
9 from os.path import realpath
11 def setup_environment():
12 """Prepends sys.path with ugit's module path."""
13 # ex: sys.path = [ ..., /usr/share ]
14 # from ugit import git
15 # implies: git = /usr/share/ugit/git.py
16 ugit = realpath(sys.argv[0])
17 bin = dirname(ugit)
18 prefix = dirname(bin)
19 share = join(prefix,'share')
20 sys.path.insert(0, share)
22 def main():
23 # cmdline
24 parser = optparse.OptionParser(
25 usage='%prog /repo/path-1 ... /repo/path-N*\n\n'
26 +'*the current directory is used when no '
27 +'paths are specified.''')
28 parser.add_option('-v', '--version',
29 help='Show ugit version',
30 dest='version',
31 default=False,
32 action='store_true')
33 opts, args = parser.parse_args()
35 # allow "git ugit /path/to/repo"
36 if args:
37 os.chdir(os.path.realpath(args[0]))
39 # This sets up sys.path so that the ugit modules can be found.
40 setup_environment()
42 if opts.version:
43 from ugit.version import VERSION
44 print "ugit version", VERSION
45 sys.exit(0)
47 # allow "git ugit /repo/path-1 .. /repo/path-N
48 from ugit.models import Model
49 from ugit import utils
50 from ugit.views import View
51 from ugit.controllers import Controller
53 if args[1:]:
54 for repo in [ os.path.realpath(r) for r in args[1:] ]:
55 utils.fork("git", "ugit", repo)
57 # load the model right away so that we can bail out if
58 # when no git repo exists
59 model = Model()
62 # qt
63 try:
64 from PyQt4 import QtCore
65 from PyQt4 import QtGui
66 except ImportError:
67 print "Sorry, you do not seem to have PyQt4 installed."
68 print "Please install it before using ugit."
69 print "e.g.: sudo apt-get install python-qt4"
70 sys.exit(-1)
72 app = QtGui.QApplication(sys.argv)
73 app.setWindowIcon(QtGui.QIcon( utils.get_icon('git.png')) )
74 locale = str(QtCore.QLocale().system().name())
75 qmfile = utils.get_qm_for_locale( locale )
76 if os.path.exists(qmfile):
77 translator = QtCore.QTranslator()
78 translator.load(qmfile)
79 app.installTranslator(translator)
80 # simple mvc
81 view = View(app.activeWindow())
82 ctl = Controller(model, view)
83 view.show()
84 sys.exit(app.exec_())
86 if __name__ == "__main__":
87 main()