Skip to content

Commit

Permalink
Merge 3cd3fbd into d63a59d
Browse files Browse the repository at this point in the history
  • Loading branch information
peuter committed Sep 11, 2016
2 parents d63a59d + 3cd3fbd commit 3582154
Show file tree
Hide file tree
Showing 31 changed files with 623 additions and 179 deletions.
18 changes: 18 additions & 0 deletions .doc/__init__.py
@@ -0,0 +1,18 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-

# copyright (c) 2010-2016, Christian Mayer and the CometVisu contributers.
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the Free
# Software Foundation; either version 3 of the License, or (at your option)
# any later version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
# more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
31 changes: 31 additions & 0 deletions .doc/commands/__init__.py
@@ -0,0 +1,31 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-

# copyright (c) 2010-2016, Christian Mayer and the CometVisu contributers.
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the Free
# Software Foundation; either version 3 of the License, or (at your option)
# any later version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
# more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
import os
import ConfigParser


class Command(object):

def __init__(self):
self.config = ConfigParser.ConfigParser()
self.config.read(os.path.join('.doc', 'config.ini'))
self.root_dir = os.path.abspath(os.path.join(os.path.realpath(os.path.dirname(__file__)), '..', '..'))

def process_output(self, line):
print(line.rstrip())
103 changes: 103 additions & 0 deletions .doc/commands/doc.py
@@ -0,0 +1,103 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-

# copyright (c) 2010-2016, Christian Mayer and the CometVisu contributers.
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the Free
# Software Foundation; either version 3 of the License, or (at your option)
# any later version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
# more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA

import os
import logging
import sh
import shutil
from argparse import ArgumentParser
from . import Command


class DocGenerator(Command):

def __init__(self):
super(DocGenerator, self).__init__()
self.log = logging.getLogger("doc")
logging.basicConfig(level=logging.INFO, format='%(levelname)s: %(message)s')

def _run(self, language, target_dir, browser, skip_screenshots=True, force=False):

sphinx_build = sh.Command("sphinx-build")

# check if sources exist for this language
section = "manual-%s" % language
target_type = self.config.get(section, "target-type")

source_dir = os.path.join(self.root_dir, self.config.get(section, "source"))
if target_dir is None:
target_dir = os.path.join(self.root_dir, self.config.get(section, "target"))
else:
target_dir = os.path.join(self.root_dir, target_dir)

if not os.path.exists(source_dir):
self.log.error("no sources found for manual (%s) in language '%s'" % (source_dir, language))
exit(1)

if force and os.path.exists(target_dir):
# delete target dir
print("deleting old content in '%s'" % target_dir)
shutil.rmtree(target_dir)

if not os.path.exists(target_dir):
os.makedirs(target_dir)

# first run generates the widget-example configs
sphinx_build("-b", target_type, source_dir, target_dir, _out=self.process_output, _err=self.process_output)

if not skip_screenshots:
grunt = sh.Command("grunt")
# generate the screenshots
grunt("screenshots", "--subDir=manual", "--browserName=%s" % browser, _out=self.process_output, _err=self.process_output)

# 2dn run with access to the generated screenshots
sphinx_build("-b", target_type, source_dir, target_dir, _out=self.process_output, _err=self.process_output)

def run(self, args):
parser = ArgumentParser(usage="%(prog)s - CometVisu documentation generator")

parser.add_argument("--force", "-f", dest="force", action='store_true', help="force existing docs to be overridden")

parser.add_argument("--complete", "-c", dest="complete", action='store_true', help="Complete run: generate docs + screenshots")

parser.add_argument("--language", "-l", dest="language", default="de",
help="Language of documentation (only available for manual)")

parser.add_argument("--target", dest="target",
help="Target dir for generation")

parser.add_argument("--browser", "-b", dest="browser", default="chrome",
help="Browser used for screenshot generation")

parser.add_argument('--doc-type', "-dt", dest="doc", default="manual",
type=str, help='type of documentation to generate (manual, source)', nargs='?')

options = parser.parse_args(args)

if 'doc' not in options or options.doc == "manual":
self._run(options.language, options.target, options.browser, force=options.force, skip_screenshots=not options.complete)
elif options.doc == "source":
grunt = sh.Command("grunt")
if options.target is not None:
grunt("api-doc", "--subDir=jsdoc", "--browserName=%s" % options.browser, "--targetDir=%s" % options.target, _out=self.process_output, _err=self.process_output)
else:
grunt("api-doc", "--subDir=jsdoc", "--browserName=%s" % options.browser, _out=self.process_output, _err=self.process_output)
else:
self.log.error("generation of '%s' documentation is not available" % options.type)
exit(1)
97 changes: 97 additions & 0 deletions .doc/commands/scaffolding.py
@@ -0,0 +1,97 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-

# copyright (c) 2010-2016, Christian Mayer and the CometVisu contributers.
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the Free
# Software Foundation; either version 3 of the License, or (at your option)
# any later version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
# more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA

import os
import logging
from argparse import ArgumentParser
from . import Command


class Scaffolder(Command):

def __init__(self):
super(Scaffolder, self).__init__()
self.log = logging.getLogger("scaffolder")
logging.basicConfig(level=logging.INFO, format='%(levelname)s: %(message)s')

