oops: fixed git reset usage
[ugit.git] / ugit / git-ugit
blob3b5757ea80158afb490c6e8b6e7d16b39231a341
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 platform
7 import optparse
9 def setup_environment():
10 """Prepends sys.path with ugit's module path."""
11 version = platform.python_version()
12 try:
13 thisfile = os.path.realpath(__file__)
14 sys.path.insert(0, os.path.dirname(os.path.dirname(thisfile)))
15 sys.path.insert(0, os.path.join(
16 os.path.dirname(os.path.dirname(thisfile)),
17 'lib', 'python' + version[:3],
18 'site-packages'))
20 ugitmodules = os.path.dirname(thisfile)
21 if ugitmodules not in sys.path:
22 sys.path.insert(0, os.path.dirname(thisfile))
23 except:
24 sys.path.insert(0, os.getcwd())
26 def ugit_main():
27 try:
28 from PyQt4 import QtCore
29 from PyQt4 import QtGui
30 except ImportError:
31 print "Sorry, you do not seem to have PyQt4 installed."
32 print "Please install it before using ugit."
33 print "e.g.: sudo apt-get install python-qt4"
34 sys.exit(-1)
36 parser = optparse.OptionParser(usage='usage: %prog [options]')
37 parser.add_option('-p', '--project',
38 help='Path to a git repository',
39 metavar='PROJECT',
40 dest='project',
41 default=None)
43 parser.add_option('-v', '--version',
44 help='Show ugit version',
45 dest='version',
46 default=False,
47 action='store_true')
48 opts, args = parser.parse_args()
50 if opts.project and os.path.isdir(opts.project):
51 os.chdir(opts.project)
53 # This sets up sys.path so that the ugit modules can be found.
54 setup_environment()
56 from ugit.models import Model
57 from ugit.views import View
58 from ugit.controllers import Controller
59 from ugit import utils
61 if opts.version:
62 from ugit.version import VERSION
63 print "ugit version", VERSION
64 sys.exit(0)
66 app = QtGui.QApplication(sys.argv)
67 app.setWindowIcon(QtGui.QIcon(utils.get_icon('git.png')))
68 locale = str(QtCore.QLocale().system().name())
69 qmfile = utils.get_qm_for_locale(locale)
70 if os.path.exists(qmfile):
71 translator = QtCore.QTranslator()
72 translator.load(qmfile)
73 app.installTranslator(translator)
74 model = Model()
75 view = View(app.activeWindow())
76 ctl = Controller(model, view)
77 view.show()
78 sys.exit(app.exec_())
80 if __name__ == "__main__":
81 ugit_main()