Example #1
0
    def handle(self, options, global_options, *args):
        from uliweb.utils.pyini import Ini
        from uliweb.utils.common import pkg
        from uliweb.contrib.template.tags import find
        from uliweb.contrib.staticfiles import url_for_static
        from uliweb import json_dumps

        if not options.dest and not options.app:
            print 'Error: Please use -d to specify output app'
            sys.exit(1)

        app = self.get_application(global_options)

        if options.app:
            settings_file = pkg.resource_filename(options.app, 'settings.ini')
            x = Ini(settings_file)

        else:
            x = app.settings

        if options.dest:
            filename = pkg.resource_filename(options.dest, '/static/jsmodules.js')
        else:
            filename = pkg.resource_filename(options.app, '/static/jsmodules.js')

        d = {}
        for name in x.get('TEMPLATE_USE', {}).keys():
            s = find(name)
            m = s[0] + s[1]
            d[name] = [url_for_static(i) for i in m if not i.startswith('<!--')]

        print 'jsmodules.js is saved in {} please check'.format(filename)
        with open(filename, 'wb') as f:
            f.write('var jsmodules = ')
            f.write(json_dumps(d))
Example #2
0
    def process(self, theme_name, data, options, global_options, args):
        from uliweb.utils.common import pkg, copy_dir
        import shutil
        from uliweb.utils.pyini import Ini

        #if there is no apps/appname then create files in current directory

        path = os.path.join(global_options.apps_dir, data['appname'])
        if not os.path.exists(path):
            path = '.'

        gpath = pkg.resource_filename('uliweb.contrib.generic',
                                      'template_files/%s' % theme_name)

        def render(fpath, dst, df):
            text = template_file(fpath, data).replace('\r\n', '\n')
            open(df, 'w').write(text)
            return True

        #copy template files
        copy_dir(os.path.join(gpath, 'templates'),
                 os.path.join(path, 'templates', data['classname']),
                 processor=render)

        #process config.ini
        src_config = os.path.join(gpath, 'config.ini')
        dst_config = os.path.join(path, 'config.ini')
        if os.path.exists(dst_config):
            dst = Ini(dst_config)
            src = Ini(src_config)
            for x in src.DEPENDS.REQUIRED_APPS:
                if x not in dst.DEPENDS.REQUIRED_APPS:
                    dst.DEPENDS.REQUIRED_APPS.append(x)
            dst.save()
        else:
            shutil.copy2(os.path.join(gpath, 'config.ini'), path)

        cpath = pkg.resource_filename('uliweb.contrib.generic',
                                      'template_files/common')

        #copy views file
        self.copy_view(os.path.join(cpath, 'views.py.tmpl'), data,
                       os.path.join(path, data['viewfile']), options.replace)

        #copy add, edit, view
        dpath = os.path.join(path, 'templates', data['classname'])
        if data['addview_popup']:
            self.copy_template(os.path.join(cpath, 'ajax_add.html'), data,
                               os.path.join(dpath, 'add.html'))
        else:
            self.copy_template(os.path.join(cpath, 'add.html'), data,
                               os.path.join(dpath, 'add.html'))
        if data['editview_popup']:
            self.copy_template(os.path.join(cpath, 'ajax_edit.html'), data,
                               os.path.join(dpath, 'edit.html'))
        else:
            self.copy_template(os.path.join(cpath, 'edit.html'), data,
                               os.path.join(dpath, 'edit.html'))
        self.copy_template(os.path.join(cpath, 'view.html'), data,
                           os.path.join(dpath, 'view.html'))