def _run(self, language, widget_name, force=False):
section = "manual-%s" % language
template = os.path.join(self.root_dir, self.config.get(section, "widget-template"))
if not os.path.exists(template):
self.log.error("widget template '%s' language '%s' not found" % (widget_name,language))
exit(1)

widgets = []
for file in os.listdir(os.path.join("src", "structure", "pure")):
if file.endswith(".js") and not file.startswith("_"):
# this is a widget
found_widget = os.path.splitext(file)[0]
if widget_name == "ALL" or widget_name.lower() == found_widget.lower():
widgets.append(found_widget)

if len(widgets) == 0:
self.log.error("widget '%s' does not exist" % widget_name)
exit(1)

if len(widgets) > 1:
# do not allow forced overriding of multiple widgets, too dangerous
force = False

for widget_name in widgets:
print("Generating doc source for '%s' widget in language '%s'" % (widget_name, language))
target = os.path.join(self.root_dir, self.config.get(section, "widgets"), widget_name.lower(), "index.rst")

if force is False and os.path.exists(target):
self.log.error("widget documentation already exists for widget '%s' in language '%s'" % (widget_name, language))
continue

headline = "Das %s Widget" % widget_name
headline_mark = "=" * len(headline)
headline += "\n%s" % headline_mark

with open(template, "r") as f:
source = f.read()
source = source.replace("%%%HEADLINE%%%", headline)
source = source.replace("%%%WIDGET_NAME%%%", widget_name)
source = source.replace("%%%WIDGET_NAME_LOWER%%%", widget_name.lower())

if not os.path.exists(target):
os.makedirs(os.path.dirname(target))

with open(target, "w") as ft:
ft.write(source)

def run(self, args):
parser = ArgumentParser(usage="%(prog)s - CometVisu documentation scaffolder")

parser.add_argument("--force", "-f", dest="force", action='store_true', help="force existing docs to be overridden")

parser.add_argument("--language", "-l", dest="language", default="de",
help="Language the widget docs should be generated for")

parser.add_argument("--widget", "-w", dest="widget",
help="Name of the widget to generate docs for")

options = parser.parse_args(args)

if 'widget' not in options:
self.log.error("please provide a widget name" % options.type)
exit(1)

self._run(options.language, options.widget, force=options.force)
37 changes: 37 additions & 0 deletions .doc/commands/translation.py
@@ -0,0 +1,37 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-

# copyright (c) 2010-2016, Christian Mayer and the CometVisu contributers.
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the Free
# Software Foundation; either version 3 of the License, or (at your option)
# any later version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
# more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA

import logging
import sh
from . import Command

class TranslationHandler(Command):

def __init__(self):
super(TranslationHandler, self).__init__()
self.log = logging.getLogger("doc")
logging.basicConfig(level=logging.INFO, format='%(levelname)s: %(message)s')

def _run(self):
pygettext = sh.Command("pygettext")
pygettext("-d", "messages", "-p", self.config.get("main", "locale"), ".doc/docutils/directives/*.py",
_out=self.process_output, _err=self.process_output)

def run(self):
self._run()
3 changes: 3 additions & 0 deletions .doc/docutils/__init__.py
@@ -1,3 +1,6 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-

# copyright (c) 2010-2016, Christian Mayer and the CometVisu contributers.
#
# This program is free software; you can redistribute it and/or modify it
Expand Down
18 changes: 18 additions & 0 deletions .doc/docutils/directives/__init__.py
@@ -0,0 +1,18 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-

# copyright (c) 2010-2016, Christian Mayer and the CometVisu contributers.
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the Free
# Software Foundation; either version 3 of the License, or (at your option)
# any later version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
# more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
17 changes: 9 additions & 8 deletions .doc/docutils/directives/cometvisu.py
Expand Up @@ -33,14 +33,15 @@

default_ref = re.compile("^index-[0-9]+$")
redirect_map = {}
with open(redirect_file, "r") as f:
for line in f:
if re.match(" \"(.+)\"$", line):
wiki, manual = line[3:-2].strip().split("|")
redirect_map[wiki] = manual
elif "|" in line:
wiki, manual = line.strip().split("|")
redirect_map[wiki] = manual
if os.path.exists(redirect_file):
with open(redirect_file, "r") as f:
for line in f:
if re.match(" \"(.+)\"$", line):
wiki, manual = line[3:-2].strip().split("|")
redirect_map[wiki] = manual
elif "|" in line:
wiki, manual = line.strip().split("|")
redirect_map[wiki] = manual


def process_references(app, doctree, fromdocname):
Expand Down
18 changes: 18 additions & 0 deletions .doc/docutils/directives/helper/__init__.py
@@ -0,0 +1,18 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-

# copyright (c) 2010-2016, Christian Mayer and the CometVisu contributers.
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the Free
# Software Foundation; either version 3 of the License, or (at your option)
# any later version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
# more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
2 changes: 1 addition & 1 deletion .doc/docutils/directives/widget_example.py
Expand Up @@ -194,7 +194,7 @@ def run(self):

for screenshot in settings_node.iter('screenshot'):
shot = {
"name": screenshot.get("name", name + str(shot_index)),
"name": screenshot.get("name", name + str(counters[name] + shot_index)),
"data": []
}
if screenshot.get("clickpath", None):
Expand Down

0 comments on commit 3582154

Please sign in to comment.