Skip to content
Browse files

Merge branch 'doc' of github.com:operasoftware/dragonfly-build-tools …

…into doc
  • Loading branch information...
2 parents b868396 + c0aed8c commit 218341087eba7f40f7bb59ea911c5f4e0d8adb40 @chriskr chriskr committed Sep 17, 2012
Showing with 319 additions and 108 deletions.
  1. +203 −0 LICENSE
  2. +8 −8 df2/codegen/node.py
  3. +1 −1 df2/codegen/protoobjects.py
  4. +62 −59 df2/codegen/scopedoc.py
  5. +45 −40 df2/df2.py
View
203 LICENSE
@@ -0,0 +1,203 @@
+
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright 2008 - 2012 Opera Software ASA
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+
View
16 df2/codegen/node.py
@@ -1,8 +1,8 @@
INDENT = " "
-def escpae_text_html(str): return str.replace("&", "&amp;").replace("<", "&lt;")
+def escape_text_html(str): return str.replace("&", "&amp;").replace("<", "&lt;")
-def escpae_attr_html(str): return str.replace("\"", "&quot;")
+def escape_attr_html(str): return str.replace("\"", "&quot;")
class Node(object):
ELEMENT = 1
@@ -20,7 +20,7 @@ def insert_before(self, node):
def insert_after(self, node):
try: self.next.insert_before(node)
- except: self.parent.append(node)
+ except AttributeError: self.parent.append(node)
return node
@property
@@ -72,7 +72,7 @@ def split(self, pos):
return text
def serialize(self, initial_depth=0):
- return escpae_text_html(self.value)
+ return escape_text_html(self.value)
class Element(Node):
type = Node.ELEMENT
@@ -99,7 +99,7 @@ def normalize(self):
node = self.first_child
text_node = None
while node:
- if node.type == Node.TEXT:
+ if node.is_text:
if text_node:
text_node.value += node.parent.remove(node).value
node = text_node
@@ -130,16 +130,16 @@ def contains_blocklevel(self):
def text_content(self):
text = []
for child in self.children:
- if child.type == Node.TEXT: text.append(child.value)
- elif child.type == Node.ELEMENT: text.append(child.text_content)
+ if child.is_text: text.append(child.value)
+ elif child.is_element: text.append(child.text_content)
return "".join(text)
@text_content.setter
def text_content(self, value):
self.children = [Text(value)]
def serialize(self, initial_depth=0):
- attrs = "".join((" %s=\"%s\"" % (key, escpae_attr_html(value)) for key, value in self.attrs.items()))
+ attrs = "".join((" %s=\"%s\"" % (key, escape_attr_html(value)) for key, value in self.attrs.items()))
content = "".join((child.serialize(initial_depth) for child in self.children))
name = self.name
indent = (initial_depth + self.depth) * INDENT
View
2 df2/codegen/protoobjects.py
@@ -107,7 +107,7 @@ def full_type_name(self):
@property
def default_value(self):
try: return self.options.default.value
- except AttributeError: return ""
+ except AttributeError: return None
class Message(Type, DocLines):
sup_type = MESSAGE
View
121 df2/codegen/scopedoc.py
@@ -12,10 +12,12 @@ def get_timestamp(): return time.strftime("%A, %d %b %Y %H:%M", time.localtime()
INDENT = " "
def indent(count): return count * INDENT
+def join(*args): return "".join(args)
+
def get_field_id(cmd_or_ev_name, recurse_list, field=""):
if field:
- return "%s.%s.%s" % (cmd_or_ev_name, ".".join((m.name for m in recurse_list)), field.name)
- return "%s.%s" % (cmd_or_ev_name, ".".join((m.name for m in recurse_list)))
+ return "%s.%s.%s" % (cmd_or_ev_name, join(*(m.name for m in recurse_list)), field.name)
+ return "%s.%s" % (cmd_or_ev_name, join(*(m.name for m in recurse_list)))
SOURCE_ROOT = os.path.dirname(os.path.abspath(__file__))
CSS_CLASSES = {protoobjects.NUMBER: "number",
@@ -70,53 +72,55 @@ def get_field_id(cmd_or_ev_name, recurse_list, field=""):
</div>
</div>
"""
-SIDEPANLE_LINK = """<li><a href="#%s">%s</a></li>\n"""
-COMMAND = "".join(("<pre class=\"code-line\" id=\"%s\">",
- "<a href=\"#%s\">",
- "<span class=\"keyword\">command</span>",
- " <span class=\"command-name\">%s</span>",
- "(<span class=\"message-name\">%s</span>)",
- "</a>",
- "</pre>"))
-RETURNS = "".join(("<pre class=\"code-line\" id=\"%s\">",
- "<a href=\"#%s\">",
- "<span class=\"keyword\">returns</span>",
- " (<span class=\"message-name\">%s</span>)",
- "</a>",
- "</pre>"))
-KEY = "".join(("<pre class=\"code-line\" id=\"%s\">",
+SIDEPANEL_LINK = """<li><a href="#%s">%s</a></li>\n"""
+COMMAND = join("<pre class=\"code-line\" id=\"%s\">",
+ "<a href=\"#%s\">",
+ "<span class=\"keyword\">command</span>",
+ " <span class=\"command-name\">%s</span>",
+ "(<span class=\"message-name\">%s</span>)",
+ "</a>",
+ "</pre>")
+RETURNS = join("<pre class=\"code-line\" id=\"%s\">",
"<a href=\"#%s\">",
- "<span class=\"proto-key\">= %s;</span>",
+ "<span class=\"keyword\">returns</span>",
+ " (<span class=\"message-name\">%s</span>)",
"</a>",
- "</pre>"))
-EVENT = "".join(("<pre class=\"code-line\" id=\"%s\">",
- "<a href=\"#%s\">",
- "<span class=\"keyword\">event</span>",
- " <span class=\"command-name\">%s</span>",
- "<span class=\"keyword\"> returns </span>",
- "(<span class=\"message-name\">%s</span>)",
- "</a>",
- "</pre>"))
-FIELD = "".join(("<pre class=\"code-line\" id=\"%s\">",
- "%s",
- "<a href=\"#%s\">",
- "<span class=\"qualifier\">%s</span>",
- " <span class=\"%s\">%s</span>",
- " <span class=\"field-name\">%s</span>",
- "<span class=\"proto-key\"> = %s</span>",
- "%s",
- "<span class=\"proto-key\">;</span>",
- "</a>",
- "</pre>"))
-ENUM = "".join(("<pre class=\"code-line\" id=\"%s\">",
- "<a href=\"#%s\">",
- "<span class=\"enum-name\">%s</span>",
- "<span class=\"proto-key\"> = </span>",
- "<span class=\"enum-key\">%s</span>",
- "<span class=\"proto-key\">;</span>",
- "</a>",
- "</pre>"))
+ "</pre>")
+KEY = join("<pre class=\"code-line\" id=\"%s\">",
+ "<a href=\"#%s\">",
+ "<span class=\"proto-key\">= %s;</span>",
+ "</a>",
+ "</pre>")
+EVENT = join("<pre class=\"code-line\" id=\"%s\">",
+ "<a href=\"#%s\">",
+ "<span class=\"keyword\">event</span>",
+ " <span class=\"command-name\">%s</span>",
+ "<span class=\"keyword\"> returns </span>",
+ "(<span class=\"message-name\">%s</span>)",
+ "</a>",
+ "</pre>")
+FIELD = join("<pre class=\"code-line\" id=\"%s\">",
+ "%s",
+ "<a href=\"#%s\">",
+ "<span class=\"qualifier\">%s</span>",
+ " <span class=\"%s\">%s</span>",
+ " <span class=\"field-name\">%s</span>",
+ "<span class=\"proto-key\"> = %s</span>",
+ "%s",
+ "<span class=\"proto-key\">;</span>",
+ "</a>",
+ "</pre>")
+ENUM = join("<pre class=\"code-line\" id=\"%s\">",
+ "<a href=\"#%s\">",
+ "<span class=\"enum-name\">%s</span>",
+ "<span class=\"proto-key\"> = </span>",
+ "<span class=\"enum-key\">%s</span>",
+ "<span class=\"proto-key\">;</span>",
+ "</a>",
+ "</pre>")
EXPANDER = """<span class="expander">&nbsp;</span>"""
+CURLY_OPEN = """<pre class="code-line">{</pre>\n"""
+CURLY_CLOSE = """<pre class="code-line">}</pre>\n"""
class ServiceDoc(object):
def __init__(self, global_scope, protopath, dest):
@@ -141,7 +145,7 @@ def print_doc(fp, obj, depth=0):
def print_enum(fp, cmd_or_ev_name, enum, recurse_list):
fp.write("<div class=\"enum\">\n")
- fp.write("<pre class=\"code-line\">{</pre>\n")
+ fp.write(CURLY_OPEN)
fp.write("<ul>")
if enum.doc:
fp.write("<li class=\"message-doc\">\n")
@@ -154,12 +158,12 @@ def print_enum(fp, cmd_or_ev_name, enum, recurse_list):
print_doc(fp, field)
fp.write("</li>\n")
fp.write("</ul>\n")
- fp.write("<pre class=\"code-line\">}</pre>\n")
+ fp.write(CURLY_CLOSE)
fp.write("</div>")
def print_message(fp, cmd_or_ev_name, msg, depth=0, recurse_list=[]):
fp.write("<div class=\"message\">\n")
- fp.write("<pre class=\"code-line\">{</pre>\n")
+ fp.write(CURLY_OPEN)
fp.write("<ul>")
if msg.doc:
fp.write("<li class=\"message-doc\">\n")
@@ -182,7 +186,7 @@ def print_message(fp, cmd_or_ev_name, msg, depth=0, recurse_list=[]):
print_enum(fp, cmd_or_ev_name, f_type, recurse_list)
fp.write("</li>\n")
fp.write("</ul>\n")
- fp.write("<pre class=\"code-line\">}</pre>\n")
+ fp.write(CURLY_CLOSE)
fp.write("</div>")
def print_command(fp, command):
@@ -214,9 +218,9 @@ def print_service(fp, services, service):
fp.write(H1 % (service.name, service.version))
commands = service.command_names
events = service.event_names
- command_links = (SIDEPANLE_LINK % (cmd, cmd) for cmd in commands)
- event_links = (SIDEPANLE_LINK % (ev, ev) for ev in events)
- fp.write(SIDEPANEL % ("".join(command_links), "".join(event_links)))
+ command_links = (SIDEPANEL_LINK % (cmd, cmd) for cmd in commands)
+ event_links = (SIDEPANEL_LINK % (ev, ev) for ev in events)
+ fp.write(SIDEPANEL % (join(*command_links), join(*event_links)))
fp.write("<div class=\"main-view\">\n")
if service.doc: print_doc(fp, service)
for cmd in commands: print_command(fp, getattr(service, cmd))
@@ -231,11 +235,10 @@ def print_index(fp, services_dict, dest):
latest_versions = []
all_versions = []
for name, versions_dict in services:
- all_versions_list.append(SIDEPANLE_LINK % (name, name))
+ all_versions_list.append(SIDEPANEL_LINK % (name, name))
versions = versions_dict.values()
- versions.sort(key=lambda s: s.service.patch_version, reverse=True)
- versions.sort(key=lambda s: s.service.minor_version, reverse=True)
- versions.sort(key=lambda s: s.service.major_version, reverse=True)
+ for version in ["patch_version", "minor_version", "major_version"]:
+ versions.sort(key=lambda s: getattr(s.service, version), reverse=True)
latest = versions[0]
latest_file_name = "%s.html" % name
latest_versions.append(H2_INDEX % (latest_file_name, name, latest.service.version))
@@ -249,8 +252,8 @@ def print_index(fp, services_dict, dest):
args = version.file_name, version.service.version
all_versions.append(H3_INDEX_ONLY_VERSION % args)
all_versions.append("</ul>\n")
- fp.write(SIDEPANEL_INDEX % ("".join(all_versions_list), get_timestamp()))
- fp.write(MAIN_INDEX % ("".join(latest_versions), "".join(all_versions)))
+ fp.write(SIDEPANEL_INDEX % (join(*all_versions_list), get_timestamp()))
+ fp.write(MAIN_INDEX % (join(*latest_versions), join(*all_versions)))
def get_scope_services(proto_paths, dest):
services = {}
View
85 df2/df2.py
@@ -1,3 +1,9 @@
+# To add a new command import a module which exposes a method
+#
+# def setup_subparser(subparsers, config):
+#
+# All modules will be scanned for such a method.
+
import os
import sys
import argparse
@@ -10,54 +16,53 @@
import showconfig
import build
import cleanrepo
-import codegen.msgdefs as msdefs
-import codegen.jsclasses as jsclasses
-import codegen.scopedoc as scopedoc
+import codegen.msgdefs
+import codegen.jsclasses
+import codegen.scopedoc
SOURCE_ROOT = os.path.dirname(os.path.abspath(__file__))
def deep_update(target, src):
- for key in src.keys():
- if type(src[key]) == type({}):
- if not key in target:
- target[key] = {}
- deep_update(target[key], src[key])
- else:
- target[key] = src[key]
+ for key in src.keys():
+ if type(src[key]) == type({}):
+ if not key in target:
+ target[key] = {}
+ deep_update(target[key], src[key])
+ else:
+ target[key] = src[key]
def get_config():
- config = {}
- with open(os.path.join(SOURCE_ROOT, "DEFAULTS"), "r") as f:
- config.update(json.loads(f.read()))
- home = os.environ.get('HOME') or os.environ.get('HOMEPATH')
- if home:
- for name in ['df2.ini', '.df2', 'DF2', 'df2.cfg']:
- path = os.path.abspath(os.path.join(home, name))
- if os.path.isfile(path):
- with open(path, "r") as f:
- deep_update(config, json.loads(f.read()))
- break
- return config
+ config = {}
+ with open(os.path.join(SOURCE_ROOT, "DEFAULTS"), "r") as f:
+ config.update(json.loads(f.read()))
+ home = os.environ.get('HOME') or os.environ.get('HOMEPATH')
+ if home:
+ for name in ['df2.ini', '.df2', 'DF2', 'df2.cfg']:
+ path = os.path.abspath(os.path.join(home, name))
+ if os.path.isfile(path):
+ with open(path, "r") as f:
+ deep_update(config, json.loads(f.read()))
+ break
+ return config
def main():
- description = """Tool collection to build Opera Dragonfly and handle
- language strings. The tool uses an optional configuration file in the home
- directory ("df2.ini", ".df2", "DF2" or "df2.cfg"). Use 'df2 configdoc'
- to see all options."""
+ description = """Tool collection to build Opera Dragonfly and handle
+ language strings. The tool uses an optional configuration file in the home
+ directory ("df2.ini", ".df2", "DF2" or "df2.cfg"). Use 'df2 configdoc'
+ to see all options."""
- parser = argparse.ArgumentParser(prog='df2', description=description)
- config=get_config()
- #print config.get("build").get("default_profile")
- parser.set_defaults(config=config)
- parser.set_defaults(root_path=SOURCE_ROOT)
- subparsers = parser.add_subparsers()
- g = globals()
- for name in g:
- module = g.get(name)
- if hasattr(module, "setup_subparser"):
- getattr(module, "setup_subparser")(subparsers, config)
- args = parser.parse_args()
- args.func(args)
+ parser = argparse.ArgumentParser(prog='df2', description=description)
+ config=get_config()
+ parser.set_defaults(config=config)
+ parser.set_defaults(root_path=SOURCE_ROOT)
+ subparsers = parser.add_subparsers()
+ candidates = globals().values()
+ candidates.extend((getattr(codegen, name) for name in dir(codegen)))
+ for module in candidates:
+ try: getattr(module, "setup_subparser")(subparsers, config)
+ except AttributeError: pass
+ args = parser.parse_args()
+ args.func(args)
if __name__ == '__main__':
- main()
+ main()

0 comments on commit 2183410

Please sign in to comment.
Something went wrong with that request. Please try again.