fgdocx  0.2 [master]
FlightGear API Docs
project.py
Go to the documentation of this file.
1 ## @package fgdocs
2 
3 
4 import os
5 import sys
6 import datetime
7 
8 import json
9 import shutil
10 
11 import helpers as h
12 
13 ## Builds a project
15 
16  ## Initialze the project builder from configs
17  # @param mainConf - a config.Config instance
18  # @param projObj - a config.ProjectConfig instance
19  # @param verbose - verbosity of output
20  def __init__(self, mainConf, projname, verbose=1):
21 
22  ## Verbosity 0-4
23  self.V = verbose
24 
25  ## Config object
26  self.main_conf = mainConf
27  self.projname = projname
28 
29 
30 
31  ## ProjectConfig object
32  self.conf = self.main_conf.get_project_config_object(self.projname)
33 
34  def wd(self):
35  return self.conf.work_dir
36 
37  ## Prepare the project, copying files, setting up doxy etc
38  def prepare(self):
39  if self.V > 0:
40  print "\n================================================================================="
41  print "# Processing: %s" % self.conf.proj
42  print "================================================================================="
43 
44  ##===========================================
45  if self.V > 1:
46  print "> Checking if temp/work_dir exists: %s" % self.conf.work_dir
47  if not os.path.exists(self.conf.work_dir):
48  if self.V > 1:
49  print " > creating temp/work_dir path: %s" % self.conf.work_dir
50  os.mkdir(self.conf.work_dir)
51  else:
52  if self.V > 1:
53  print " > path Exists temp/work_dir path: %s" % self.conf.work_dir
54 
55  ##===========================================
56 
57 
58  # nuke and recreate build:
59  if not self.conf.is_main:
60  if self.V > 0:
61  print "> checking build directory exits: %s" % self.conf.build_dir
62  #if os.path.exists(self.conf.build_dir):
63  #if self.V > 1:
64  # print "\t nuking build directory: %s" % self.conf.build_dir
65  #shutil.rmtree(build_dir)
66  #if self.V > 1:
67  # print " > creating build directory: %s" % self.conf.build_dir
68 
69  #os.mkdir(build_dir)
70 
71 
72 
73 
74 
75 
76  ## Copy file
77  # @ see copy_config
78  self.copy_files()
79 
80  #print nav_str
81  #sys.exit(0)
82 
83  #### copy required file
84  if self.V > 0:
85  print "> Copying build files:"
86  for f in ["fg_xstyle.css", "fg_docx_footer.html"]:
87  if self.V > 0:
88  print "> copied: %s" % f
89  shutil.copyfile( self.conf.ETC + f , self.conf.work_dir + f )
90 
91  self.write_header_html()
92 
93  ##############################################
94  ## Create temp doxy string and write to file
95 
96  ## READ default
97  dox_file_contents = self.get_doxy_file()
98 
99  ## Add the extra stuff doxy vars from config
100  if self.V > 0:
101  print "> Checking doxy vars from config.yaml"
102 
103 
104  xover = self.get_doxy_args()
105 
106  ## MAIN project extras
107  if self.conf.is_main:
108  h.write_file(self.conf.work_dir + "projects_index.html", self.get_projects_table_html())
109  h.write_file( self.conf.work_dir + "project_pages.cpp", self.get_projects_pages_cpp())
110 
111  ## Append and override the main settings from here
112  xover.append('PROJECT_NAME="%s"' % self.conf.proj)
113 
114  ## get version no from yaml, or source file
115  self.version = self.get_version()
116 
117  xover.append('PROJECT_NUMBER="%s"' % self.version)
118  xover.append('PROJECT_BRIEF="%s"' % self.conf.title)
119 
120  xover.append('OUTPUT_DIRECTORY=' + self.conf.build_dir )
121  xover.append('HTML_OUTPUT=%s' % "./")
122  xover.append('GENERATE_TAGFILE=' + self.conf.build_dir + self.conf.proj + ".tag")
123  xover.append('HTML_HEADER = fg_docx_header.html')
124  xover.append('HTML_FOOTER = fg_docx_footer.html')
125  xover.append('HTML_EXTRA_STYLESHEET = "fg_xstyle.css"')
126  xover.append('TREEVIEW_WIDTH = 250')
127 
128  #xover.append('CLASS_DIAGRAMS = ')
129  xover.append('HAVE_DOT = ')
130  #xover.append('FILTER_SOURCE_FILES: YES')
131  py_processor = self.conf.ETC + "doxypy.py"
132  #xover.append( 'FILTER_PATTERNS = "*.py=%s"' % py_processor )
133  #xover.append('INPUT_FILTER: "%sdoxypy.py" ' % self.conf.ROOT)
134  xover.append('WARN_LOGFILE = %s' % self.conf.build_dir + "warnings.txt")
135 
136  if self.conf.tags:
137  tag_list = []
138  for t in self.conf.tags:
139  tag_list.append( self.conf.BUILD + t + "/" + t + ".tag=../" + t )
140  xover.append("TAGFILES = %s \n" % " ".join(tag_list) )
141 
142  dox_override = "\n".join(xover)
143 
144  if self.V > 0:
145  print "> Overides for fg-docs output"
146  for oo in xover:
147  print " > " + oo
148 
149  ## make config string and write to file
150  dox_config_str = dox_file_contents + dox_override
151  self.write_temp_doxy(dox_config_str)
152 
153  def get_build_cmd(self):
154  print "\n> Compile: "
155  os.chdir(self.conf.work_dir)
156  if self.V > 0:
157  print " > curdir: %s" % os.path.abspath( os.curdir )
158 
159  dox_cmd = "/usr/local/bin/doxygen ./%s " % self.conf.TEMP_DOXY
160  if self.V > 0:
161  print " > command: %s" % dox_cmd
162  return dox_cmd
163 
164  def post_build(self):
165 
166  if self.V > 0:
167  print "> Copying extra files:"
168  for f in ["logo-23.png", 'favicon.ico']: #, "dynsections.js"]:
169  if self.V > 0:
170  print "> copied: %s" % f
171  shutil.copyfile( self.conf.ETC + f , self.conf.build_dir + f )
172 
173  ## write info json
174  self.write_info_file()
175 
176  print "< Done: %s" % self.conf.proj
177 
178 
179 
180  ## Copies the files and paths in \ref copy_config
181  def copy_files(self):
182  if self.conf.copy:
183  print self.conf.copy
184  for f in self.conf.copy:
185  source = self.conf.ROOT + f
186 
187 
188  if os.path.isdir(source):
189  target = self.conf.work_dir + f
190  if os.path.exists(target):
191  shutil.rmtree(target)
192  shutil.copytree( source, target)
193  else:
194 
195  head, tail = os.path.split(source)
196  target = self.conf.work_dir + tail
197  print " > cp " + source + " >> " + target
198 
199  shutil.copyfile( self.conf.ROOT + f, target)
200 
201  ## Top navigation list
202  # @return str Hmtl nav list
203  def get_navigation(self):
204  nav_str = ""
205  if self.conf.is_main:
206  nav_str += '<li><a href="index.html">Index</a></li>\n'
207  else:
208  nav_str += '<li><a href="../">Index</a></li>\n'
209  link_prefix = "" if self.conf.is_main else "../"
210  for p in self.main_conf.get_projects_index():
211  if not p.is_main:
212  nav_str += '<li><a href="%s%s/">%s</a></li>\n' % (link_prefix, p.proj, p.abbrev)
213 
214  return nav_str
215 
216  def get_repo_link(self):
217  s = ""
218  if not self.conf.is_main:
219  s += '<a target="_blank" class="projectrepos" href="%s">%s</a>\n' % (self.conf.project_page, self.conf.checkout)
220  return s
221 
222  def get_branch(self):
223  return "[%s]" % self.conf.branch
224  if self.conf.is_main:
225  s += '<a href="%s">%s</a>\n' % (self.conf.checkout, self.conf.checkout)
226  return s
227 
228  ## Writes out the html header file
229  def write_header_html(self):
230 
231  template_header = h.read_file( self.conf.ETC + "fg_docx_header.html" )
232  template_header = template_header.replace("___NAV_ITEMS___", self.get_navigation() )
233  template_header = template_header.replace("___REPO_LINK___", self.get_repo_link() )
234  template_header = template_header.replace("___REPO_BRANCH___", self.get_branch() )
235  h.write_file( self.conf.work_dir + "fg_docx_header.html", template_header)
236 
237  ## Return the contents of the doxy file
238  def get_doxy_file(self):
239  if self.V > 0:
240  print "> Checking doxy file"
241 
242  if self.conf.doxy_file:
243  if self.V > 0:
244  doxy_path = self.conf.ROOT + self.conf.doxy_file
245  print " > using %s project doxy file: %s" % (self.conf.proj, doxy_path )
246  dox_contents = h.read_file(doxy_path)
247 
248  else:
249  dox_contents = h.read_file(self.conf.ETC + self.conf.DEFAULT_DOXY)
250  if self.V > 0:
251  print " > using default fg-docs file: etc/%s" % self.conf.DEFAULT_DOXY
252  return dox_contents
253 
254  def get_doxy_args(self):
255 
256  if not self.conf.doxy_args:
257  if self.V > 0:
258  print " > No vars"
259  return []
260 
261  xover = []
262  for dox in self.conf.doxy_args:
263  xover.append(dox )
264  return xover
265 
266 
267 
268  def get_version(self):
269 
270  version = "-na-"
271  if self.conf.version_no:
272  version = self.conf.version_no
273 
274  if self.conf.version_file:
275  version = h.read_file( self.conf.work_dir + self.conf.version_file ).strip()
276  return version
277 
278  ## Write out temp doxy file
279  # @param contents The doxy string
280  def write_temp_doxy(self, contents):
281  #print "CONTENTS", contents[:1000]
282  if os.path.exists( self.conf.temp_doxy_path):
283  os.remove(self.conf.temp_doxy_path)
284  h.write_file( self.conf.temp_doxy_path, contents)
285  if self.V > 0:
286  print "> Wrote temp doy file: %s" % self.conf.temp_doxy_path
287 
288  ## Write out json encoded info file to config.Config.INFO_JSON_FILE
289  def write_info_file(self):
290  dic = dict(color= self.conf.color,
291  version=self.get_version(),
292  title=self.conf.title,
293  project=self.conf.proj,
294  date_updated=datetime.datetime.strftime(datetime.datetime.utcnow(),"%Y-%m-%d %H:%M:%S")
295  )
296  h.write_file(self.conf.json_info_path, json.dumps(dic) )
297 
299  projects = self.main_conf.get_projects_index()
300 
301  l = []
302  for p in projects:
303  l.append( " * \section project_%s %s" % (p.proj, p.title) )
304  l.append( " * - Version: %s" % p.version)
305  l.append( " * - repo: %s" % p.repo)
306  l.append( " * - checkout: %s" % p.checkout)
307  l.append( " *")
308  s = "/**\n * \page Projects Projects\n *\n"
309  s += "\n".join(l)
310  s += "/\n"
311 
312  return s
313 
314  ## Return the html index page. This is included in \ref mainpage
315  # @retval str The table contents
317  s = '<table id="projects_index">\n'
318  s += "<tr>\n"
319  s += "\t<th>Path</th><th>Project</th><th>Version</th><th>Branch</th><th>Updated</th><th>Source</th>"
320  s += "\n</tr>\n"
321  for p in self.main_conf.get_projects_index(load_info=True):
322  if p.is_main == False:
323  s += '\n<tr>\n'
324  s += '\t<td><a class="lnk" href="%s/" style="border-left: 10px solid %s;">' % (p.proj, p.color)
325  s += '%s</a></td>' % (p.proj)
326  s += '\t<td>%s<br><a target="_blank" class="lnkp" href="%s">' % (p.title, p.project_page)
327  s += '%s</a></td>' % p.project_page
328 
329  s += '\n<td>%s</td><td>%s</td><td>%s</td>' % (p.version, p.branch if p.branch else "-", p.date_updated)
330  s += '<td>%s</td>' % (p.checkout)
331  s += '</tr>\n'
332  s += '\n<tr>\n'
333  s += '\t<td><a class="lnk" target="_fgms" href="%s" style="border-left: 10px solid %s;">' % ("http://fgms.freeflightsim.org/", "#C974B4")
334  s += '%s</a></td>' % ("fgms")
335  s += '\t<td>%s<br><a target="_fgms" class="lnkp" href="%s">' % ("Multiplayer Server", "http://fgms.freeflightsim.org/")
336  s += '%s</a></td>' % "http://fgms.freeflightsim.org/"
337 
338  s += '\n<td>%s</td><td>%s</td><td>%s</td>' % ("-", "-", "-")
339  s += '<td>%s</td>' % "-"
340  s += '</tr>\n'
341  s += "</table>"
342  return s
343 
def get_projects_pages_cpp(self)
Definition: project.py:298
def get_projects_table_html(self)
Return the html index page.
Definition: project.py:316
def prepare(self)
Prepare the project, copying files, setting up doxy etc.
Definition: project.py:38
def __init__
Initialze the project builder from configs.
Definition: project.py:20
def write_info_file(self)
Write out json encoded info file to config.Config.INFO_JSON_FILE.
Definition: project.py:289
def write_temp_doxy(self, contents)
Write out temp doxy file.
Definition: project.py:280
def get_doxy_file(self)
Return the contents of the doxy file.
Definition: project.py:238
Builds a project.
Definition: project.py:14
conf
ProjectConfig object.
Definition: project.py:32
version
===========================================
Definition: project.py:115
def write_header_html(self)
Writes out the html header file.
Definition: project.py:229
def copy_files(self)
Copies the files and paths in copy:.
Definition: project.py:181
def get_navigation(self)
Top navigation list.
Definition: project.py:203
main_conf
Config object.
Definition: project.py:26