Example #1
0
def main():
    parser = optparse.OptionParser(usage='%prog [options] file-or-directory',
                                   description='builds a Zope 2 import file'
                                               ' from filesystem objects')
    parser.add_option('-o', action='store', dest='output', type='str',
                      help='output filename')
    parser.add_option('-f', action='store', dest='format', type='str',
                      help='output format (xml or zexp);'
                      ' default is autodetected from output filename')
    opts, args = parser.parse_args()
    if args:
        what = args[0]
    else:
        parser.print_help()
        sys.exit()
    ob = z2loader.load_object(what)
    if ob is None:
        sys.exit('cannot load %s' % what)
    format = opts.format
    if opts.output != '-':
        where = file(opts.output, 'wb')
        if not format:
            if opts.output.endswith('.xml'):
                format = 'xml'
            else:
                format = 'zexp'
    else:
        where = sys.stdout
        if not format: format = 'xml'
    export_object(ob, where, format)
Example #2
0
def main():
    parser = optparse.OptionParser(
        usage='%prog [options] directory [object ...]',
        description='renders Zope 2 page templates'
        ' from filesystem objects')
    parser.add_option('-o',
                      action='store',
                      dest='output',
                      type='str',
                      help='output location',
                      default='-')
    parser.add_option('--overwrite',
                      action='store_true',
                      help='overwrite output directory tree?')
    parser.add_option('--debug',
                      action='store_true',
                      help='debug errors (show tracebacks)')
    parser.add_option('--pdb', action='store_true', help='spawn pdb on errors')
    parser.add_option('--serve',
                      action='store_true',
                      help='serve the results over http')
    opts, args = parser.parse_args()
    if len(args) < 1:
        parser.print_help()
        sys.exit()
    what = args.pop(0)
    ob = z2loader.load_object(what)
    if ob is None:
        sys.exit('cannot load %s' % what)
    if opts.pdb:
        opts.debug = True
    try:
        configure()
        if not args and opts.output == '-':
            args = ob.objectIds('Page Template')
        if args:
            for what in args:
                render_object(ob, what, opts.output, raise_errors=opts.debug)
        else:
            if opts.overwrite and os.path.exists(opts.output):
                shutil.rmtree(opts.output)
            render_folder(ob, '', opts.output, raise_errors=opts.debug)
            if opts.serve:
                serve_folder(opts.output)
    except KeyboardInterrupt:
        print
    except Exception, e:
        if opts.pdb:
            print "%s: %s" % (e.__class__.__name__, e)
            import pdb
            pdb.post_mortem(sys.exc_info()[-1])
        else:
            raise
def main():
    parser = optparse.OptionParser(usage='%prog [options] directory [object ...]',
                                   description='renders Zope 2 page templates'
                                               ' from filesystem objects')
    parser.add_option('-o', action='store', dest='output', type='str',
                      help='output location', default='-')
    parser.add_option('--overwrite', action='store_true',
                      help='overwrite output directory tree?')
    parser.add_option('--debug', action='store_true',
                      help='debug errors (show tracebacks)')
    parser.add_option('--pdb', action='store_true',
                      help='spawn pdb on errors')
    parser.add_option('--serve', action='store_true',
                      help='serve the results over http')
    opts, args = parser.parse_args()
    if len(args) < 1:
        parser.print_help()
        sys.exit()
    what = args.pop(0)
    ob = z2loader.load_object(what)
    if ob is None:
        sys.exit('cannot load %s' % what)
    if opts.pdb:
        opts.debug = True
    try:
        configure()
        if not args and opts.output == '-':
            args = ob.objectIds('Page Template')
        if args:
            for what in args:
                render_object(ob, what, opts.output,
                              raise_errors=opts.debug)
        else:
            if opts.overwrite and os.path.exists(opts.output):
                shutil.rmtree(opts.output)
            render_folder(ob, '', opts.output,
                          raise_errors=opts.debug)
            if opts.serve:
                serve_folder(opts.output)
    except KeyboardInterrupt:
        print
    except Exception, e:
        if opts.pdb:
            print "%s: %s" % (e.__class__.__name__, e)
            import pdb; pdb.post_mortem(sys.exc_info()[-1])
        else:
            raise