Example #3
0
    def process(self, theme_name, data, options, global_options, args):
        from uliweb.utils.common import pkg, copy_dir
        import shutil
        from uliweb.utils.pyini import Ini
        
        #if there is no apps/appname then create files in current directory
        
        path = os.path.join(global_options.apps_dir, data['appname'])
        if not os.path.exists(path):
            path = '.'
            
        gpath = pkg.resource_filename('uliweb.contrib.generic', 'template_files/%s' % theme_name)
        
        def render(fpath, dst, df):
            text = template_file(fpath, data).replace('\r\n', '\n')
            open(df, 'w').write(text)
            return True
        
        #copy template files
        copy_dir(os.path.join(gpath, 'templates'), os.path.join(path, 'templates', data['classname']),
            processor=render)

        #process config.ini
        src_config = os.path.join(gpath, 'config.ini')
        dst_config = os.path.join(path, 'config.ini')
        if os.path.exists(dst_config):
            dst = Ini(dst_config)
            src = Ini(src_config)
            for x in src.DEPENDS.REQUIRED_APPS:
                if x not in dst.DEPENDS.REQUIRED_APPS:
                    dst.DEPENDS.REQUIRED_APPS.append(x)
            dst.save()
        else:
            shutil.copy2(os.path.join(gpath, 'config.ini'), path)
            
        cpath = pkg.resource_filename('uliweb.contrib.generic', 'template_files/common')

        #check if layout is existed, if not then create it
        layout_file = os.path.join(path, 'templates', data['layout'])
        if not os.path.exists(layout_file):
            self.copy_template(os.path.join(cpath, 'layout.html'), data, layout_file)

        #copy views file
        self.copy_view(os.path.join(cpath, 'views.py.tmpl'), data, 
            os.path.join(path, data['viewfile']), options.replace)
        
        #copy add, edit, view
        dpath = os.path.join(path, 'templates', data['classname'])
        if data['addview_popup']:
            self.copy_template(os.path.join(cpath, 'ajax_add.html'), data, os.path.join(dpath, 'add.html'))
        else:
            self.copy_template(os.path.join(cpath, 'add.html'), data, os.path.join(dpath, 'add.html')) 
        if data['editview_popup']:
            self.copy_template(os.path.join(cpath, 'ajax_edit.html'), data, os.path.join(dpath, 'edit.html')) 
        else:
            self.copy_template(os.path.join(cpath, 'edit.html'), data, os.path.join(dpath, 'edit.html')) 
        self.copy_template(os.path.join(cpath, 'view.html'), data, os.path.join(dpath, 'view.html')) 
        
Example #4
0
 def handle(self, options, global_options, *args):
     from uliweb.utils.common import pkg
     from uliweb.utils.pyini import Ini
     from uliweb.core.commands import get_input
     from uliweb.core.template import template_file
     import glob
     
     _types = []
     config_files = {}
     app_dirs = [os.path.join(SimpleFrame.get_app_dir(appname), 'template_files/config') for appname in self.get_apps(global_options)]
     for path in [pkg.resource_filename('uliweb', 'template_files/config/')] + app_dirs:
         if os.path.exists(path):
             files = glob.glob(os.path.join(path, '*.conf'))
             if files:
                 for f in files:
                     _name = os.path.splitext(os.path.basename(f))[0]
                     _types.append(_name)
                     config_files[_name] = f
     
     support_type = args[0] if args else ''
     while not support_type in _types and support_type != 'quit':
         print 'Supported types:\n'
         print '    ' + '\n    '.join(sorted(_types))
         print
         support_type = raw_input('Please enter support type[quit to exit]:')
     
     if support_type != 'quit':
         conf_file = config_files[support_type]
         conf_ini = conf_file[:-5] + '.ini'
         
         if not os.path.exists(conf_file):
             log.error("%s config can't be found" % support_type)
             sys.exit(1)
             
         data = {}
         data['project_dir'] = os.path.abspath(os.getcwd())
         data['project'] = os.path.basename(data['project_dir'])
         if os.path.exists(conf_ini):
             x = Ini(conf_ini)
             for k, v in x.INPUT.items():
                 if isinstance(v, (tuple, list)):
                     if len(v) == 2:
                         prompt, default = v
                     else:
                         prompt = v[0]
                         default = ''
                 else:
                     prompt, default = v or '', ''
                 if not prompt.strip():
                     prompt = 'Please input %s[%s]:' % (k, default)
                 r = get_input(prompt, default=default)
                 data[k] = r
             data.update(x.get('DEFAULT', {}))
             
         print
         print template_file(conf_file, data)
