Ejemplo n.º 1
0
        c.convert(args.varfile)

    if args.cmd == 'varxml':
        from kolekti import variables
        c = variables.OdsToXML(args.base)
        c.convert(args.varfile)


    if args.cmd == 'index':
        from kolekti import searchindex
        ix = searchindex.indexer(args.base)
        ix.indexbase()

    if args.cmd == 'search':
        from kolekti import searchindex
        ix = searchindex.searcher(args.base)
        for res in ix.search(args.query):
            print res

    if args.cmd == 'sync':
        from kolekti import synchro
        sync = synchro.SynchroManager(args.base)
        if args.cmdsync == "status":
            changes = sync.statuses()
            for s,l in changes.iteritems():
                print s,len(l)
                
#                for item in l:
#                    logging.debug("%s : %s"%(item['path'],item['rstatus']))
                                           
            # print 'files to be added:'
Ejemplo n.º 2
0
def main():
    
    metaparser = argparse.ArgumentParser(add_help=False)
    metaparser.add_argument('-C','--config', help="alternative config file", metavar="FILE")
    metaparser.add_argument('-v','--verbose', help="display verbose ouput", action = 'store_true' )
    args, remaining_argv = metaparser.parse_known_args()
    
    config_sections=['server',
                     'publish',
                     ]
    try:
        if args.verbose:
            logging.config.fileConfig('logging-cmd-v.conf')
            logging.debug('verbose output')
        else:
            logging.config.fileConfig('logging-cmd.conf')
            #logging.basicConfig(format='%(message)s', level=logging.INFO)
    except:
        if args.verbose:
            logging.basicConfig(level=logging.DEBUG)
        else:
            logging.basicConfig(level=logging.INFO)

        
    if args.config:
        config = settings(args.config)
    else:
        config = settings()
        
    logger = logging.getLogger(__name__)
        
    # read configuration
    parser = argparse.ArgumentParser(parents=[metaparser],description=__doc__)    
    defaults=config.get("InstallSettings",{})
    
    parser.set_defaults(**defaults)
    
    parser.add_argument('-b','--base', action='store',help="kolekti base path")
    subparsers = parser.add_subparsers(title='kolekti commands')

    # http server 
    # parser_s = subparsers.add_parser('runserver', help="start kolekti server")
    # parser_s.add_argument('host', action='store', default="127.0.0.1:8088",nargs='?')
    # defaults=config.get("server",{})
    # defaults.update({'cmd':'server'})
    # parser_s.set_defaults(**defaults)

    # publish
    parser_draft = subparsers.add_parser('publish', help="assemble, filter and produce documents")
    parser_draft.add_argument('toc', action='store', help="Toc to be published")
    parser_draft.add_argument('-j', '--job', action='store', help="Job to be used, overrides the job associated with the toc")
    parser_draft.add_argument('-l', '--languages', required=True, action='store', help="comma-separated list of languages to publish")
    parser_draft.add_argument('--nocleanup', action='store_true', help="do not remove temporary files after publication")
    defaults=config.get("publish",{})
    defaults.update({'cmd':'publish'})
    parser_draft.set_defaults(**defaults)
    
    # release generation
    parser_release = subparsers.add_parser('make_release', help="create a release")
    parser_release.add_argument('toc', action='store', help="Toc source of the release")
    parser_release.add_argument('name', action='store', help="Name of the release")
    parser_release.add_argument('-l', '--lang', action='store', help="language of sources" )
    parser_release.add_argument('-j', '--job', action='store', help="Job to be used, overrides the job associated with the toc")
    # parser_release.add_argument('release', action='store')
    defaults=config.get("make_release",{})
    defaults.update({'cmd':'make_release'})
    parser_release.set_defaults(**defaults)
    

    # publication d'une release 
    parser_pub = subparsers.add_parser('publish_release', help="publish a release")
    parser_pub.add_argument('name', action='store', help="the release name")
