|
@@ -48,7 +48,7 @@ if not PY2:
|
|
|
def _get_encoding():
|
|
|
encoding = locale.getdefaultlocale()[1]
|
|
|
if not encoding:
|
|
|
- encoding = 'UTF-8'
|
|
|
+ encoding = "UTF-8"
|
|
|
return encoding
|
|
|
|
|
|
|
|
@@ -67,8 +67,11 @@ def decode(bytes_):
|
|
|
return unicode(bytes_)
|
|
|
|
|
|
|
|
|
-html_page_footer_pages_path = os.getenv('HTML_PAGE_FOOTER_PAGES_PATH') if \
|
|
|
- os.getenv('HTML_PAGE_FOOTER_PAGES_PATH') else ''
|
|
|
+html_page_footer_pages_path = (
|
|
|
+ os.getenv("HTML_PAGE_FOOTER_PAGES_PATH")
|
|
|
+ if os.getenv("HTML_PAGE_FOOTER_PAGES_PATH")
|
|
|
+ else ""
|
|
|
+)
|
|
|
|
|
|
pgm = sys.argv[1]
|
|
|
|
|
@@ -130,7 +133,8 @@ GRASS GIS ${GRASS_VERSION} Reference Manual
|
|
|
</div>
|
|
|
</body>
|
|
|
</html>
|
|
|
-""")
|
|
|
+"""
|
|
|
+)
|
|
|
|
|
|
footer_noindex = string.Template(
|
|
|
"""<hr class="header">
|
|
@@ -150,11 +154,13 @@ GRASS GIS ${GRASS_VERSION} Reference Manual
|
|
|
</div>
|
|
|
</body>
|
|
|
</html>
|
|
|
-""")
|
|
|
+"""
|
|
|
+)
|
|
|
+
|
|
|
|
|
|
def read_file(name):
|
|
|
try:
|
|
|
- f = open(name, 'rb')
|
|
|
+ f = open(name, "rb")
|
|
|
s = f.read()
|
|
|
f.close()
|
|
|
if PY2:
|
|
@@ -171,13 +177,13 @@ def create_toc(src_data):
|
|
|
HTMLParser.__init__(self)
|
|
|
self.reset()
|
|
|
self.idx = 1
|
|
|
- self.tag_curr = ''
|
|
|
- self.tag_last = ''
|
|
|
+ self.tag_curr = ""
|
|
|
+ self.tag_last = ""
|
|
|
self.process_text = False
|
|
|
self.data = []
|
|
|
- self.tags_allowed = ('h1', 'h2', 'h3')
|
|
|
- self.tags_ignored = ('img')
|
|
|
- self.text = ''
|
|
|
+ self.tags_allowed = ("h1", "h2", "h3")
|
|
|
+ self.tags_ignored = "img"
|
|
|
+ self.text = ""
|
|
|
|
|
|
def handle_starttag(self, tag, attrs):
|
|
|
if tag in self.tags_allowed:
|
|
@@ -187,11 +193,10 @@ def create_toc(src_data):
|
|
|
|
|
|
def handle_endtag(self, tag):
|
|
|
if tag in self.tags_allowed:
|
|
|
- self.data.append((tag, '%s_%d' % (tag, self.idx),
|
|
|
- self.text))
|
|
|
+ self.data.append((tag, "%s_%d" % (tag, self.idx), self.text))
|
|
|
self.idx += 1
|
|
|
self.process_text = False
|
|
|
- self.text = ''
|
|
|
+ self.text = ""
|
|
|
|
|
|
self.tag_curr = self.tag_last
|
|
|
|
|
@@ -201,7 +206,7 @@ def create_toc(src_data):
|
|
|
if self.tag_curr in self.tags_allowed or self.tag_curr in self.tags_ignored:
|
|
|
self.text += data
|
|
|
else:
|
|
|
- self.text += '<%s>%s</%s>' % (self.tag_curr, data, self.tag_curr)
|
|
|
+ self.text += "<%s>%s</%s>" % (self.tag_curr, data, self.tag_curr)
|
|
|
|
|
|
# instantiate the parser and fed it some HTML
|
|
|
parser = MyHTMLParser()
|
|
@@ -209,15 +214,17 @@ def create_toc(src_data):
|
|
|
|
|
|
return parser.data
|
|
|
|
|
|
+
|
|
|
def escape_href(label):
|
|
|
# remove html tags
|
|
|
- label = re.sub('<[^<]+?>', '', label)
|
|
|
+ label = re.sub("<[^<]+?>", "", label)
|
|
|
# fix
|
|
|
- label = label.replace(' ', '')
|
|
|
+ label = label.replace(" ", "")
|
|
|
# fix "
|
|
|
- label = label.replace('"', '')
|
|
|
+ label = label.replace('"', "")
|
|
|
# replace space with underscore + lower
|
|
|
- return label.replace(' ', '-').lower()
|
|
|
+ return label.replace(" ", "-").lower()
|
|
|
+
|
|
|
|
|
|
def write_toc(data):
|
|
|
if not data:
|
|
@@ -232,40 +239,49 @@ def write_toc(data):
|
|
|
in_h3 = False
|
|
|
indent = 4
|
|
|
for tag, href, text in data:
|
|
|
- if tag == 'h3' and not in_h3 and has_h2:
|
|
|
- fd.write('\n%s<ul class="toc">\n' % (' ' * indent))
|
|
|
+ if tag == "h3" and not in_h3 and has_h2:
|
|
|
+ fd.write('\n%s<ul class="toc">\n' % (" " * indent))
|
|
|
indent += 4
|
|
|
in_h3 = True
|
|
|
elif not first:
|
|
|
- fd.write('</li>\n')
|
|
|
+ fd.write("</li>\n")
|
|
|
|
|
|
- if tag == 'h2':
|
|
|
+ if tag == "h2":
|
|
|
has_h2 = True
|
|
|
if in_h3:
|
|
|
indent -= 4
|
|
|
- fd.write('%s</ul></li>\n' % (' ' * indent))
|
|
|
+ fd.write("%s</ul></li>\n" % (" " * indent))
|
|
|
in_h3 = False
|
|
|
|
|
|
- text = text.replace(u'\xa0', u' ')
|
|
|
- fd.write('%s<li class="toc"><a href="#%s" class="toc">%s</a>' %
|
|
|
- (' ' * indent, escape_href(text), text))
|
|
|
+ text = text.replace(u"\xa0", u" ")
|
|
|
+ fd.write(
|
|
|
+ '%s<li class="toc"><a href="#%s" class="toc">%s</a>'
|
|
|
+ % (" " * indent, escape_href(text), text)
|
|
|
+ )
|
|
|
first = False
|
|
|
|
|
|
- fd.write('</li>\n</ul>\n')
|
|
|
- fd.write('</div>\n')
|
|
|
+ fd.write("</li>\n</ul>\n")
|
|
|
+ fd.write("</div>\n")
|
|
|
+
|
|
|
|
|
|
def update_toc(data):
|
|
|
ret_data = []
|
|
|
- pat = re.compile(r'(<(h[2|3])>)(.+)(</h[2|3]>)')
|
|
|
+ pat = re.compile(r"(<(h[2|3])>)(.+)(</h[2|3]>)")
|
|
|
idx = 1
|
|
|
for line in data.splitlines():
|
|
|
if pat.search(line):
|
|
|
xline = pat.split(line)
|
|
|
- line = xline[1] + '<a name="%s">' % escape_href(xline[3]) + xline[3] + '</a>' + xline[4]
|
|
|
+ line = (
|
|
|
+ xline[1]
|
|
|
+ + '<a name="%s">' % escape_href(xline[3])
|
|
|
+ + xline[3]
|
|
|
+ + "</a>"
|
|
|
+ + xline[4]
|
|
|
+ )
|
|
|
idx += 1
|
|
|
ret_data.append(line)
|
|
|
|
|
|
- return '\n'.join(ret_data)
|
|
|
+ return "\n".join(ret_data)
|
|
|
|
|
|
|
|
|
def get_addon_path(pgm):
|
|
@@ -275,34 +291,35 @@ def get_addon_path(pgm):
|
|
|
|
|
|
:return tuple: (True, path) if pgm is addon else (None, None)
|
|
|
"""
|
|
|
- addon_base = os.getenv('GRASS_ADDON_BASE')
|
|
|
+ addon_base = os.getenv("GRASS_ADDON_BASE")
|
|
|
if addon_base:
|
|
|
"""'addons_paths.json' is file created during install extension
|
|
|
check get_addons_paths() function in the g.extension.py file
|
|
|
"""
|
|
|
- addons_paths = os.path.join(addon_base, 'addons_paths.json')
|
|
|
+ addons_paths = os.path.join(addon_base, "addons_paths.json")
|
|
|
if os.path.exists(addons_paths):
|
|
|
- with open(addons_paths, 'r') as f:
|
|
|
+ with open(addons_paths, "r") as f:
|
|
|
addons_paths = json.load(f)
|
|
|
- for addon in addons_paths['tree']:
|
|
|
- split_path = addon['path'].split('/')
|
|
|
+ for addon in addons_paths["tree"]:
|
|
|
+ split_path = addon["path"].split("/")
|
|
|
root_dir, module_dir = split_path[0], split_path[-1]
|
|
|
- if 'grass7' == root_dir and pgm == module_dir:
|
|
|
- return True, addon['path']
|
|
|
+ if "grass7" == root_dir and pgm == module_dir:
|
|
|
+ return True, addon["path"]
|
|
|
return None, None
|
|
|
|
|
|
|
|
|
# process header
|
|
|
src_data = read_file(src_file)
|
|
|
-name = re.search('(<!-- meta page name:)(.*)(-->)', src_data, re.IGNORECASE)
|
|
|
+name = re.search("(<!-- meta page name:)(.*)(-->)", src_data, re.IGNORECASE)
|
|
|
pgm_desc = "GRASS GIS Reference Manual"
|
|
|
if name:
|
|
|
- pgm = name.group(2).strip().split('-', 1)[0].strip()
|
|
|
- name_desc = re.search('(<!-- meta page name description:)(.*)(-->)', src_data, re.IGNORECASE)
|
|
|
+ pgm = name.group(2).strip().split("-", 1)[0].strip()
|
|
|
+ name_desc = re.search(
|
|
|
+ "(<!-- meta page name description:)(.*)(-->)", src_data, re.IGNORECASE
|
|
|
+ )
|
|
|
if name_desc:
|
|
|
pgm_desc = name_desc.group(2).strip()
|
|
|
-desc = re.search('(<!-- meta page description:)(.*)(-->)', src_data,
|
|
|
- re.IGNORECASE)
|
|
|
+desc = re.search("(<!-- meta page description:)(.*)(-->)", src_data, re.IGNORECASE)
|
|
|
if desc:
|
|
|
pgm = desc.group(2).strip()
|
|
|
header_tmpl = string.Template(header_base + header_nopgm)
|
|
@@ -312,7 +329,7 @@ else:
|
|
|
else:
|
|
|
header_tmpl = string.Template(header_base + header_pgm_desc)
|
|
|
|
|
|
-if not re.search('<html>', src_data, re.IGNORECASE):
|
|
|
+if not re.search("<html>", src_data, re.IGNORECASE):
|
|
|
tmp_data = read_file(tmp_file)
|
|
|
"""
|
|
|
Adjusting keywords html pages paths if add-on html man page
|
|
@@ -321,12 +338,13 @@ if not re.search('<html>', src_data, re.IGNORECASE):
|
|
|
if html_page_footer_pages_path:
|
|
|
new_keywords_paths = []
|
|
|
orig_keywords_paths = re.search(
|
|
|
- r'<h[1-9]>KEYWORDS</h[1-9]>(.*?)<h[1-9]>',
|
|
|
- tmp_data, re.DOTALL,
|
|
|
+ r"<h[1-9]>KEYWORDS</h[1-9]>(.*?)<h[1-9]>",
|
|
|
+ tmp_data,
|
|
|
+ re.DOTALL,
|
|
|
)
|
|
|
if orig_keywords_paths:
|
|
|
search_txt = 'href="'
|
|
|
- for i in orig_keywords_paths.group(1).split(','):
|
|
|
+ for i in orig_keywords_paths.group(1).split(","):
|
|
|
if search_txt in i:
|
|
|
index = i.index(search_txt) + len(search_txt)
|
|
|
new_keywords_paths.append(
|
|
@@ -335,13 +353,13 @@ if not re.search('<html>', src_data, re.IGNORECASE):
|
|
|
if new_keywords_paths:
|
|
|
tmp_data = tmp_data.replace(
|
|
|
orig_keywords_paths.group(1),
|
|
|
- ','.join(new_keywords_paths),
|
|
|
+ ",".join(new_keywords_paths),
|
|
|
)
|
|
|
- if not re.search('<html>', tmp_data, re.IGNORECASE):
|
|
|
+ if not re.search("<html>", tmp_data, re.IGNORECASE):
|
|
|
sys.stdout.write(header_tmpl.substitute(PGM=pgm, PGM_DESC=pgm_desc))
|
|
|
if tmp_data:
|
|
|
for line in tmp_data.splitlines(True):
|
|
|
- if not re.search('</body>|</html>', line, re.IGNORECASE):
|
|
|
+ if not re.search("</body>|</html>", line, re.IGNORECASE):
|
|
|
sys.stdout.write(line)
|
|
|
|
|
|
# create TOC
|
|
@@ -352,31 +370,31 @@ sys.stdout.write(update_toc(src_data))
|
|
|
|
|
|
# if </html> is found, suppose a complete html is provided.
|
|
|
# otherwise, generate module class reference:
|
|
|
-if re.search('</html>', src_data, re.IGNORECASE):
|
|
|
+if re.search("</html>", src_data, re.IGNORECASE):
|
|
|
sys.exit()
|
|
|
|
|
|
index_names = {
|
|
|
- 'd': 'display',
|
|
|
- 'db': 'database',
|
|
|
- 'g': 'general',
|
|
|
- 'i': 'imagery',
|
|
|
- 'm': 'miscellaneous',
|
|
|
- 'ps': 'postscript',
|
|
|
- 'p': 'paint',
|
|
|
- 'r': 'raster',
|
|
|
- 'r3': 'raster3d',
|
|
|
- 's': 'sites',
|
|
|
- 't': 'temporal',
|
|
|
- 'v': 'vector'
|
|
|
+ "d": "display",
|
|
|
+ "db": "database",
|
|
|
+ "g": "general",
|
|
|
+ "i": "imagery",
|
|
|
+ "m": "miscellaneous",
|
|
|
+ "ps": "postscript",
|
|
|
+ "p": "paint",
|
|
|
+ "r": "raster",
|
|
|
+ "r3": "raster3d",
|
|
|
+ "s": "sites",
|
|
|
+ "t": "temporal",
|
|
|
+ "v": "vector",
|
|
|
}
|
|
|
|
|
|
|
|
|
def to_title(name):
|
|
|
"""Convert name of command class/family to form suitable for title"""
|
|
|
- if name == 'raster3d':
|
|
|
- return '3D raster'
|
|
|
- elif name == 'postscript':
|
|
|
- return 'PostScript'
|
|
|
+ if name == "raster3d":
|
|
|
+ return "3D raster"
|
|
|
+ elif name == "postscript":
|
|
|
+ return "PostScript"
|
|
|
else:
|
|
|
return name.capitalize()
|
|
|
|
|
@@ -386,17 +404,17 @@ for key, name in index_names.items():
|
|
|
index_titles[key] = to_title(name)
|
|
|
|
|
|
# process footer
|
|
|
-index = re.search('(<!-- meta page index:)(.*)(-->)', src_data, re.IGNORECASE)
|
|
|
+index = re.search("(<!-- meta page index:)(.*)(-->)", src_data, re.IGNORECASE)
|
|
|
if index:
|
|
|
index_name = index.group(2).strip()
|
|
|
- if '|' in index_name:
|
|
|
- index_name, index_name_cap = index_name.split('|', 1)
|
|
|
+ if "|" in index_name:
|
|
|
+ index_name, index_name_cap = index_name.split("|", 1)
|
|
|
else:
|
|
|
index_name_cap = to_title(index_name)
|
|
|
else:
|
|
|
- mod_class = pgm.split('.', 1)[0]
|
|
|
- index_name = index_names.get(mod_class, '')
|
|
|
- index_name_cap = index_titles.get(mod_class, '')
|
|
|
+ mod_class = pgm.split(".", 1)[0]
|
|
|
+ index_name = index_names.get(mod_class, "")
|
|
|
+ index_name_cap = index_titles.get(mod_class, "")
|
|
|
|
|
|
grass_version = os.getenv("VERSION_NUMBER", "unknown")
|
|
|
year = os.getenv("VERSION_DATE")
|
|
@@ -408,45 +426,47 @@ topdir = os.path.abspath(os.getenv("MODULE_TOPDIR"))
|
|
|
curdir = os.path.abspath(os.path.curdir)
|
|
|
if curdir.startswith(topdir):
|
|
|
source_url = trunk_url
|
|
|
- pgmdir = curdir.replace(topdir, '').lstrip(os.path.sep)
|
|
|
+ pgmdir = curdir.replace(topdir, "").lstrip(os.path.sep)
|
|
|
else:
|
|
|
# addons
|
|
|
source_url = addons_url
|
|
|
pgmdir = os.path.sep.join(curdir.split(os.path.sep)[-3:])
|
|
|
-url_source = ''
|
|
|
-if os.getenv('SOURCE_URL', ''):
|
|
|
+url_source = ""
|
|
|
+if os.getenv("SOURCE_URL", ""):
|
|
|
# addons
|
|
|
for prefix in index_names.keys():
|
|
|
cwd = os.getcwd()
|
|
|
- idx = cwd.find('{0}{1}.'.format(os.path.sep, prefix))
|
|
|
+ idx = cwd.find("{0}{1}.".format(os.path.sep, prefix))
|
|
|
if idx > -1:
|
|
|
- pgmname = cwd[idx+1:]
|
|
|
+ pgmname = cwd[idx + 1 :]
|
|
|
classname = index_names[prefix]
|
|
|
- url_source = urlparse.urljoin('{0}{1}/'.format(
|
|
|
- os.environ['SOURCE_URL'], classname),
|
|
|
- pgmname
|
|
|
+ url_source = urlparse.urljoin(
|
|
|
+ "{0}{1}/".format(os.environ["SOURCE_URL"], classname), pgmname
|
|
|
)
|
|
|
break
|
|
|
else:
|
|
|
url_source = urlparse.urljoin(source_url, pgmdir)
|
|
|
-if sys.platform == 'win32':
|
|
|
- url_source = url_source.replace(os.path.sep, '/')
|
|
|
+if sys.platform == "win32":
|
|
|
+ url_source = url_source.replace(os.path.sep, "/")
|
|
|
|
|
|
if index_name:
|
|
|
- tree = 'grass/tree'
|
|
|
- commits = 'grass/commits'
|
|
|
+ tree = "grass/tree"
|
|
|
+ commits = "grass/commits"
|
|
|
is_addon, addon_path = get_addon_path(pgm=pgm)
|
|
|
if is_addon:
|
|
|
# Fix gui/wxpython addon url path
|
|
|
url_source = urlparse.urljoin(
|
|
|
- os.environ['SOURCE_URL'], addon_path.split('/', 1)[1],
|
|
|
+ os.environ["SOURCE_URL"],
|
|
|
+ addon_path.split("/", 1)[1],
|
|
|
)
|
|
|
- tree = 'grass-addons/tree'
|
|
|
- commits = 'grass-addons/commits'
|
|
|
+ tree = "grass-addons/tree"
|
|
|
+ commits = "grass-addons/commits"
|
|
|
|
|
|
- sys.stdout.write(sourcecode.substitute(
|
|
|
- URL_SOURCE=url_source, PGM=pgm, URL_LOG=url_source.replace(
|
|
|
- tree, commits)))
|
|
|
+ sys.stdout.write(
|
|
|
+ sourcecode.substitute(
|
|
|
+ URL_SOURCE=url_source, PGM=pgm, URL_LOG=url_source.replace(tree, commits)
|
|
|
+ )
|
|
|
+ )
|
|
|
sys.stdout.write(
|
|
|
footer_index.substitute(
|
|
|
INDEXNAME=index_name,
|