Example #5
0
 def handle(self, options, global_options, *args):
     from uliweb.utils.common import pkg
     from uliweb.utils.pyini import Ini
     from uliweb.core.commands import get_input
     from uliweb.core.template import template_file
     import glob
     
     _types = []
     config_files = {}
     app_dirs = [os.path.join(SimpleFrame.get_app_dir(appname), 'template_files/config') for appname in self.get_apps(global_options)]
     for path in [pkg.resource_filename('uliweb', 'template_files/config/')] + app_dirs:
         if os.path.exists(path):
             files = glob.glob(os.path.join(path, '*.conf'))
             if files:
                 for f in files:
                     _name = os.path.splitext(os.path.basename(f))[0]
                     _types.append(_name)
                     config_files[_name] = f
     
     support_type = args[0] if args else ''
     while not support_type in _types and support_type != 'quit':
         print 'Supported types:\n'
         print '    ' + '\n    '.join(sorted(_types))
         print
         support_type = raw_input('Please enter support type[quit to exit]:')
     
     if support_type != 'quit':
         conf_file = config_files[support_type]
         conf_ini = conf_file[:-5] + '.ini'
         
         if not os.path.exists(conf_file):
             log.error("%s config can't be found" % support_type)
             sys.exit(1)
             
         data = {}
         data['project_dir'] = os.path.abspath(os.getcwd())
         data['project'] = os.path.basename(data['project_dir'])
         if os.path.exists(conf_ini):
             x = Ini(conf_ini)
             for k, v in x.INPUT.items():
                 if isinstance(v, (tuple, list)):
                     if len(v) == 2:
                         prompt, default = v
                     else:
                         prompt = v[0]
                         default = ''
                 else:
                     prompt, default = v or '', ''
                 if not prompt.strip():
                     prompt = 'Please input %s[%s]:' % (k, default)
                 r = get_input(prompt, default=default)
                 data[k] = r
             data.update(x.get('DEFAULT', {}))
             
         print
         print template_file(conf_file, data)
Example #6
0
    def handle(self, options, global_options, *args):
        from uliweb.utils.common import pkg
        from uliweb.utils.pyini import Ini
        from uliweb.core.commands import get_input
        from uliweb.core.template import template_file
        import glob

        _types = []
        config_files = {}
        app_dirs = [
            os.path.join(SimpleFrame.get_app_dir(appname), "template_files/config")
            for appname in self.get_apps(global_options)
        ]
        for path in [pkg.resource_filename("uliweb", "template_files/config/")] + app_dirs:
            if os.path.exists(path):
                files = glob.glob(os.path.join(path, "*.conf"))
                if files:
                    for f in files:
                        _name = os.path.splitext(os.path.basename(f))[0]
                        _types.append(_name)
                        config_files[_name] = f

        support_type = args[0] if args else ""
        while not support_type in _types and support_type != "quit":
            print "Supported types:\n"
            print "    " + "\n    ".join(sorted(_types))
            print
            support_type = raw_input("Please enter support type[quit to exit]:")

        if support_type != "quit":
            conf_file = config_files[support_type]
            conf_ini = conf_file[:-5] + ".ini"

            if not os.path.exists(conf_file):
                log.error("%s config can't be found" % support_type)
                sys.exit(1)

            data = {}
            data["project_dir"] = os.path.abspath(os.getcwd())
            data["project"] = os.path.basename(data["project_dir"])
            if os.path.exists(conf_ini):
                x = Ini(conf_ini)
                for k, v in x.INPUT.items():
                    if isinstance(v, (tuple, list)):
                        prompt, default = v
                    else:
                        prompt, default = v or "", ""
                    if not prompt.strip():
                        prompt = "Please input %s[%s]:" % (k, default)
                    r = get_input(prompt, default=default)
                    data[k] = r
                data.update(x.get("DEFAULT", {}))

            print
            print template_file(conf_file, data)
