Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Code cleanup.

  • Loading branch information...
commit 625944a5c807f28eaf6aff3f2efebe67cea1f620 1 parent 987cfe4
@chriskr chriskr authored
Showing with 46 additions and 41 deletions.
  1. +1 −1  df2/codegen/protoobjects.py
  2. +45 −40 df2/df2.py
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
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()
Please sign in to comment.
Something went wrong with that request. Please try again.