Exemplo n.º 1
0
def po(args):
    """
    Manage catalog for all knowed languages
    """
    starttime = datetime.datetime.now()
    # Init, load and builds
    root_logger = init_logging(args.loglevel.upper(), logfile=args.logfile)

    # Only load optimus stuff after the settings module name has been retrieved
    os.environ['OPTIMUS_SETTINGS_MODULE'] = args.settings
    from optimus.conf import settings
    from optimus.utils import display_settings

    display_settings(settings, ('DEBUG', 'PROJECT_DIR', 'SOURCES_DIR',
                                'TEMPLATES_DIR', 'LOCALES_DIR'))

    i18n = I18NManager(root_logger, settings)

    # NOTE: Should we do this automatically to prevent error on missing files
    #       OR should we only do checking before and abort on the first missing file ?
    if args.init or args.update or args.compile:
        i18n.init_locales_dir()
        i18n.extract(force=args.update)
        i18n.init_catalogs()

    if args.update:
        i18n.update_catalogs()

    if args.compile:
        i18n.compile_catalogs()

    endtime = datetime.datetime.now()
    root_logger.info('Done in %s', str(endtime - starttime))
Exemplo n.º 2
0
def build(args):
    """
    Build elements for a project
    """
    starttime = datetime.datetime.now()
    # Init, load and builds
    root_logger = init_logging(args.loglevel.upper(), logfile=args.logfile)
    
    # Only load optimus stuff after the settings module name has been retrieved
    os.environ['OPTIMUS_SETTINGS_MODULE'] = args.settings
    from optimus.conf import settings, import_project_module
    from optimus.builder.assets import register_assets
    from optimus.builder.pages import PageBuilder
    from optimus.utils import initialize, display_settings
    
    display_settings(settings, ('DEBUG', 'PROJECT_DIR','SOURCES_DIR','TEMPLATES_DIR','PUBLISH_DIR','STATIC_DIR','STATIC_URL'))
    
    if hasattr(settings, 'PAGES_MAP'):
        root_logger.info('Loading external pages map')
        pages_map = import_project_module(settings.PAGES_MAP)
        setattr(settings, 'PAGES', pages_map.PAGES)

    initialize(settings)
    # Assets
    assets_env = register_assets()
    # Pages
    pages_env = PageBuilder(assets_env=assets_env)
    pages_env.build_bulk(settings.PAGES)
    
    endtime = datetime.datetime.now()
    root_logger.info('Done in %s', str(endtime-starttime))
Exemplo n.º 3
0
def init(args):
    """
    Create a new project from a project template
    """
    starttime = datetime.datetime.now()
    # Init, load and builds
    root_logger = init_logging(args.loglevel.upper(), logfile=args.logfile)
    
    # DEPRECATED
    #if not args.name:
        #root_logger.error("'--name' argument is required")
        #return
    # TODO: Check that the given project name is a valid python module name
    # identifier ::=  (letter|"_") (letter | digit | "_")*
    # So valid that all characters from the name are : "_" character, letters, 
    # digits and does not starts with digits
    
    if args.dry_run:
        root_logger.warning("'Dry run' mode enabled")
    
    # TODO: optionnal command option to specify another path where the project will 
    #       be created
    project_directory = os.path.abspath(os.getcwd())

    loader = ProjectStarter(project_directory, args.name, dry_run=args.dry_run)
    loader.install(args.template)
    
    endtime = datetime.datetime.now()
    root_logger.info('Done in %s', str(endtime-starttime))
Exemplo n.º 4
0
def build(args):
    """
    Build elements for a project
    """
    starttime = datetime.datetime.now()
    # Init, load and builds
    root_logger = init_logging(args.loglevel.upper(), logfile=args.logfile)
    
    # Only load optimus stuff after the settings module name has been retrieved
    os.environ['OPTIMUS_SETTINGS_MODULE'] = args.settings
    from optimus.conf import settings, import_pages_module
    from optimus.builder.assets import register_assets
    from optimus.builder.pages import PageBuilder
    from optimus.utils import initialize, display_settings
    
    display_settings(settings, ('DEBUG', 'PROJECT_DIR','SOURCES_DIR','TEMPLATES_DIR','PUBLISH_DIR','STATIC_DIR','STATIC_URL'))
    
    if hasattr(settings, 'PAGES_MAP'):
        root_logger.info('Loading external pages map')
        pages_map = import_pages_module(settings.PAGES_MAP)
        setattr(settings, 'PAGES', pages_map.PAGES)

    initialize(settings)
    # Assets
    assets_env = register_assets()
    # Pages
    pages_env = PageBuilder(assets_env=assets_env)
    pages_env.build_bulk(settings.PAGES)
    
    endtime = datetime.datetime.now()
    root_logger.info('Done in %s', str(endtime-starttime))