Example #7
0
def develop_app_conf():
    module = request.GET['module']
    app_path = pkg.resource_filename(module, '')
    
    form = '<h3>Nothing need to configure!</h3>'
    message = ''
    if is_pyfile_exist(app_path, 'conf'):
        try:
            mod = __import__(module + '.conf', {}, {}, [''])
            f = getattr(mod, 'ManageForm', None)
            if f:
                form = f(action=url_for(develop_app_conf)+'?module=%s' % module, method='post')
                if request.method == 'POST':
                    ini = Ini(os.path.join(application.apps_dir, 'settings.ini'))
                    default_ini = Ini(os.path.join(app_path, 'settings.ini'))
                    r = form.validate(request.POST)
                    if r:
                        flag = form_to_ini(form, ini, default_ini)
                        if flag:
                            message = '<div class="note">Changes have been saved!</div>'
                            ini.save()
                        else:
                            message = '<div class="important">There are no changes.</div>'
                    else:
                        message = '<div class="warning">There are some errors.</div>'
                elif request.method == 'GET':
                    ini = Ini()
                    ini_file = os.path.join(app_path, 'settings.ini')
                    if os.path.exists(ini_file):
                        ini.read(ini_file)
                    ini.read(os.path.join(application.apps_dir, 'settings.ini'))
                    ini_to_form(form, ini)
        
        except ImportError, e:
            log.exception(e)
Example #8
0
def get_app_info(name, app_path, info_ini):
    catalog = 'No Catalog'
    desc = ''
    title = name.capitalize()
    icon = 'app_icon.png'
    author = ''
    version = ''
    homepage = ''

    if os.path.exists(info_ini):
        ini = Ini(info_ini)
        catalog = ini.info.get('catalog', catalog) or catalog
        desc = ini.info.get('description', desc) or desc
        title = ini.info.get('title', title) or title
        icon = ini.info.get('icon', icon) or icon
        icon_file = os.path.join(app_path, 'static', icon)
        author = ini.info.get('author', author) or author
        version = ini.info.get('version', version) or version
        homepage = ini.info.get('homepage', homepage) or homepage

    return {
        'catalog': catalog,
        'desc': desc,
        'title': title,
        'name': name,
        'path': app_path,
        'icon': icon,
        'author': author,
        'version': version,
        'homepage': homepage
    }
Example #9
0
def develop_build():
    from uliweb.utils.common import pkg

    import uliweb.core.SimpleFrame as sf
    app_apps = sf.get_apps(application.apps_dir)

    contrib_path = pkg.resource_filename('uliweb.contrib', '')
    apps_dirs = [(application.apps_dir, ''), (contrib_path, 'uliweb.contrib')]

    #using entry point to find installed apps
    try:
        from pkg_resources import iter_entry_points
    except:
        iter_entry_points = None
    if iter_entry_points:
        #process apps group
        for p in iter_entry_points('uliweb_apps'):
            apps_dirs.append((os.path.join(p.dist.location,
                                           p.module_name), p.module_name))

    catalogs, apps = get_apps(application, apps_dirs, app_apps)

    if iter_entry_points:
        #proces single app
        for p in iter_entry_points('uliweb_app'):
            _get_app(os.path.join(p.dist.location, p.module_name),
                     p.module_name, apps, catalogs, app_apps)

    from forms import GenericForm

    f = GenericForm(method="post")

    if request.method == 'GET':
        #        ini = Ini(os.path.join(application.apps_dir, 'settings.ini'))
        ini_to_form(f, application.settings)

    else:
        r = f.validate(request.params)
        if r:
            ini = Ini(os.path.join(application.apps_dir, 'settings.ini'))
            flag = form_to_ini(f, ini, application.settings)
            if flag:
                ini.save()

    return {'catalogs': catalogs, 'generic_form': f}
