Merge branch 'dag-selection'
[git-cola.git] / bin / git-dag
blobb5c27cb537ff780c6f31c13e39e28c85fd5696f1
1 #!/usr/bin/env python
2 # -*- python-mode -*-
3 """git-dag: An advanced git DAG visualizer
4 """
6 from __future__ import division, absolute_import, unicode_literals
8 __copyright__ = """
9 Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012, 2013
10 David Aguilar <davvid@gmail.com> and contributors
12 This program is free software; you can redistribute it and/or modify
13 it under the terms of the GNU General Public License version 2 as
14 published by the Free Software Foundation.
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
21 """
23 import os
24 import sys
25 from argparse import ArgumentParser
26 from os.path import abspath
27 from os.path import dirname
28 from os.path import join
29 from os.path import realpath
32 def setup_environment():
33 """Provides access to the cola modules"""
34 # Try to detect where it is run from and set prefix and the search path.
35 # It is assumed that the user installed Cola using the --prefix= option
36 python2 = sys.version_info[0] == 2
37 prefix = dirname(dirname(realpath(abspath(__file__))))
38 if python2:
39 cola_mod = join(prefix, str('cola'), str('__init__.py'))
40 install_lib = join(prefix, str('share'), str('git-cola'), str('lib'))
41 else:
42 # Look for modules in the source or install trees
43 cola_mod = os.path.join(prefix, 'cola', '__init__.py')
44 install_lib = os.path.join(prefix, 'share', 'git-cola', 'lib')
46 if os.path.exists(cola_mod):
47 # Source tree
48 sys.path.insert(1, prefix)
49 else:
50 # Install tree
51 sys.path.insert(1, install_lib)
52 setup_environment()
55 from cola.app import add_common_arguments
56 from cola.app import application_init
57 from cola.app import application_start
58 from cola.widgets.dag import git_dag
61 def main():
62 args = parse_args()
63 return args.func(args)
66 def parse_args():
67 parser = ArgumentParser()
68 parser.set_defaults(func=cmd_dag)
70 add_common_arguments(parser)
71 parser.add_argument('-c', '--count', '--max-count', metavar='<count>',
72 type=int, default=1000,
73 help='number of commits to display')
74 parser.add_argument('args', nargs='*', metavar='<args>',
75 help='git log arguments')
76 args, rest = parser.parse_known_args()
77 if rest:
78 # splice unknown arguments to the beginning ~
79 # these are forwarded to git-log(1).
80 args.args[:0] = rest
81 return args
84 def cmd_dag(args):
85 context = application_init(args)
86 view = git_dag(context.model, args=args, settings=args.settings)
87 return application_start(context, view)
90 if __name__ == '__main__':
91 sys.exit(main())