Exemplo n.º 5
0
def init(args):
    """
    Create a new project from a project template
    """
    starttime = datetime.datetime.now()
    # Init, load and builds
    root_logger = init_logging(args.loglevel.upper(), logfile=args.logfile)
    
    # Valid that all characters from the name are : "_" character, letters, 
    # identifier ::=  (letter|"_") (letter | digit | "_")*
    # This is not fully safe, user can create a project name using an installed 
    # Python module that will override it and make some troubles in some case
    if args.name:
        if args.name[0] not in letters:
            root_logger.error("Project name must start with a letter")
            return
        for k in args.name[1:]:
            if k not in letters and k not in digits and k != "_":
                root_logger.error("Project name must only contains letters, digits or '_' character")
                return
    
    if args.dry_run:
        root_logger.warning("'Dry run' mode enabled")
    
    # TODO: optionnal command option to specify another path where the project will 
    #       be created
    project_directory = os.path.abspath(os.getcwd())

    loader = ProjectStarter(project_directory, args.name, dry_run=args.dry_run)
    loader.install(args.template)
    
    endtime = datetime.datetime.now()
    root_logger.info('Done in %s', str(endtime-starttime))
Exemplo n.º 6
0
def po(args):
    """
    Manage catalog for all knowed languages
    """
    starttime = datetime.datetime.now()
    # Init, load and builds
    root_logger = init_logging(args.loglevel.upper(), logfile=args.logfile)
    
    # Only load optimus stuff after the settings module name has been retrieved
    os.environ['OPTIMUS_SETTINGS_MODULE'] = args.settings
    from optimus.conf import settings
    from optimus.utils import display_settings
    
    display_settings(settings, ('DEBUG', 'PROJECT_DIR','SOURCES_DIR','TEMPLATES_DIR','LOCALES_DIR'))
    
    i18n = I18NManager(root_logger, settings)
    
    # NOTE: Should we do this automatically to prevent error on missing files
    #       OR should we only do checking before and abort on the first missing file ?
    if args.init or args.update or args.compile:
        i18n.init_locales_dir()
        i18n.extract(force=args.update)
        i18n.init_catalogs()
    
    if args.update:
        i18n.update_catalogs()
    
    if args.compile:
        i18n.compile_catalogs()
    
    endtime = datetime.datetime.now()
    root_logger.info('Done in %s', str(endtime-starttime))
Exemplo n.º 7
0
def runserver(args):
    """
    Launch the project watcher to automatically re-build knowed elements on changes
    """
    root_logger = init_logging(args.loglevel.upper(), printout=not(args.silent), logfile=args.logfile)
    
    # Only load optimus stuff after the settings module name has been retrieved
    os.environ['OPTIMUS_SETTINGS_MODULE'] = args.settings
    from optimus.conf import settings, import_project_module
    from optimus.utils import display_settings
    
    display_settings(settings, ('DEBUG', 'PROJECT_DIR','PUBLISH_DIR','STATIC_DIR','STATIC_URL'))
    
    # Parse given hostname
    address, port = ("127.0.0.1", "80")
    _splits = args.hostname.split(':')
    if len(_splits)>2:
        raise CommandError("Error: Invalid hostname format, too many ':'")
    elif len(_splits)==2:
        address, port = _splits
        if not port or not address:
            raise CommandError("Error: Invalid hostname format, address or port is empty")
    else:
        port = _splits[0]
    
    try:
        int(port)
    except ValueError:
        raise CommandError("Error: Invalid port given: {0}".format(port))
    
    if not os.path.exists(settings.PUBLISH_DIR):
        raise CommandError("Error: Publish directory does not exist yet, you should build it before")
    
    # Run server with publish directory served with tools.staticdir
    print "Running http server on address {address} with port {port}".format(address=address, port=port)
    
    cherrypy.config.update({
        'server.socket_host': address,
        'server.socket_port': int(port),
        'engine.autoreload_on': False,
    })
    
    conf = {
        '/': {
            'tools.staticdir.index': 'index.html',
            'tools.staticdir.on': True,
            'tools.staticdir.dir': settings.PUBLISH_DIR,
        },
    }
    cherrypy.quickstart(None, '/', config=conf)