Example #10
0
def develop_build():
    from uliweb.utils.common import pkg
    
    import uliweb.core.SimpleFrame as sf
    app_apps = sf.get_apps(application.apps_dir)
    
    contrib_path = pkg.resource_filename('uliweb.contrib', '')
    apps_dirs = [(application.apps_dir, ''), (contrib_path, 'uliweb.contrib')]
    
    #using entry point to find installed apps
    try:
        from pkg_resources import iter_entry_points
    except:
        iter_entry_points = None
    if iter_entry_points:
        #process apps group
        for p in iter_entry_points('uliweb_apps'):
            apps_dirs.append((os.path.join(p.dist.location, p.module_name), p.module_name))
            
    catalogs, apps = get_apps(application, apps_dirs, app_apps)
    
    if iter_entry_points:
        #proces single app
        for p in iter_entry_points('uliweb_app'):
            _get_app(os.path.join(p.dist.location, p.module_name), p.module_name, apps, catalogs, app_apps)
    
    from forms import GenericForm
    
    f = GenericForm(method="post")
    
    if request.method == 'GET':
#        ini = Ini(os.path.join(application.apps_dir, 'settings.ini'))
        ini_to_form(f, application.settings)
        
    else:
        r = f.validate(request.params)
        if r:
            ini = Ini(os.path.join(application.apps_dir, 'settings.ini'))
            flag = form_to_ini(f, ini, application.settings)
            if flag:
                ini.save()
        
    return {'catalogs':catalogs, 'generic_form':f}
Example #11
0
    def handle(self, options, global_options, *args):
        from uliweb.utils.pyini import Ini
        from uliweb.utils.common import pkg
        from uliweb.contrib.template.tags import find
        from uliweb.contrib.staticfiles import url_for_static
        from uliweb import json_dumps

        if not options.dest and not options.app:
            print('Error: Please use -d to specify output app')
            sys.exit(1)

        app = self.get_application(global_options)

        if options.app:
            settings_file = pkg.resource_filename(options.app, 'settings.ini')
            x = Ini(settings_file)

        else:
            x = app.settings

        if options.dest:
            filename = pkg.resource_filename(options.dest,
                                             '/static/jsmodules.js')
        else:
            filename = pkg.resource_filename(options.app,
                                             '/static/jsmodules.js')

        d = {}
        for name in x.get('TEMPLATE_USE', {}).keys():
            s = find(name)
            m = s[0] + s[1]
            d[name] = [
                url_for_static(i) for i in m if not i.startswith('<!--')
            ]

        print('jsmodules.js is saved in {} please check'.format(filename))
        with open(filename, 'wb') as f:
            f.write('var jsmodules = ')
            f.write(json_dumps(d))
Example #12
0
def develop_edit_app():
    ini = Ini(os.path.join(application.apps_dir, 'settings.ini'))
    flag = False
    module = str(request.GET['module'])
    
    import uliweb.core.SimpleFrame as sf
    app_apps = sf.get_apps(application.apps_dir)
    
    if request.GET['action'] == 'add':
        if not ini.GLOBAL.get('INSTALLED_APPS'):
            ini.GLOBAL.INSTALLED_APPS = app_apps
        if module not in ini.GLOBAL.INSTALLED_APPS:
            ini.GLOBAL.INSTALLED_APPS.append(module)
            flag = True
    else:
        if not ini.GLOBAL.get('INSTALLED_APPS'):
            ini.GLOBAL.INSTALLED_APPS = app_apps
        if module in ini.GLOBAL.INSTALLED_APPS:
            ini.GLOBAL.INSTALLED_APPS.remove(module)
            flag = True
    
    if flag:
        ini.save()
    return 'ok'
