git-cola v1.9.0
[git-cola.git] / bin / git-dag
blob3c1e29ee19328a31c20be6ed2829e4bc936a8eba
1 #!/usr/bin/env python
2 # -*- python-mode -*-
3 """git-dag: An advanced git DAG visualizer
4 """
6 __copyright__ = """
7 Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012, 2013
8 David Aguilar <davvid@gmail.com> and contributors
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License version 2 as
12 published by the Free Software Foundation.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 """
21 import os
22 import sys
23 from argparse import ArgumentParser
24 from os.path import abspath
25 from os.path import dirname
26 from os.path import realpath
28 def setup_environment():
29 """Provides access to the cola modules"""
30 # Try to detect where it is run from and set prefix and the search path.
31 # It is assumed that the user installed Cola using the --prefix= option
32 prefix = dirname(dirname(realpath(abspath(__file__))))
34 # Look for modules in the source or install trees
35 cola_mod = os.path.join(prefix, 'cola', '__init__.py')
36 if os.path.exists(cola_mod):
37 # Source tree
38 sys.path.insert(1, prefix)
39 else:
40 # Install tree
41 install_lib = os.path.join(prefix, 'share', 'git-cola', 'lib')
42 sys.path.insert(1, install_lib)
43 setup_environment()
46 from cola.app import add_common_arguments
47 from cola.app import application_init
48 from cola.app import application_start
51 def main():
52 args = parse_args()
53 return args.func(args)
56 def parse_args():
57 parser = ArgumentParser()
58 parser.set_defaults(func=dag)
60 add_common_arguments(parser)
61 parser.add_argument('-c', '--count', metavar='<count>',
62 type=int, default=1000,
63 help='number of commits to display')
64 parser.add_argument('args', nargs='*', metavar='<args>',
65 help='git log arguments')
66 return parser.parse_args()
69 def dag(args):
70 context = application_init(args)
71 from cola.widgets.dag import git_dag
72 view = git_dag(context.model, args=args)
73 return application_start(context, view)
76 if __name__ == '__main__':
77 sys.exit(main())