#    parser_pub.add_argument('assembly', action='store')
    parser_pub.add_argument('-l', '--languages', action='store', help="comma-separated list of languages to publish")
    defaults=config.get("publish_release",{})
    defaults.update({'cmd':'publish_release'})
    parser_pub.set_defaults(**defaults)
    
    # perform diagnostics
    parser_diag = subparsers.add_parser('diagnostic', help="diagnostic on project or toc")
    parser_diag.add_argument('-t', '--toc', action='store')
    parser_diag.add_argument('-l', '--lang', action='store')
    defaults=config.get("diagnostic",{})
    defaults.update({'cmd':'diagnostic'})
    parser_diag.set_defaults(**defaults)
    
    # variables file conversion xml->ods 
    parser_varods = subparsers.add_parser('varods', help="convert variables from xml to ods")
    parser_varods.add_argument('odsfile', help="ods file", action='store')
    parser_varods.add_argument('varpath', help="location of variable file in project", action='store')
    parser_varods.add_argument('-l','--lines', help="produces lines-oriented ods", action = 'store_false' )
    defaults=config.get("varods",{})
    defaults.update({'cmd':'varods'})
    parser_varods.set_defaults(**defaults)
    
    # variables file conversion ods->xml 
    parser_varxml = subparsers.add_parser('varxml', help="convert variables from ods to xml")
    parser_varxml.add_argument('odsfile', help="ods file", action='store')
    parser_varxml.add_argument('varpath', help="location of variable file in project", action='store')
    parser_varxml.add_argument('-l','--lines', help="produces xml variable file", action = 'store_false' )
    defaults=config.get("varxml",{})
    defaults.update({'cmd':'varxml'})
    parser_varxml.set_defaults(**defaults)
    
    # build search index  
    parser_idx = subparsers.add_parser('index', help="(re)build search index")
    defaults=config.get("index",{})
    defaults.update({'cmd':'index'})
    parser_idx.set_defaults(**defaults)
    
    # search query  
    parser_search = subparsers.add_parser('search', help="search query")
    parser_search.add_argument('query', action='store')
    defaults=config.get("search",{})
    defaults.update({'cmd':'search'})
    parser_search.set_defaults(**defaults)
    
    # svn synchro  
    parser_sync = subparsers.add_parser('sync', help="synchronize project")
    subparsers_sync = parser_sync.add_subparsers(title='synchro commands')

    # status
    parser_sync_status = subparsers_sync.add_parser('status', help="get synchro status")
    parser_sync_status.set_defaults(cmdsync='status')
    parser_sync_update = subparsers_sync.add_parser('update', help="get synchro update")
    parser_sync_update.set_defaults(cmdsync='update')
    parser_sync_update = subparsers_sync.add_parser('history', help="get history")
    parser_sync_update.set_defaults(cmdsync='history')

    # fixture
    parser_fixture = subparsers.add_parser('fixture', help="fixture")
    parser_fixture.add_argument('number', action='store')
    defaults=config.get("fixture",{})
    defaults.update({'cmd':'fixture'})
    parser_fixture.set_defaults(**defaults)
    
        #parser_sync_status.add_argument('synccmd', action='store')

    defaults=config.get("sync",{})
    defaults.update({'cmd':'sync'})
    parser_sync.set_defaults(**defaults)
 
    args = parser.parse_args()

    # calculate absolute base directory

    basepath = os.path.abspath(args.base)
    rootpath, username, project =  basepath.rsplit('/', 2)
    
    
    
    # if args.cmd == 'server':
    #    host,port = args.host.split(':')
    #    from kolekti.server.wsgi import wsgiclass
    #    from paste import httpserver
    #    wsgi = wsgiclass(basepath)
    #    httpserver.serve(wsgi, host, port)
        
    if args.cmd == 'publish':
        from kolekti import publish
        try:
            langs = args.languages.split(',')
            for lang in langs:
                p = publish.DraftPublisher(rootpath, username, project,  lang = lang, cleanup = not(args.nocleanup))
                toc = p.parse(p.substitute_criteria(args.toc, profile = None))
                if args.job:
                    job = args.job
                else:
                    tocjob = toc.xpath('string(/html:html/html:head/html:meta[@name="kolekti.job"]/@content)', namespaces={'html':'http://www.w3.org/1999/xhtml'})
                    job = "/kolekti/publication-parameters/"+tocjob+'.xml'
                xjob = p.parse(job)
                pubdir = toc.xpath('string(/html:html/html:head/html:meta[@name="kolekti.pubdir"]/@content)', namespaces={'html':'http://www.w3.org/1999/xhtml'})
                print pubdir
                xjob.getroot().set('pubdir',pubdir)
                                   
                for event in p.publish_draft(toc, xjob):
                    if event['event'] == "job":
                        logger.info('Publishing Job %s'%event['label'])
                    if event['event'] == "profile":
                        logger.info(' profile %s'%event['label'])
                    if event['event'] == "result":
                        logger.info('%s complete'%event['script'])
                        for doc in event['docs']:
                            logger.info('[%s] %s'%(doc['type'],doc.get('url','')))

                    if event['event'] == "error":
                        logger.info(' [E] %s\n%s'%(event['msg'], event['stacktrace']) )
                    if event['event'] == "warning":
                        logger.warning(' [W] %s'%(event['msg'],) )
                        logger.debug(' [W] %s'%(event['stacktrace'],) )
            logger.info("Publication complete")
        except:
            logger.exception("Publication ended with errors")

    if args.cmd == 'make_release':
        from kolekti import publish
        try:
            p = publish.Releaser(rootpath, username, project, lang=args.lang)
            toc = p.parse(args.toc)
            if args.job:
                job = args.job
            else:
                tocjob = toc.xpath('string(/html:html/html:head/html:meta[@name="kolekti.job"]/@content)', namespaces={'html':'http://www.w3.org/1999/xhtml'})
                job = "/kolekti/publication-parameters/"+tocjob+'.xml'
            xjob = p.parse(job)
            xjob.getroot().set('pubdir',args.name)
            p.make_release(toc, xjob, release_dir=args.name)
            try:
                import pysvn
                cl = pysvn.Client()
                cl.propset("release_state","sourcelang",os.path.join([basepath,'releases',release_dir,"sources",lang,"assembly",pp[0]['releasedir']+'_asm.html']))
                cl.propset("release_srclang",args.lang,os.path.join([basepath,'releases',release_dir,"sources",lang,"assembly",pp[0]['releasedir']+'_asm.html']))
            except:
                logger.warning('assembly property failed')
                
            
            logger.info("Release sucessful")
        except:
            logger.exception("Release ended with errors")
                    
    if args.cmd == 'publish_release':
        from kolekti import publish
        try:
            release = '/releases/' + args.name
            p = publish.ReleasePublisher(release, rootpath, username, project, langs = args.languages.split(','))

            for event in p.publish_assembly(args.name + "_asm"):
                if event['event'] == "job":
                    logger.info('Publishing Job %s'%event['label'])
                if event['event'] == "profile":
                    logger.info(' profile %s'%event['label'])
                if event['event'] == "result":
                    logger.info('%s complete'%event['script'])
                    for doc in event['docs']:
                        logger.info('[%s] %s'%(doc['type'],doc.get('url','')))

                if event['event'] == "error":
                    logger.info(' [E] %s\n%s'%(event['msg'], event['stacktrace']) )
                if event['event'] == "warning":
                    logger.info(' [W] %s\n%s'%(msg) )

            logger.info("Release publication complete")
        except:

            logger.exception("Release publication ended with errors")
            
    if args.cmd == 'diagnostic':
        from kolekti import diagnostic
        try:
            d = diagnostic.Diagnostic(basepath)
            if args.toc:
                d.diag_toc(args.toc)
            else:
                d.diag_project()
        except:
            logger.exception("Diagnostics failed")
                    
    if args.cmd == 'varods':
        from kolekti import variables
        c = variables.XMLToOds(rootpath, username, project)
        c.convert(args.odsfile, args.varpath)

    if args.cmd == 'varxml':
        from kolekti import variables
        c = variables.OdsToXML(rootpath, username, project)
        c.convert(args.odsfile, args.varpath )


    if args.cmd == 'index':
        from kolekti import searchindex
        ix = searchindex.indexer(rootpath, username, project)
        ix.indexbase()

    if args.cmd == 'search':
        from kolekti import searchindex
        ix = searchindex.searcher(rootpath, username, project)
        for res in ix.search(args.query):
            print res

    if args.cmd == 'sync':
        from kolekti import synchro
        sync = synchro.SynchroManager(rootpath, username, project)
        if args.cmdsync == "status":
            changes = sync.statuses()
            for s,l in changes.iteritems():
                print s,len(l)
                
#                for item in l:
#                    logger.debug("%s : %s"%(item['path'],item['rstatus']))
                                           
            # print 'files to be added:'
            # print changes['added']
            # print 'files to be removed:'
            # print changes['removed']
            # print 'files that have changed:'
            # print changes['changed']
            # print 'files with merge conflicts:'
            # print changes['conflict']
            # print 'unversioned files:'
            # print changes['unversioned']

        if args.cmdsync == "update":
            updates = sync.update()
            print updates

        if args.cmdsync == "history":
            records = sync.history()
            for record in records:
#                print dict(record)
                print int(record.date), record.author, ':'
                print record.message

    if args.cmd == 'fixture':
        from kolekti import fixture
        fix = fixture.fixture(rootpath, username, project)
        fix.apply(args.number)