Jan Borsodi avatar Jan Borsodi committed 3e37ec3

Fixed commands js and rst-doc to use outl/warnl to output text to user, this fixes the problem with the --quiet option not working for these commands.

Comments (0)

Files changed (3)

 def const_id(field, name=""):
     return dashed_name(field.message and name or field.name, '_').upper()
 
-def generate_service_implementation(service, template_env):
+def generate_service_implementation(ui, service, template_env):
     version = '_'.join(service.options["version"].value.split('.')[:2])
     service_name = dashed_name(service.name, dash="_")
     fname = "%s_%s.js" % (service_name, version)
         ).encode('utf-8')
     res = updateFile(fpath, codecs.BOM_UTF8 + text, mode="wb")
     if res in (WRITE_UPDATED, WRITE_CREATED):
-        print "Wrote service-implementation %s to '%s'" % (service.name, short_fpath)
+        ui.outl("Wrote service-implementation %s to '%s'" % (service.name, short_fpath))
     else:
         javascript.up2date_count += 1
 
         proto=proto,
         )
 
-def generate_services(target, args, out_dir="js-out", js_test_framework=False, console_logger_tutorial=False):
+def generate_services(ui, target, args, out_dir="js-out", js_test_framework=False, console_logger_tutorial=False):
     gen = Generator(subdir="js", lookup_args=dict(default_filters=['decode.utf8']))
     lookup = gen.lookup
     # lookup = TemplateLookup(
         manager = PackageManager()
         package = manager.loadFile(path)
         if not package:
-            print >> sys.stderr, "No protocol buffer definitions found in file %s" % path
+            ui.warnl("No protocol buffer definitions found in file %s" % path)
 
         for service in package.services:  # TODO: Should generate for package instead?
             if "version" not in service.options:
                 raise Exception("Option 'version' is not set on service %s" % service.name)
             service_list.append(service)
             for task in tasks:
-                task(service, template_env)
+                task(ui, service, template_env)
     dependencies = {"Scope": False,
                     "WindowManager": False}
     for service in service_list:
         path = os.path.join(out_dir, short_path)
         res = updateFile(path, codecs.BOM_UTF8 + text.encode('utf-8'), mode="wb")
         if res in (WRITE_UPDATED, WRITE_CREATED):
-            print "Wrote '%s'" % short_path
+            ui.outl("Wrote '%s'" % short_path)
         else:
             javascript.up2date_count += 1
 
             path = os.path.join(out_dir, short_path)
             res = updateFile(path, text, mode="wb")
             if res in (WRITE_UPDATED, WRITE_CREATED):
-                print "Wrote '%s'" % short_path
+                ui.outl("Wrote '%s'" % short_path)
             else:
                 javascript.up2date_count += 1
     sources = [
                     needs_copy = False
         if needs_copy:
             shutil.copy(source_path, out_path)
-            print "Copied %s" % short_source_path
+            ui.outl("Copied %s" % short_source_path)
         else:
             javascript.up2date_count += 1
 
     if javascript.up2date_count > 0:
-        print "%d files was already up-to-date" % javascript.up2date_count
+        ui.outl("%d files was already up-to-date" % javascript.up2date_count)
                                    indent_level=1,
                                    protoHTMLClass=protoHTMLClass))
 
-def generate_rst(target, service_names, out_dir="rst-doc", syntax="scope"):
+def generate_rst(ui, target, service_names, out_dir="rst-doc", syntax="scope"):
     from hob.proto import PackageManager, iterProtoFiles
     rst_doc_service_index = []
     if not os.path.exists(out_dir):
         else:
             package = target.findPackage(path)
         if not package:
-            print >> sys.stderr, "No protocol buffer definitions found in file %s" % path
+            ui.warnl("No protocol buffer definitions found in file %s" % path)
         for service in package.services:
             rst_doc_service_index.append(service)
             gen = RstGenerator(syntax=syntax)
             if not os.path.exists(os.path.dirname(fname)):
                 os.makedirs(os.path.dirname(fname))
             outfile = open(fname, "w").write(text.encode('utf-8'))
-            print "Wrote service %s to '%s'" % (service.name, fname)
+            ui.outl("Wrote service %s to '%s'" % (service.name, fname))
     for service_name, services in service_index.iteritems():
         gen = RstGenerator(syntax=syntax)
         text = gen.serviceindex(service_name, services)
         fname = os.path.join(out_dir, "%s.rst" % service_name)
         outfile = open(fname, "w").write(text.encode('utf-8'))
-        print "Wrote service index %s to '%s'" % (service_name, fname)
+        ui.outl("Wrote service index %s to '%s'" % (service_name, fname))
     If no files are specified all services are added.
     """
     import hob._rst
-    hob._rst.generate_rst(ui.config.currentTarget(), services, out_dir, syntax)
+    hob._rst.generate_rst(ui, ui.config.currentTarget(), services, out_dir, syntax)
 
 @cmds.add(
     [('', 'out_dir', 'js-out',
     e.g. just ecmascript-debugger.
     scope.py and window_manager.py will always be added."""
     import hob._js
-    hob._js.generate_services(ui.config.currentTarget(), services, out_dir, test_framework or js_test_framework, console_logger_tutorial)
+    hob._js.generate_services(ui, ui.config.currentTarget(), services, out_dir, test_framework or js_test_framework, console_logger_tutorial)
 
 def main(args=None):
     try:
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.