Example #13
0
def develop_edit_app():
    ini = Ini(os.path.join(application.apps_dir, 'settings.ini'))
    flag = False
    module = str(request.GET['module'])

    import uliweb.core.SimpleFrame as sf
    app_apps = sf.get_apps(application.apps_dir)

    if request.GET['action'] == 'add':
        if not ini.GLOBAL.get('INSTALLED_APPS'):
            ini.GLOBAL.INSTALLED_APPS = app_apps
        if module not in ini.GLOBAL.INSTALLED_APPS:
            ini.GLOBAL.INSTALLED_APPS.append(module)
            flag = True
    else:
        if not ini.GLOBAL.get('INSTALLED_APPS'):
            ini.GLOBAL.INSTALLED_APPS = app_apps
        if module in ini.GLOBAL.INSTALLED_APPS:
            ini.GLOBAL.INSTALLED_APPS.remove(module)
            flag = True

    if flag:
        ini.save()
    return 'ok'
Example #14
0
    def handle(self, options, global_options, *args):
        import os
        from uliweb.utils.pyini import Ini
        if not args:
            print "Error: The daemon name is required."
            return
        else:
            daemon_name = args[0]

        fileconfig = None
        if options.config:
            if os.path.exists(os.path.abspath(os.path.normpath(
                    options.config))) and os.path.isfile(options.config):
                fileconfig = Ini(options.config)
            else:
                print "Error: cannot read configuration file:%s" % options.config
                return

        self.get_application(global_options)
        apps_list = self.get_apps(global_options)

        exe_flag = False

        for app in apps_list:
            module = '%s.%s%s' % (app, __daemon_prefix__, daemon_name)
            try:
                package = __import__(module, fromlist=['*'])
                if global_options.verbose:
                    print "Importing... %s" % module
                if hasattr(package, 'start'):
                    getattr(package, 'start')(args, options, global_options,
                                              fileconfig)
                else:
                    raise Exception("Can't find start entry in module %s" %
                                    module)
                exe_flag = True
            except ImportError:
                pass

        if not exe_flag:
            print "Error: Cannot start daemon [%s], please check the file and try again." % daemon_name
Example #15
0
    def _find_option(self, global_options, option):
        from uliweb import settings
        from uliweb.core.SimpleFrame import collect_settings
        from uliweb.utils.pyini import Ini
        
        print '------ Combined value of [%s] ------' % option
        print settings.get_var(option)

        print '------ Detail   value of [%s] ------' % option
        sec_flag = '/' not in option
        if not sec_flag:
            section, key = option.split('/')
            
        for f in collect_settings(global_options.project, settings_file=global_options.settings,
            local_settings_file=global_options.local_settings):
            x = Ini(f, raw=True)
            if sec_flag:
                if option in x:
                    print x[option]
            else:
                if section in x:
                    if key in x[section]:
                        v = x[section][key]
                        print "%s %s%s" % (str(v), key, v.value())
Example #16
0
def develop_app_conf():
    module = request.GET['module']
    app_path = pkg.resource_filename(module, '')

    form = '<h3>Nothing need to configure!</h3>'
    message = ''
    if is_pyfile_exist(app_path, 'conf'):
        try:
            mod = __import__(module + '.conf', {}, {}, [''])
            f = getattr(mod, 'ManageForm', None)
            if f:
                form = f(action=url_for(develop_app_conf) +
                         '?module=%s' % module,
                         method='post')
                if request.method == 'POST':
                    ini = Ini(
                        os.path.join(application.apps_dir, 'settings.ini'))
                    default_ini = Ini(os.path.join(app_path, 'settings.ini'))
                    r = form.validate(request.POST)
                    if r:
                        flag = form_to_ini(form, ini, default_ini)
                        if flag:
                            message = '<div class="note">Changes have been saved!</div>'
                            ini.save()
                        else:
                            message = '<div class="important">There are no changes.</div>'
                    else:
                        message = '<div class="warning">There are some errors.</div>'
                elif request.method == 'GET':
                    ini = Ini()
                    ini_file = os.path.join(app_path, 'settings.ini')
                    if os.path.exists(ini_file):
                        ini.read(ini_file)
                    ini.read(os.path.join(application.apps_dir,
                                          'settings.ini'))
                    ini_to_form(form, ini)

        except ImportError, e:
            log.exception(e)