Imported Upstream version 2.53.3
[platform/upstream/glib.git] / gio / gdbus-2.0 / codegen / codegen_main.py
index 76c838c..0f26f11 100755 (executable)
@@ -7,7 +7,7 @@
 # This library is free software; you can redistribute it and/or
 # modify it under the terms of the GNU Lesser General Public
 # License as published by the Free Software Foundation; either
-# version 2 of the License, or (at your option) any later version.
+# version 2.1 of the License, or (at your option) any later version.
 #
 # This library is distributed in the hope that it will be useful,
 # but WITHOUT ANY WARRANTY; without even the implied warranty of
 # Lesser General Public License for more details.
 #
 # You should have received a copy of the GNU Lesser General
-# Public License along with this library; if not, write to the
-# Free Software Foundation, Inc., 59 Temple Place, Suite 330,
-# Boston, MA 02111-1307, USA.
+# Public License along with this library; if not, see <http://www.gnu.org/licenses/>.
 #
 # Author: David Zeuthen <davidz@redhat.com>
 
 import sys
 import optparse
+from os import path
 
 from . import config
 from . import utils
@@ -56,6 +55,7 @@ def find_prop(iface, prop):
     return None
 
 def apply_annotation(iface_list, iface, method, signal, prop, arg, key, value):
+    iface_obj = None
     for i in iface_list:
         if i.name == iface:
             iface_obj = i
@@ -157,15 +157,19 @@ def codegen_main():
                             help='Generate a GDBusObjectManagerClient subclass when generating C code')
     arg_parser.add_option('', '--generate-c-code', metavar='OUTFILES',
                           help='Generate C code in OUTFILES.[ch]')
+    arg_parser.add_option('', '--c-generate-autocleanup', type='choice', choices=['none', 'objects', 'all'], default='objects',
+                             help='Generate autocleanup support')
     arg_parser.add_option('', '--generate-docbook', metavar='OUTFILES',
                           help='Generate Docbook in OUTFILES-org.Project.IFace.xml')
     arg_parser.add_option('', '--annotate', nargs=3, action='append', metavar='WHAT KEY VALUE',
                           help='Add annotation (may be used several times)')
+    arg_parser.add_option('', '--output-directory', metavar='OUTDIR', default='',
+                          help='Location to output generated files')
     (opts, args) = arg_parser.parse_args();
 
     all_ifaces = []
     for fname in args:
-        f = open(fname)
+        f = open(fname, 'rb')
         xml_data = f.read()
         f.close()
         parsed_ifaces = parser.parse_dbus_xml(xml_data)
@@ -177,22 +181,29 @@ def codegen_main():
     for i in all_ifaces:
         i.post_process(opts.interface_prefix, opts.c_namespace)
 
+    outdir = opts.output_directory
+
     docbook = opts.generate_docbook
-    docbook_gen = codegen_docbook.DocbookCodeGenerator(all_ifaces, docbook);
+    docbook_gen = codegen_docbook.DocbookCodeGenerator(all_ifaces, docbook, outdir);
     if docbook:
         ret = docbook_gen.generate()
 
     c_code = opts.generate_c_code
     if c_code:
-        h = file(c_code + '.h', 'w')
-        c = file(c_code + '.c', 'w')
+        header_name = c_code + '.h'
+        h = open(path.join(outdir, header_name), 'w')
+        c = open(path.join(outdir, c_code + '.c'), 'w')
         gen = codegen.CodeGenerator(all_ifaces,
                                     opts.c_namespace,
                                     opts.interface_prefix,
                                     opts.c_generate_object_manager,
+                                    opts.c_generate_autocleanup,
                                     docbook_gen,
-                                    h, c);
+                                    h, c,
+                                    header_name)
         ret = gen.generate()
+        h.close()
+        c.close()
 
     sys.exit(0)