views: add a bookmarks view
[git-cola.git] / ugit / git-ugit
blobc9c7864cc0726a48313b3bfde38340ead845884c
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 if args[1:]:
49 for repo in [ os.path.realpath(r) for r in args[1:] ]:
50 from ugit.utils import fork
51 fork( sys.argv[0], repo )
54 from ugit.models import Model
55 from ugit import utils
56 from ugit.views import View
57 from ugit.controllers import Controller
59 # load the model right away so that we can bail out if
60 # when no git repo exists
61 model = Model()
64 # qt
65 try:
66 from PyQt4 import QtCore
67 from PyQt4 import QtGui
68 except ImportError:
69 print "Sorry, you do not seem to have PyQt4 installed."
70 print "Please install it before using ugit."
71 print "e.g.: sudo apt-get install python-qt4"
72 sys.exit(-1)
74 app = QtGui.QApplication(sys.argv)
75 app.setWindowIcon(QtGui.QIcon( utils.get_icon('git.png')) )
76 locale = str(QtCore.QLocale().system().name())
77 qmfile = utils.get_qm_for_locale( locale )
78 if os.path.exists(qmfile):
79 translator = QtCore.QTranslator()
80 translator.load(qmfile)
81 app.installTranslator(translator)
82 # simple mvc
83 view = View(app.activeWindow())
84 ctl = Controller(model, view)
85 view.show()
86 sys.exit(app.exec_())
88 if __name__ == "__main__":
89 main()