Exemplo n.º 8
0
    def runserver(args):
        """
        Launch the project watcher to automatically re-build knowed elements on changes
        """
        root_logger = init_logging(args.loglevel.upper(), printout=not(args.silent), logfile=args.logfile)

        # Only load optimus stuff after the settings module name has been retrieved
        os.environ['OPTIMUS_SETTINGS_MODULE'] = args.settings
        from optimus.conf import settings
        from optimus.utils import display_settings

        display_settings(settings, ('DEBUG', 'PROJECT_DIR','PUBLISH_DIR','STATIC_DIR','STATIC_URL'))

        # Parse given hostname
        address, port = ("127.0.0.1", "80")
        _splits = args.hostname.split(':')
        if len(_splits)>2:
            raise CommandError("Error: Invalid hostname format, too many ':'")
        elif len(_splits)==2:
            address, port = _splits
            if not port or not address:
                raise CommandError("Error: Invalid hostname format, address or port is empty")
        else:
            port = _splits[0]

        try:
            int(port)
        except ValueError:
            raise CommandError("Error: Invalid port given: {0}".format(port))

        if not os.path.exists(settings.PUBLISH_DIR):
            raise CommandError("Error: Publish directory does not exist yet, you should build it before")

        # Run server with publish directory served with tools.staticdir
        print("Running HTTP server on address {address} with port {port}".format(address=address, port=port))

        cherrypy.config.update({
            'server.socket_host': address,
            'server.socket_port': int(port),
            'engine.autoreload_on': False,
        })

        conf = {
            '/': {
                'tools.staticdir.index': 'index.html',
                'tools.staticdir.on': True,
                'tools.staticdir.dir': settings.PUBLISH_DIR,
            },
        }
        cherrypy.quickstart(None, '/', config=conf)
Exemplo n.º 9
0
Arquivo: po.py Projeto: simbha/Optimus
def po(args, init=False, update=False, compile=False):
    """
    Manage catalog for all knowed languages
    """
    starttime = datetime.datetime.now()
    # Init, load and builds
    root_logger = init_logging(args.loglevel.upper(), logfile=args.logfile)
    
    # Only load optimus stuff after the settings module name has been retrieved
    os.environ['OPTIMUS_SETTINGS_MODULE'] = args.settings
    from optimus.conf import settings, import_project_module
    from optimus.utils import display_settings
    
    display_settings(settings, ('DEBUG', 'PROJECT_DIR','SOURCES_DIR','TEMPLATES_DIR','LOCALES_DIR'))
    
    i18n = I18NManager(root_logger, settings)
    
    # TODO: * Copy the actual locale directory to a temporary directory
    #       * If process is success, remove previous backup dir if exists then promote the temp backup dir as the current backup
    #       * If process goes wrong, just remove the temp backup dir
    #       -> Always keeping only one backup dir and allways for a successful process
    if args.backup:
        pass
        
    # NOTE: Should we do this automatically to prevent error on missing files
    #       OR should we only do checking before and abort on the first missing file ?
    if args.init or args.update or args.compile:
        i18n.init_locales_dir()
        i18n.extract(force=args.update)
        i18n.init_catalogs()
    
    if args.update:
        i18n.update_catalogs()
    
    if args.compile:
        i18n.compile_catalogs()
    
    endtime = datetime.datetime.now()
    root_logger.info('Done in %s', str(endtime-starttime))
Exemplo n.º 10
0
def watch(args):
    """
    Launch the project watcher to automatically re-build knowed elements on changes
    """
    root_logger = init_logging(args.loglevel.upper(), printout=not(args.silent), logfile=args.logfile)
    
    # Only load optimus stuff after the settings module name has been retrieved
    os.environ['OPTIMUS_SETTINGS_MODULE'] = args.settings
    from optimus.conf import settings, import_project_module
    from optimus.watchers import TemplatesWatchEventHandler, AssetsWatchEventHandler
    from optimus.builder.assets import register_assets
    from optimus.builder.pages import PageBuilder
    from optimus.utils import initialize, display_settings
    
    display_settings(settings, ('DEBUG', 'PROJECT_DIR','SOURCES_DIR','TEMPLATES_DIR','PUBLISH_DIR','STATIC_DIR','STATIC_URL'))
    
    if hasattr(settings, 'PAGES_MAP'):
        root_logger.info('Loading external pages map')
        pages_map = import_project_module(settings.PAGES_MAP)
        setattr(settings, 'PAGES', pages_map.PAGES)
    
    # Init environments
    assets_env = register_assets()
    pages_env = PageBuilder(assets_env=assets_env)
    
    # add a first build to avoid error on unbuilded project
    if not os.path.exists(settings.PUBLISH_DIR):
        root_logger.info('Seems you never do a first build so do it now')
        pages_env.build_bulk(settings.PAGES)
    
    pages_env.scan_bulk(settings.PAGES)
    
    observer = Observer()
    
    # Templates watcher settings
    watcher_templates_patterns = {
        'patterns': ['*.html'],
        'ignore_patterns': None,
        'ignore_directories': False,
        'case_sensitive': False,
    }
    watcher_templates_patterns.update(settings.WATCHER_TEMPLATES_PATTERNS)
    # Assets watcher settings
    watcher_assets_patterns = {
        'patterns': ['*.css', '*.js', '*.json'],
        'ignore_patterns': None,
        'ignore_directories': False,
        'case_sensitive': False,
    }
    watcher_assets_patterns.update(settings.WATCHER_ASSETS_PATTERNS)
    
    # Init templates and assets event watchers
    templates_event_handler = TemplatesWatchEventHandler(settings, root_logger, assets_env, pages_env, **watcher_templates_patterns)
    if assets_env is not None:
        assets_event_handler = AssetsWatchEventHandler(settings, root_logger, assets_env, pages_env, **watcher_assets_patterns)
    # Registering event watchers and start to watch
    observer.schedule(templates_event_handler, settings.TEMPLATES_DIR, recursive=True)
    if assets_env is not None:
        observer.schedule(assets_event_handler, settings.SOURCES_DIR, recursive=True)
        
    root_logger.warning('Launching the watcher, use CTRL+C to stop it')
    observer.start()
    try:
        while True:
            time.sleep(1)
    except KeyboardInterrupt:
        observer.stop()
    observer.join()
