logilab/doctools
view mkview.py @ 0:cc367abb080e
forget the past.
forget the past.
| author | root |
|---|---|
| date | Wed, 26 Apr 2006 10:48:09 +0000 |
| parents | |
| children | d0486a1a421d |
line source
1 #!/usr/bin/env python2.2
2 # Copyright (c) 2000-2002 LOGILAB S.A. (Paris, FRANCE).
3 # http://www.logilab.fr/ -- mailto:contact@logilab.fr
4 #
5 # This program is free software; you can redistribute it and/or modify it under
6 # the terms of the GNU General Public License as published by the Free Software
7 # Foundation; either version 2 of the License, or (at your option) any later
8 # version.
9 #
10 # This program is distributed in the hope that it will be useful, but WITHOUT
11 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License along with
15 # this program; if not, write to the Free Software Foundation, Inc.,
16 # 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 """USAGE: mkview [OPTIONS] <input.xml> [output_file.xml]
19 Will create a table in which the project's tasks are listed with all
20 the main informations (duration, cost, resources)
21 If output_file is omitted, it will be automatically generated
23 OPTIONS:
24 --h / -help
25 display this help message and exit.
26 --verbose
27 Will output a lot of messages to stdout.
29 --format=<OUPUT_FORMAT>
30 set output format. Default to docbook.
31 Available formats are docbook, csv, html.
32 Defaults to docbook.
34 --group-class=<group_class>
35 Will process only tasks which match this group-class
36 (This option can be combined with --group-name).
37 --group-name=<group_name>
38 Will process only tasks which match this group-name
39 (This option can be combined with --group-class).
41 --dump-groups=<groups_table.xxx>
42 Creates a table with tasks in rows, classes in columns
43 and the list of class-groups in the table body.
44 --dump-vcg=<file.vcg>
45 Will dump a vcg file which will contain the task dependencies.
46 --dump-tasks=<a_file.xxx>
47 Will dump tasks information. If --group-class and / or --group-name
48 are specified, then only tasks matching these groups will be processed.
49 The file a_file.xml will be used for the output.
51 --resources-columns=(on|off)
52 Add / remove resources columns in the tasks-table.
53 Default is 'off'.
54 """
56 import sys
57 import getopt
59 __revision__ = '$Id: mkview.py,v 1.13 2004-10-31 02:18:06 nico Exp $'
62 def build_filename(base, group_name, group_class):
63 """Returns a filename for the tasks table
64 """
66 table_filename = base
67 if group_name :
68 if group_class :
69 table_filename = "%s_%s_%s" % (base, group_name,group_class)
70 else:
71 table_filename = "%s_%s" % (base,group_name)
72 else:
73 if group_class :
74 table_filename = "%s_%s" % (base,group_class)
76 return table_filename
78 def run(*args):
79 # Long options list
80 l_opt = ['group-class=', 'group-name=', 'format=',
81 'dump-vcg=', 'dump-tasks=',
82 'resources-columns=',
83 'dump-groups=', 'help', 'verbose']
84 try:
85 (optlist,args) = getopt.getopt(args, 'o:hv', l_opt)
86 except getopt.GetoptError, e :
87 print e
88 print __doc__
89 sys.exit(1)
91 group_class = None
92 group_name = None
93 format = "docbook"
94 vcg_filename = None
95 tasks_file = None
96 verbose = 0
97 check_integrity = 0
98 list_ref = 0
99 group_table_name = None
100 resource_cols = False
101 output_file = None
103 ## Browse command line
104 for opt, val in optlist:
106 if opt == '--group-class':
107 group_class = val
108 elif opt == '--group-name':
109 group_name = val
110 elif opt == '--format':
111 format = val
112 if format not in ("docbook","csv","html"):
113 print "[mkview] ERROR : unknown format : ",format
114 sys.exit(1)
115 elif opt == '--dump-vcg':
116 vcg_filename = val
117 elif opt == '--dump-tasks':
118 tasks_file = val
119 elif opt == '--resources-columns':
120 if val == 'on':
121 resource_cols = True
122 else:
123 resource_cols = False
124 elif opt == '--check-integrity':
125 check_integrity = 1
126 elif opt == '--list-references':
127 list_ref = 1
128 elif opt == "--dump-groups":
129 group_table_name = val
130 elif opt in ('--help','-h'):
131 print __doc__
132 sys.exit(0)
133 elif opt in ('--verbose','-v'):
134 verbose = 1
135 else:
136 print __doc__
137 sys.exit(1)
139 # if len(args) == 0 or len(args) > 1:
140 if len(args) < 1 or len(args) > 2:
141 print __doc__
142 sys.exit(1)
144 project_file = args[0]
145 if len(args) == 2:
146 output_file = args[1].split('.')[0]
148 if verbose:
149 print "[mkview] File to parse : ",project_file
152 from logilab.pygantt.lib.readers import ExtProjectXMLReader
153 from logilab.pygantt.lib import writers
154 parser = ExtProjectXMLReader()
155 # Start the parse.
156 if verbose:
157 print "[mkview] starting parse ..."
158 project = parser.fromFile(project_file)
160 from logilab.pygantt.schedule import schedule
161 schedule(project, csp = 0)
162 # project.schedule_reset()
164 if verbose:
165 print "[mkview] parsing done "
168 # Find appropriate writer object
169 dumper = None
170 if output_file is None:
171 table_file_name = build_filename("tasks_table",group_name,group_class)
172 else:
173 table_file_name = output_file
175 if format == "docbook":
176 table_file_name += ".xml"
177 dumper = writers.DocbookDumper(project)
178 elif format == "csv":
179 table_file_name += ".csv"
180 dumper = writers.CsvDumper(project)
181 else:
182 table_file_name += ".html"
183 dumper = writers.HtmlDumper(project)
186 # XXX for tests ...
187 dumper.dump_gantt_xml("fichier_gantt.xml")
190 if tasks_file :
191 if verbose:
192 print "[mkview] generating tasks description file ..."
193 try:
194 dumper.dump(tasks_file, group_name, group_class)
195 # p.dumpDocbook(open(tasks_file,"w"))
196 if verbose:
197 print "[mkview] tasks description file generated"
198 except NotImplementedError, e:
199 print "[mkview] ERROR : ", e
201 ## Task Table
202 if verbose:
203 print "[mkview] generating task informations table ..."
204 try:
205 dumper.dump_task_table(table_file_name, group_name, group_class,
206 resource_cols = resource_cols)
207 if verbose:
208 print "[mkview] task informations table generated (%s)" % \
209 table_file_name
210 except NotImplementedError, e:
211 print "[mkview] ERROR : ", e
213 ## ## Integrity (Class / Group check)
214 ## if check_integrity:
215 ## if verbose: print "[mkview] Checking classes / groups integrity ..."
216 ## project.checkGroupsIntegrity()
217 ## if verbose: print "[mkview] Checking integrity done"
219 ## VCG generation
220 if vcg_filename:
221 if verbose:
222 print "[mkview] generating vcg file"
223 dumper.dump_vcg(vcg_filename)
224 if verbose:
225 print "[mkview] vcg file generated (%s)" % vcg_filename
227 ## ## External Refs
228 ## if list_ref:
229 ## if verbose: print "[mkview] checking all external references"
230 ## ref_dict = project.getExternalReferences()
231 ## for ref, taskid_list in ref_dict.items():
232 ## print ref.encode('iso-8859-1')," : ",taskid_list
234 ## group_table
235 if group_table_name:
236 if verbose:
237 print "[mkview] generating group_table file"
238 try:
239 dumper.dump_group_dependencies(group_table_name)
240 if verbose:
241 print "[mkview] group_table file generated (%s)" \
242 % group_table_name
243 except NotImplementedError, e:
244 print "[mkview] ERROR : ", e
248 if __name__ == '__main__':
249 run(*sys.argv[1:])
