fgdocx  0.2 [master]
FlightGear API Docs
config.py
Go to the documentation of this file.
1 ## @namespace fgdocs
2 # @package config
3 # @author Peter Morgan
4 
5 import os
6 import sys
7 import yaml
8 import json
9 from optparse import OptionParser
10 import operator
11 
12 
13 import helpers as h
14 
15 ## The base config class inherited by Config and ProjectConfig
16 # The core class creates class constants such as the project root, temp paths etc
18 
19  ## This project itself
20  SELF_PROJ = "fgdocx"
21 
22  ## Absolute directory path to location of this file with trailing /
23  ROOT = os.path.abspath( os.path.dirname(__file__) + "/../" ) + "/"
24 
25  ## Location of etc/ dir with trailing /
26  ETC = ROOT + "etc/"
27 
28  ## Location of the temp/ directory with trailing /
29  TEMP = ROOT + "temp/"
30 
31  ## Location of the build/ output directory WITH TRAILING /
32  BUILD = "/home/fg/api-docs.freeflightsim.org/"
33 
34  ## Name of the default doxygen file
35  DEFAULT_DOXY = "doxy-default.conf"
36 
37  ## Name of the json encoded
38  INFO_JSON_FILE = "info.json"
39 
40  ## Name of the config file
41  CONFIG_FILE = "projects.config.yaml"
42 
43  TEMP_DOXY = "fg_docs_temp_doxy.conf"
44 
45 
46 ## Project Configuration
47 # This class loads the configuration and settings for a project
49 
50  ## Load project configuration
51  # @param proj The project key
52  # @param dic The project dictionary
53  def __init__(self, proj, dic):
54 
55  ## The project key
56  self.proj = proj
57 
58  ## Whether this is the main/self config
59  # This affect mainly to build target which is not a subdirectory
60  self.is_main = proj == self.SELF_PROJ
61 
62  ## Abbreviation
63  self.abbrev = dic['abbrev']
64 
65 
66  ## Project Title
67  # @see \ref title_config
68  self.title = dic['title']
69 
70  ## Project color - This is output in the index
71  # @see \ref color_config
72  self.color = dic['color'] if 'color' in dic else "#004499"
73 
74  ## The runlevel
75  # @see \ref runlevel_config
76  self.runlevel = int(dic['runlevel'])
77 
78  ## The repo type
79  # @see \ref repo_config
80  self.repo = dic['repo']
81 
82  #print dic.keys()
83  self.project_page = dic['project_page']
84 
85  ## The checkout url
86  # @see \ref checkout_config
87  self.checkout = dic['checkout']
88 
89  ## True is \b repo: is git
90  self.is_git = self.repo == "git"
91 
92  ## True if \b repo: is svn
93  self.is_svn = self.repo == "svn"
94 
95  ## The git branch (defaults to \b master_
96  # @see \ref branch_config
97  self.branch = None
98  if self.is_git:
99  self.branch = dic['branch'] if "branch" in dic else "master"
100 
101  if self.is_main:
102  self.build_dir = self.BUILD
103  else:
104  self.build_dir = self.BUILD + self.proj + "/"
105 
106  self.work_dir = self.TEMP + self.proj + "/"
107 
108 
109  ## Files to copy
110  self.copy = None
111  if 'copy' in dic and len(dic['copy']) > 0:
112  self.copy = []
113  for co in dic['copy']:
114  self.copy.append(co)
115 
116  ## Extra doxy args
117  # @see \ref doxy_args_conf
118  self.doxy_args = None
119  if 'doxy_args' in dic:
120  self.doxy_args = []
121  for dox in dic['doxy_args']:
122  v = dic['doxy_args'][dox]
123  if isinstance(v, bool):
124  v = "YES" if v else "NO"
125  self.doxy_args.append( "%s = %s" % (dox, v) )
126 
127  ## The doxy file to use if present
128  # A project might not have a doxy file
129  self.doxy_file = None
130  if 'doxy_file' in dic:
131  self.doxy_file = dic['doxy_file']
132 
133  ## Whether this is an official upstream repository
134  self.official = None
135 
136  ## Date of last build
137  self.date_updated = None
138 
139  ## The version No
140  # @see \ref version_config
141  self.version_no = None
142  if 'number' in dic['version']:
143  self.version_no = dic['version']['number']
144 
145  ## The version file.
146  # @see \ref version_config
147  self.version_file = None
148  if 'file' in dic['version']:
149  self.version_file = dic['version']['file'].strip()
150 
151  ## Placeholde Version. populated by:
152  self.version = None
153 
154  ## The full path to the temp doxy file
155  self.temp_doxy_path = self.work_dir + self.TEMP_DOXY
156 
157  ## The full path to the json encoded info file config.ConfigCore.INFO_JSON_FILE
158  self.json_info_path = self.BUILD + self.proj + "/" + self.INFO_JSON_FILE
159  if self.is_main:
160  self.json_info_path = self.BUILD + self.INFO_JSON_FILE
161 
162  ## The tag files to include
163  # @see \ref tags_config
164  self.tags = None
165  if 'tags' in dic:
166  self.tags = []
167  parts = dic['tags'].split()
168  for p in parts:
169  self.tags.append(p)
170 
171 
172 
173 
174 ## Load the config file and access as objects
176 
177  ## Load the default config from CONFIG_FILE
178  def __init__(self, verbose=0):
179 
180  self._V = verbose
181  self.raw_yaml_str = h.read_file( self.ETC + self.CONFIG_FILE )
182 
183  self.conf = yaml.load(self.raw_yaml_str)
184  if self._V > 0:
185  print "> Loaded configs: %s" % " ".join( self.conf.keys() )
186 
187 
188  ## Return project details
189  # @param proj the project key
190  # @retval dict Project dictinary or None if project to exist
191  def get_project_dict(self, proj):
192  if not self.has_project(proj):
193  return None
194 
195  dic = self.conf[proj]
196  dic['proj'] = proj
197  return dic
198 
199  ## Return ProjectConfig instance
200  # @param proj the project key
201  # @retval ProjectConfig instance or None
202  def get_project_config_object(self, proj):
203  if not self.has_project(proj):
204  return None
205  projConf = ProjectConfig(proj, self.get_project_dict(proj))
206  return projConf
207 
208  def get_projects_list(self):
209  lst = []
210  for c in self.conf:
211  dic = self.conf[c].copy()
212  dic['proj'] = c
213  lst.append(dic)
214  return lst
215 
216  ## Return the project index
217  def get_projects_index(self, load_info=True, runlevel=False):
218 
219  #if runlevel:
220  # proj_list = self.get_projects_list()
221  # proj_keys = sorted( proj_list, key=lambda k: k['runlevel'])
222  #else:
223  proj_keys = sorted( self.conf.keys() )
224 
225  proj_lst = []
226  for proj in proj_keys:
227  proj = self.get_project_config_object(proj)
228  data = self.load_json_info(proj.json_info_path)
229  if data != None:
230  proj.version = data['version']
231  if 'date_updated' in data:
232  proj.date_updated = data['date_updated']
233  proj_lst.append(proj)
234  return proj_lst
235 
236  ## Loads a json encoded fiel from path
237  # @param file_path to json encoded file
238  # @retval dict of values if file exists and readable, else None
239  def load_json_info(self, file_path):
240  if os.path.exists(file_path):
241  json_str = h.read_file(file_path)
242  dic = json.loads(json_str)
243  return dic
244  return None
245 
246 
247  ## Return is configuration available for project
248  # @param proj the project key
249  # @retval bool True if config exists
250  def has_project(self, proj):
251  return proj in self.conf
252 
253  ## Print the configuration
254  ## @param yaml_str outputs the raw yaml string, otherwise nice
255  def print_view(self, yaml_str=False):
256 
257  if yaml_str:
258  print self.raw_yaml_str
259 
260  else:
261  s = ""
262  for proj in self.projects(runlevel=True):
263  s += proj + "\n"
264  for v in self.conf[proj]:
265  s += " %s: %s\n" % (v, self.conf[proj][v])
266  print s
267 
268 
269 
repo
The repo type.
Definition: config.py:80
copy
Files to copy.
Definition: config.py:110
doxy_args
Extra doxy args.
Definition: config.py:118
def load_json_info(self, file_path)
Loads a json encoded fiel from path.
Definition: config.py:239
string CONFIG_FILE
Name of the config file.
Definition: config.py:41
version
Placeholde Version.
Definition: config.py:152
abbrev
Abbreviation.
Definition: config.py:63
date_updated
Date of last build.
Definition: config.py:137
runlevel
The runlevel.
Definition: config.py:76
branch
The git branch (defaults to master_.
Definition: config.py:97
tags
The tag files to include.
Definition: config.py:164
version_file
The version file.
Definition: config.py:147
json_info_path
The full path to the json encoded info file config.ConfigCore.INFO_JSON_FILE.
Definition: config.py:158
version_no
The version No.
Definition: config.py:141
proj
The project key.
Definition: config.py:56
The base config class inherited by Config and ProjectConfig The core class creates class constants su...
Definition: config.py:17
def __init__
Load the default config from CONFIG_FILE.
Definition: config.py:178
def has_project(self, proj)
Return is configuration available for project.
Definition: config.py:250
is_git
True is repo: is git.
Definition: config.py:90
doxy_file
The doxy file to use if present A project might not have a doxy file.
Definition: config.py:129
temp_doxy_path
The full path to the temp doxy file.
Definition: config.py:155
string SELF_PROJ
This project itself.
Definition: config.py:20
Project Configuration This class loads the configuration and settings for a project.
Definition: config.py:48
color
Project color - This is output in the index.
Definition: config.py:72
string INFO_JSON_FILE
Name of the json encoded.
Definition: config.py:38
is_main
Whether this is the main/self config This affect mainly to build target which is not a subdirectory...
Definition: config.py:60
title
Project Title.
Definition: config.py:68
string TEMP
Location of the temp/ directory with trailing /.
Definition: config.py:29
def get_projects_list(self)
Definition: config.py:208
official
Whether this is an official upstream repository.
Definition: config.py:134
def print_view
Print the configuration.
Definition: config.py:255
is_svn
True if repo: is svn.
Definition: config.py:93
def get_project_dict(self, proj)
Return project details.
Definition: config.py:191
def __init__(self, proj, dic)
Load project configuration.
Definition: config.py:53
def get_projects_index
Return the project index.
Definition: config.py:217
string ETC
Location of etc/ dir with trailing /.
Definition: config.py:26
def get_project_config_object(self, proj)
Return ProjectConfig instance.
Definition: config.py:202
checkout
The checkout url.
Definition: config.py:87
string BUILD
Location of the build/ output directory WITH TRAILING /.
Definition: config.py:32
Load the config file and access as objects.
Definition: config.py:175