Exemplo n.º 11
0
def watch(args):
    """
    Launch the project watcher to automatically re-build knowed elements on changes
    """
    root_logger = init_logging(args.loglevel.upper(),
                               printout=not (args.silent),
                               logfile=args.logfile)

    # Only load optimus stuff after the settings module name has been retrieved
    os.environ['OPTIMUS_SETTINGS_MODULE'] = args.settings
    from optimus.conf import settings, import_pages_module
    from optimus.watchers import TemplatesWatchEventHandler, AssetsWatchEventHandler
    from optimus.builder.assets import register_assets
    from optimus.builder.pages import PageBuilder
    from optimus.utils import initialize, display_settings

    display_settings(settings,
                     ('DEBUG', 'PROJECT_DIR', 'SOURCES_DIR', 'TEMPLATES_DIR',
                      'PUBLISH_DIR', 'STATIC_DIR', 'STATIC_URL'))

    if hasattr(settings, 'PAGES_MAP'):
        root_logger.info('Loading external pages map')
        pages_map = import_pages_module(settings.PAGES_MAP)
        setattr(settings, 'PAGES', pages_map.PAGES)

    # Init environments
    assets_env = register_assets()
    pages_env = PageBuilder(assets_env=assets_env)

    # add a first build to avoid error on unbuilded project
    if not os.path.exists(settings.PUBLISH_DIR):
        root_logger.info('Seems you never do a first build so do it now')
        pages_env.build_bulk(settings.PAGES)

    pages_env.scan_bulk(settings.PAGES)

    observer = Observer()

    # Templates watcher settings
    watcher_templates_patterns = {
        'patterns': ['*.html'],
        'ignore_patterns': None,
        'ignore_directories': False,
        'case_sensitive': False,
    }
    watcher_templates_patterns.update(settings.WATCHER_TEMPLATES_PATTERNS)
    # Assets watcher settings
    watcher_assets_patterns = {
        'patterns': ['*.css', '*.js', '*.json'],
        'ignore_patterns': None,
        'ignore_directories': False,
        'case_sensitive': False,
    }
    watcher_assets_patterns.update(settings.WATCHER_ASSETS_PATTERNS)

    # Init templates and assets event watchers
    templates_event_handler = TemplatesWatchEventHandler(
        settings, root_logger, assets_env, pages_env,
        **watcher_templates_patterns)
    if assets_env is not None:
        assets_event_handler = AssetsWatchEventHandler(
            settings, root_logger, assets_env, pages_env,
            **watcher_assets_patterns)
    # Registering event watchers and start to watch
    observer.schedule(templates_event_handler,
                      settings.TEMPLATES_DIR,
                      recursive=True)
    if assets_env is not None:
        observer.schedule(assets_event_handler,
                          settings.SOURCES_DIR,
                          recursive=True)

    root_logger.warning('Launching the watcher, use CTRL+C to stop it')
    observer.start()
    try:
        while True:
            time.sleep(1)
    except KeyboardInterrupt:
        root_logger.warning('Stopping watcher..')
        observer.stop()
    observer.join()
Exemplo n.º 12
0
 def runserver(args):
     """
     Launch the project watcher to automatically re-build knowed elements on changes
     """
     root_logger = init_logging(args.loglevel.upper(), printout=not(args.silent), logfile=args.logfile)
     raise CommandError("Error: Unable to import CherryPy, you should install it with 'pip install cherrypy'")