コード例 #1
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'))
コード例 #2
0
ファイル: commands.py プロジェクト: uliwebext/uliweb-ui
    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))
コード例 #3
0
ファイル: commands.py プロジェクト: 28sui/uliweb
    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')) 
        
コード例 #4
0
ファイル: commands.py プロジェクト: zhangchunlin/uliweb-ui
    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
        import ConfigParser

        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)

        from uliweb import settings

        if options.dest:
            module = options.dest
            filename = pkg.resource_filename(options.dest, 'gulp_settings.ini')
        else:
            module = options.app
            filename = pkg.resource_filename(options.app, 'gulp_settings.ini')

        with open(filename, 'wb') as f:
            template_gulp = settings.get("TEMPLATE_GULP",
                                         {})  # 导出settings中的gulp配置
            template_use_keys = settings.get(
                "TEMPLATE_USE", {}).keys()  # 导出settings中的plugins的名字
            for dist, items in template_gulp.items():
                # 有序遍历gulp的concat配置
                item_dist = dist
                for name in items:
                    if name in template_use_keys:
                        # 如果plugins中有该插件则在ini中写入该配置
                        s = find(name)
                        m = s[0] + s[1]
                        f.write("[template_use." + name + "]\r\n")
                        for i in m:
                            #if no_js then skip javascript files
                            if options.no_js and (i.startswith('<!--')
                                                  or i.endswith('.js')):
                                continue
                            if not i.startswith('<!--'):
                                f.write("toplinks[] = " +
                                        app.get_file(i, 'static') + "\r\n")
                        f.write("dist = " + item_dist + "\r\n")
                    f.write("\r\n")

        gulp_dist = pkg.resource_filename(module, '/static')
        gulp_settings = filename
        gulp_path = pkg.resource_filename("uliweb_ui", "")
        import os
        terminal_command = "cd " + gulp_path + " && gulp  --dist " + gulp_dist + " --settings " + gulp_settings
        print(">>> {}".format(terminal_command))
        os.system(terminal_command)
コード例 #5
0
ファイル: commands.py プロジェクト: uliwebext/uliweb-ui
    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
        import ConfigParser

        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)

        from uliweb import settings

        if options.dest:
            module = options.dest
            filename = pkg.resource_filename(options.dest, 'gulp_settings.ini')
        else:
            module = options.app
            filename = pkg.resource_filename(options.app, 'gulp_settings.ini')

        with open(filename, 'wb') as f:
            template_gulp = settings.get("TEMPLATE_GULP", {}) # 导出settings中的gulp配置
            template_use_keys = settings.get("TEMPLATE_USE", {}).keys() # 导出settings中的plugins的名字
            for dist,items in template_gulp.items():
                # 有序遍历gulp的concat配置
                item_dist = dist
                for name in items:
                    if name in template_use_keys:
                        # 如果plugins中有该插件则在ini中写入该配置
                        s = find(name)
                        m = s[0] + s[1]
                        f.write("[template_use." + name + "]\r\n")
                        for i in m:
                            if not i.startswith('<!--'):
                                f.write("toplinks[] = " + app.get_file(i, 'static') + "\r\n")
                        f.write("dist = " + item_dist + "\r\n")
                    f.write("\r\n")

        gulp_dist = pkg.resource_filename(module, '/static');
        gulp_settings = filename
        gulp_path = pkg.resource_filename("uliweb_ui","")
        import os
        terminal_command = "cd "+gulp_path+ " && gulp  --dist " + gulp_dist + " --settings " + gulp_settings
        print ">>> {}".format(terminal_command)
        os.system(terminal_command)
コード例 #6
0
def get_settings(project_dir, include_apps=None, settings_file='settings.ini', 
    local_settings_file='local_settings.ini', default_settings=None):
    apps_dir = os.path.join(project_dir, 'apps')
    apps = get_apps(apps_dir, settings_file=settings_file, local_settings_file=local_settings_file)
    settings = []
    inifile = pkg.resource_filename('uliweb.core', 'default_settings.ini')
    settings.insert(0, inifile)
    for p in apps:
        path = get_app_dir(p)
        #deal with settings
        inifile =os.path.join(get_app_dir(p), 'settings.ini')
        if os.path.exists(inifile):
            settings.append(inifile)
    
    set_ini = os.path.join(apps_dir, settings_file)
    if os.path.exists(set_ini):
        settings.append(set_ini)
    
    local_set_ini = os.path.join(apps_dir, local_settings_file)
    if os.path.exists(local_set_ini):
        settings.append(local_set_ini)

    x = pyini.Ini()
    for v in settings:
        x.read(v)
    x.update(default_settings or {})
    
    #process FILESYSTEM_ENCODING
    if not x.GLOBAL.FILESYSTEM_ENCODING:
        x.GLOBAL.FILESYSTEM_ENCODING = sys.getfilesystemencoding() or x.GLOBAL.DEFAULT_ENCODING
    return x
コード例 #7
0
ファイル: wsgi_staticfiles.py プロジェクト: tangjn/uliweb
 def _loader(filename):
     from werkzeug.exceptions import Forbidden, NotFound
     from uliweb.utils.common import pkg
     
     app = self.app
     f = None
     if dir:
         fname = os.path.normpath(os.path.join(dir, filename)).replace('\\', '/')
         if not fname.startswith(dir):
             return Forbidden("You can only visit the files under static directory."), None
         if os.path.exists(fname):
             f = fname
     else:
         for p in reversed(app.apps):
             fname = os.path.normpath(os.path.join('static', filename)).replace('\\', '/')
             if not fname.startswith('static/'):
                 return Forbidden("You can only visit the files under static directory."), None
             
             ff = pkg.resource_filename(p, fname)
             if os.path.exists(ff):
                 f = ff
                 break
     
     if f:
         return f, self._opener(f)
     
     return NotFound("Can't found the file %s" % filename), None
コード例 #8
0
ファイル: manage.py プロジェクト: 08haozi/uliweb
    def handle(self, options, global_options, *args):
        from uliweb.utils.common import copy_dir
        from uliweb.utils.common import pkg

        _types = []
        support_dirs = {}
        app_dirs = [
            os.path.join(SimpleFrame.get_app_dir(appname), "template_files/support")
            for appname in self.get_apps(global_options)
        ]
        for path in [pkg.resource_filename("uliweb", "template_files/support/")] + app_dirs:
            if os.path.exists(path):
                for f in os.listdir(path):
                    _path = os.path.join(path, f)
                    if os.path.isdir(_path) and not f.startswith("."):
                        _name = f
                        _types.append(_name)
                        support_dirs[_name] = _path

        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":
            src_dir = support_dirs[support_type]
            copy_dir(src_dir, ".", verbose=global_options.verbose)
コード例 #9
0
ファイル: SimpleFrame.py プロジェクト: lssebastian/uliweb
def get_settings(project_dir, include_apps=None, settings_file='settings.ini', 
    local_settings_file='local_settings.ini', default_settings=None):
    apps_dir = os.path.join(project_dir, 'apps')
    apps = get_apps(apps_dir, settings_file=settings_file, local_settings_file=local_settings_file)
    settings = []
    inifile = pkg.resource_filename('uliweb.core', 'default_settings.ini')
    settings.insert(0, inifile)
    for p in apps:
        path = get_app_dir(p)
        #deal with settings
        inifile =os.path.join(get_app_dir(p), 'settings.ini')
        if os.path.exists(inifile):
            settings.append(inifile)
    
    set_ini = os.path.join(apps_dir, settings_file)
    if os.path.exists(set_ini):
        settings.append(set_ini)
    
    local_set_ini = os.path.join(apps_dir, local_settings_file)
    if os.path.exists(local_set_ini):
        settings.append(local_set_ini)

    x = pyini.Ini()
    for v in settings:
        x.read(v)
    x.update(default_settings or {})
    
    #process FILESYSTEM_ENCODING
    if not x.GLOBAL.FILESYSTEM_ENCODING:
        x.GLOBAL.FILESYSTEM_ENCODING = sys.getfilesystemencoding() or x.GLOBAL.DEFAULT_ENCODING
    return x
コード例 #10
0
ファイル: views.py プロジェクト: datakungfu/uliweb
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)
コード例 #11
0
 def handle(self, options, global_options, *args):
     from uliweb.utils.common import check_apps_dir
     opts = {'verbose':global_options.verbose, 'template':options.template,
         'exact':options.exact}
     if options.project:
         check_apps_dir(global_options.apps_dir)
         app = self.get_application(global_options)
         
         _process(global_options.apps_dir, options.locale, opts, output_dir=global_options.project)
     elif options.apps or args:
         check_apps_dir(global_options.apps_dir)
         
         app = self.get_application(global_options)
         if options.apps:
             _apps = SimpleFrame.get_apps(global_options.apps_dir)
         else:
             _apps = args
         apps_dir = os.path.normpath(os.path.abspath(global_options.apps_dir))
         for appname in _apps:
             path = SimpleFrame.get_app_dir(appname)
             if global_options.verbose:
                 print('Processing... app=>[%s] path=>[%s]' % (appname, path))
             _process(path, options.locale, opts)
     elif options.uliweb:
         path = pkg.resource_filename('uliweb', '')
         _process(path, options.locale, opts)
     elif options.directory:
         _process(options.directory, options.locale, opts)
コード例 #12
0
ファイル: manage.py プロジェクト: dtld/uliweb
    def handle(self, options, global_options, *args):
        from uliweb.utils.common import copy_dir
        from uliweb.utils.common import pkg
        
        _types = []
        support_dirs = {}
        app_dirs = [os.path.join(SimpleFrame.get_app_dir(appname), 'template_files/support') for appname in self.get_apps(global_options)]
        for path in [pkg.resource_filename('uliweb', 'template_files/support/')] + app_dirs:
            if os.path.exists(path):
                for f in os.listdir(path):
                    _path = os.path.join(path, f)
                    if os.path.isdir(_path) and not f.startswith('.'):
                        _name = f
                        _types.append(_name)
                        support_dirs[_name] = _path

        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':
            src_dir = support_dirs[support_type]
            copy_dir(src_dir, '.', verbose=global_options.verbose)
コード例 #13
0
ファイル: i18ntool.py プロジェクト: 08haozi/uliweb
 def handle(self, options, global_options, *args):
     from uliweb.utils.common import check_apps_dir
     opts = {'verbose':global_options.verbose, 'template':options.template,
         'exact':options.exact}
     if options.project:
         check_apps_dir(global_options.apps_dir)
         app = self.get_application(global_options)
         
         _process(global_options.apps_dir, options.locale, opts, output_dir=global_options.project)
     elif options.apps or args:
         check_apps_dir(global_options.apps_dir)
         
         app = self.get_application(global_options)
         if options.apps:
             _apps = SimpleFrame.get_apps(global_options.apps_dir)
         else:
             _apps = args
         apps_dir = os.path.normpath(os.path.abspath(global_options.apps_dir))
         for appname in _apps:
             path = SimpleFrame.get_app_dir(appname)
             if global_options.verbose:
                 print 'Processing... app=>[%s] path=>[%s]' % (appname, path)
             _process(path, options.locale, opts)
     elif options.uliweb:
         path = pkg.resource_filename('uliweb', '')
         _process(path, options.locale, opts)
     elif options.directory:
         _process(options.directory, options.locale, opts)
コード例 #14
0
 def handle(self, options, global_options, *args):
     opts = {
         'verbose': global_options.verbose,
         'template': options.template,
         'exact': options.exact
     }
     if options.project:
         _process(global_options.project, options.locale, opts)
     elif options.apps or args:
         if options.apps:
             _apps = SimpleFrame.get_apps(global_options.apps_dir)
         else:
             _apps = args
         apps_dir = os.path.normpath(
             os.path.abspath(global_options.apps_dir))
         for appname in _apps:
             path = SimpleFrame.get_app_dir(appname)
             if not path.startswith(apps_dir):
                 continue
             _process(SimpleFrame.get_app_dir(appname), options.locale,
                      opts)
     elif options.uliweb:
         path = pkg.resource_filename('uliweb', '')
         _process(path, options.locale, opts)
     elif options.directory:
         _process(options.directory, options.locale, opts)
コード例 #15
0
        def _loader(filename):
            from werkzeug.exceptions import Forbidden, NotFound
            from uliweb.utils.common import pkg

            app = self.app
            if dir:
                fname = os.path.normpath(os.path.join(dir, filename)).replace(
                    '\\', '/')
                if not fname.startswith(dir):
                    return Forbidden(
                        "You can only visit the files under static directory."
                    ), None
                if os.path.exists(fname):
                    return fname, self._opener(fname)

            for p in reversed(app.apps):
                fname = os.path.normpath(os.path.join('static',
                                                      filename)).replace(
                                                          '\\', '/')
                if not fname.startswith('static/'):
                    return Forbidden(
                        "You can only visit the files under static directory."
                    ), None

                f = pkg.resource_filename(p, fname)
                if os.path.exists(f):
                    return f, self._opener(f)

            return NotFound("Can't found the file %s" % filename), None
コード例 #16
0
    def handle(self, options, global_options, *args):
        from uliweb.utils.common import copy_dir
        from uliweb.utils.common import pkg
        
        _types = []
        support_dirs = {}
        app_dirs = [os.path.join(SimpleFrame.get_app_dir(appname), 'template_files/support') for appname in self.get_apps(global_options)]
        for path in [pkg.resource_filename('uliweb', 'template_files/support/')] + app_dirs:
            if os.path.exists(path):
                for f in os.listdir(path):
                    _path = os.path.join(path, f)
                    if os.path.isdir(_path) and not f.startswith('.'):
                        _name = f
                        _types.append(_name)
                        support_dirs[_name] = _path

        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':
            src_dir = support_dirs[support_type]
            copy_dir(src_dir, '.', verbose=global_options.verbose)
コード例 #17
0
ファイル: SimpleFrame.py プロジェクト: hb44/uliweb
def collect_settings(project_dir,
                     include_apps=None,
                     settings_file='settings.ini',
                     local_settings_file='local_settings.ini'):

    apps_dir = os.path.join(project_dir, 'apps')
    apps = get_apps(apps_dir,
                    None,
                    settings_file=settings_file,
                    local_settings_file=local_settings_file)
    settings_file = os.path.join(apps_dir, settings_file)
    local_settings_file = os.path.join(apps_dir, local_settings_file)
    settings = []
    inifile = pkg.resource_filename('uliweb.core', 'default_settings.ini')
    settings.insert(0, inifile)
    for p in apps:
        path = get_app_dir(p)
        #deal with settings
        inifile = os.path.join(get_app_dir(p), 'settings.ini')
        if os.path.exists(inifile):
            settings.append(inifile)

    if os.path.exists(settings_file):
        settings.append(settings_file)

    if os.path.exists(local_settings_file):
        settings.append(local_settings_file)
    return settings
コード例 #18
0
ファイル: subcommands.py プロジェクト: limodou/uliweb3
    def handle(self, options, global_options, *args):
        from uliweb.utils.common import pkg
        from uliweb import functions
        from uliweb.core.template import template_file
        from uliweb.orm import true
        import time

        self.get_application(global_options)

        Recorder = functions.get_model('uliwebrecorder')

        if args:
            if os.path.exists(args[0]):
                message = "Ths file %s is already exists, do you want to overwrite it?" % args[
                    0]
                ans = 'Y' if global_options.yes else get_answer(message)
                if ans != 'Y':
                    return

            out = open(args[0], 'w')
            relpath = os.path.normpath(
                os.path.relpath(os.path.dirname(args[0]) or './',
                                '.')).replace('\\', '/')
        else:
            out = sys.stdout
            relpath = '.'

        condition = true()
        if options.begin_time:
            condition = (Recorder.c.begin_datetime >=
                         options.begin_time) & condition
        if options.id:
            condition = (Recorder.c.id >= int(options.id)) & condition

        path = pkg.resource_filename('uliweb.contrib.recorder',
                                     'template_files')
        tplfile = os.path.join(path, options.template).replace('\\', '/')
        row_tplfile = os.path.join(path,
                                   options.template_row).replace('\\', '/')

        out.write('#coding=utf8\n')
        if global_options.verbose:
            print('#recorder template is "%s"' % tplfile)
            print('#recorder row template is "%s"' % row_tplfile)

        begin = time.time()
        rows = []
        for row in Recorder.filter(condition):
            rows.append(template_file(row_tplfile, {'row': row}).rstrip())

        out.write(
            template_file(tplfile, {
                'project_dir': relpath,
                'rows': rows
            }))
        out.write('\n#total %d records output, time used %ds\n' %
                  (len(rows), time.time() - begin))
コード例 #19
0
ファイル: manage.py プロジェクト: dtld/uliweb
 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)
コード例 #20
0
ファイル: SimpleFrame.py プロジェクト: biluo1989/uliweb
    def collect_modules(self, check_view=True):
        modules = {}
        views = set()
        settings = []

        inifile = pkg.resource_filename("uliweb.core", "default_settings.ini")
        settings.insert(0, inifile)

        def enum_views(views_path, appname, subfolder=None, pattern=None):
            if not os.path.exists(views_path):
                log.error("Can't found the app %s path, please check if the path is right" % appname)
                return

            for f in os.listdir(views_path):
                fname, ext = os.path.splitext(f)
                if (
                    os.path.isfile(os.path.join(views_path, f))
                    and ext in [".py", ".pyc", ".pyo"]
                    and fname != "__init__"
                ):
                    if pattern:
                        import fnmatch

                        if not fnmatch.fnmatch(f, pattern):
                            continue
                    if subfolder:
                        views.add(".".join([appname, subfolder, fname]))
                    else:
                        views.add(".".join([appname, fname]))

        for p in self.apps:
            path = get_app_dir(p)
            # deal with views
            if check_view:
                views_path = os.path.join(path, "views")
                if os.path.exists(views_path) and os.path.isdir(views_path):
                    enum_views(views_path, p, "views")
                else:
                    enum_views(path, p, pattern="views*")
            # deal with settings
            inifile = os.path.join(get_app_dir(p), "settings.ini")

            if os.path.exists(inifile):
                settings.append(inifile)

        set_ini = os.path.join(self.apps_dir, self.settings_file)
        if os.path.exists(set_ini):
            settings.append(set_ini)

        local_set_ini = os.path.join(self.apps_dir, self.local_settings_file)
        if os.path.exists(local_set_ini):
            settings.append(local_set_ini)

        modules["views"] = list(views)
        modules["settings"] = settings
        return modules
コード例 #21
0
ファイル: manage.py プロジェクト: hankji/uliweb
 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)
コード例 #22
0
ファイル: commands.py プロジェクト: bobgao/uliweb
 def handle(self, options, global_options, *args):
     from uliweb.utils.common import extract_dirs, pkg
     from uliweb.core.template import template_file
     
     extract_dirs('uliweb.contrib.orm', 'templates/alembic', '.', verbose=global_options.verbose, replace=False)
     engine_string = get_engine(options, global_options)
     ini_file = os.path.join(pkg.resource_filename('uliweb.contrib.orm', 'templates/alembic/alembic.ini'))
     text = template_file(ini_file, {'CONNECTION':engine_string})
     with open(os.path.join(global_options.project, 'alembic.ini'), 'w') as f:
         f.write(text)
コード例 #23
0
ファイル: SimpleFrame.py プロジェクト: hb44/uliweb
    def collect_modules(self, check_view=True):
        modules = {}
        views = set()
        settings = []

        inifile = pkg.resource_filename('uliweb.core', 'default_settings.ini')
        settings.insert(0, ('', inifile))

        def enum_views(views_path, appname, subfolder=None, pattern=None):
            if not os.path.exists(views_path):
                log.error(
                    "Can't found the app %s path, please check if the path is right"
                    % appname)
                return

            for f in os.listdir(views_path):
                fname, ext = os.path.splitext(f)
                if os.path.isfile(os.path.join(views_path, f)) and ext in [
                        '.py', '.pyc', '.pyo'
                ] and fname != '__init__':
                    if pattern:
                        import fnmatch
                        if not fnmatch.fnmatch(f, pattern):
                            continue
                    if subfolder:
                        views.add('.'.join([appname, subfolder, fname]))
                    else:
                        views.add('.'.join([appname, fname]))

        for p in self.apps:
            path = get_app_dir(p)
            #deal with views
            if check_view:
                views_path = os.path.join(path, 'views')
                if os.path.exists(views_path) and os.path.isdir(views_path):
                    enum_views(views_path, p, 'views')
                else:
                    enum_views(path, p, pattern='views*')
            #deal with settings
            inifile = os.path.join(get_app_dir(p), 'settings.ini')

            if os.path.exists(inifile):
                settings.append((p, inifile))

        set_ini = os.path.join(self.apps_dir, self.settings_file)
        if os.path.exists(set_ini):
            settings.append(('', set_ini))

        local_set_ini = os.path.join(self.apps_dir, self.local_settings_file)
        if os.path.exists(local_set_ini):
            settings.append(('', local_set_ini))

        modules['views'] = list(views)
        modules['settings'] = settings
        return modules
コード例 #24
0
ファイル: manage.py プロジェクト: 08haozi/uliweb
    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)
コード例 #25
0
ファイル: SimpleFrame.py プロジェクト: hb44/uliweb
    def init(self, project_dir, apps_dir):
        if not project_dir:
            project_dir = norm_path(os.path.join(apps_dir, '..'))

        Dispatcher.project_dir = project_dir
        Dispatcher.apps_dir = norm_path(os.path.join(project_dir, 'apps'))
        Dispatcher.apps = get_apps(self.apps_dir, self.include_apps,
                                   self.settings_file,
                                   self.local_settings_file)
        Dispatcher.modules = self.collect_modules()

        self.install_settings(self.modules['settings'])

        self.debug = settings.GLOBAL.get('DEBUG', False)

        #process global_objects
        self.install_global_objects()

        #process binds
        self.install_binds()

        dispatch.call(self, 'after_init_settings')

        Dispatcher.settings = settings

        #process domains
        self.process_domains(settings)

        #setup log
        self.set_log()

        #set app rules
        rules.set_app_rules(dict(settings.get('URL', {})))
        rules.set_urlroute_rules(dict(settings.get('URL_ROUTE', {})))

        Dispatcher.env = self._prepare_env()
        Dispatcher.template_dirs = self.get_template_dirs()
        Dispatcher.template_loader = self.install_template_loader(
            Dispatcher.template_dirs)

        #begin to start apps
        self.install_apps()
        dispatch.call(self, 'after_init_apps')
        #process views
        self.install_views(self.modules['views'])
        #process exposes
        self.install_exposes()
        #process middlewares
        Dispatcher.middlewares = self.install_middlewares()

        dispatch.call(self, 'prepare_default_env', Dispatcher.env)
        Dispatcher.default_template = pkg.resource_filename(
            'uliweb.core', 'default.html')

        Dispatcher.installed = True
コード例 #26
0
ファイル: SimpleFrame.py プロジェクト: yonglehou/uliweb
    def collect_modules(self, check_view=True):
        modules = {}
        views = []
        settings = []

        inifile = pkg.resource_filename('uliweb.core', 'default_settings.ini')
        settings.insert(0, ('', inifile))
        
        def enum_views(views_path, appname, subfolder=None, pattern=None):
            if not os.path.exists(views_path):
                log.error("Can't found the app %s path, please check if the path is right" % appname)
                return
                 
            for f in os.listdir(views_path):
                fname, ext = os.path.splitext(f)
                if os.path.isfile(os.path.join(views_path, f)) and ext in ['.py', '.pyc', '.pyo'] and fname!='__init__':
                    if pattern:
                        import fnmatch
                        if not fnmatch.fnmatch(f, pattern):
                            continue
                    if subfolder:
                        _view = '.'.join([appname, subfolder, fname])
                    else:
                        _view = '.'.join([appname, fname])
                    if _view not in views:
                        views.append(_view)

        for p in self.apps:
            path = get_app_dir(p)
            #deal with views
            if check_view:
                views_path = os.path.join(path, 'views')
                if os.path.exists(views_path) and os.path.isdir(views_path):
                    enum_views(views_path, p, 'views')
                else:
                    enum_views(path, p, pattern='views*')
            #deal with settings
            inifile =os.path.join(get_app_dir(p), 'settings.ini')
            
            if os.path.exists(inifile):
                settings.append((p, inifile))

        set_ini = os.path.join(self.apps_dir, self.settings_file)
        if os.path.exists(set_ini):
            settings.append(('', set_ini))
        
        local_set_ini = os.path.join(self.apps_dir, self.local_settings_file)
        if os.path.exists(local_set_ini):
            settings.append(('', local_set_ini))
        
        modules['views'] = views
        modules['settings'] = settings
        return modules
コード例 #27
0
ファイル: commands.py プロジェクト: zhangchunlin/uliweb-ui
    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))
コード例 #28
0
ファイル: SimpleFrame.py プロジェクト: hb44/uliweb
    def init(self, project_dir, apps_dir):
        if not project_dir:
            project_dir = norm_path(os.path.join(apps_dir, '..'))
        
        Dispatcher.project_dir = project_dir
        Dispatcher.apps_dir = norm_path(os.path.join(project_dir, 'apps'))
        Dispatcher.apps = get_apps(self.apps_dir, self.include_apps, self.settings_file, self.local_settings_file)
        Dispatcher.modules = self.collect_modules()

        self.install_settings(self.modules['settings'])

        self.debug = settings.GLOBAL.get('DEBUG', False)

        #process global_objects
        self.install_global_objects()
        
        #process binds
        self.install_binds()
        
        dispatch.call(self, 'after_init_settings')
        
        Dispatcher.settings = settings
        
        #process domains
        self.process_domains(settings)
        
        #setup log
        self.set_log()
        
        #set app rules
        rules.set_app_rules(dict(settings.get('URL', {})))
        rules.set_urlroute_rules(dict(settings.get('URL_ROUTE', {})))

        Dispatcher.env = self._prepare_env()
        Dispatcher.template_dirs = self.get_template_dirs()
        Dispatcher.template_loader = self.install_template_loader(Dispatcher.template_dirs)

        #begin to start apps
        self.install_apps()
        dispatch.call(self, 'after_init_apps')
        #process views
        self.install_views(self.modules['views'])
        #process exposes
        self.install_exposes()
        #process middlewares
        Dispatcher.middlewares = self.install_middlewares()

        dispatch.call(self, 'prepare_default_env', Dispatcher.env)
        Dispatcher.default_template = pkg.resource_filename('uliweb.core', 'default.html')
        
        Dispatcher.installed = True
コード例 #29
0
ファイル: SimpleFrame.py プロジェクト: biluo1989/uliweb
    def init(self, project_dir, apps_dir):
        if not project_dir:
            project_dir = norm_path(os.path.join(apps_dir, ".."))
        Dispatcher.project_dir = project_dir
        Dispatcher.apps_dir = norm_path(os.path.join(project_dir, "apps"))
        Dispatcher.apps = get_apps(self.apps_dir, self.include_apps, self.settings_file, self.local_settings_file)
        Dispatcher.modules = self.collect_modules()

        self.install_settings(self.modules["settings"])

        # process global_objects
        self.install_global_objects()

        # process binds
        self.install_binds()

        dispatch.call(self, "after_init_settings")

        Dispatcher.settings = settings

        # process domains
        self.process_domains(settings)

        # setup log
        self.set_log()

        # set app rules
        rules.set_app_rules(dict(settings.get("URL", {})))

        Dispatcher.env = self._prepare_env()
        Dispatcher.template_dirs = self.get_template_dirs()
        Dispatcher.template_processors = {}
        self.install_template_processors()

        # begin to start apps
        self.install_apps()
        dispatch.call(self, "after_init_apps")
        # process views
        self.install_views(self.modules["views"])
        # process exposes
        self.install_exposes()
        # process middlewares
        Dispatcher.middlewares = self.install_middlewares()

        self.debug = settings.GLOBAL.get("DEBUG", False)
        dispatch.call(self, "prepare_default_env", Dispatcher.env)
        Dispatcher.default_template = pkg.resource_filename("uliweb.core", "default.html")

        Dispatcher.installed = True
コード例 #30
0
ファイル: SimpleFrame.py プロジェクト: lssebastian/uliweb
 def get_file(self, filename, dir='static'):
     """
     get_file will search from apps directory
     """
     if os.path.exists(filename):
         return filename
     dirs = self.apps
     if dir:
         fname = os.path.join(dir, filename)
     else:
         fname = filename
     for d in reversed(dirs):
         path = pkg.resource_filename(d, fname)
         if os.path.exists(path):
             return path
     return None
コード例 #31
0
ファイル: SimpleFrame.py プロジェクト: FashtimeDotCom/uliweb
 def get_file(self, filename, dir='static'):
     """
     get_file will search from apps directory
     """
     if os.path.exists(filename):
         return filename
     dirs = self.apps
     if dir:
         fname = os.path.join(dir, filename)
     else:
         fname = filename
     for d in reversed(dirs):
         path = pkg.resource_filename(d, fname)
         if os.path.exists(path):
             return path
     return None
コード例 #32
0
ファイル: SimpleFrame.py プロジェクト: datakungfu/uliweb
    def collect_modules(self, check_view=True):
        modules = {}
        views = set()
        settings = []

        inifile = pkg.resource_filename('uliweb.core', 'default_settings.ini')
        settings.insert(0, inifile)
        
        def enum_views(views_path, appname, subfolder=None, pattern=None):
            for f in os.listdir(views_path):
                fname, ext = os.path.splitext(f)
                if os.path.isfile(os.path.join(views_path, f)) and ext in ['.py', '.pyc', '.pyo'] and fname!='__init__':
                    if pattern:
                        import fnmatch
                        if not fnmatch.fnmatch(f, pattern):
                            continue
                    if subfolder:
                        views.add('.'.join([appname, subfolder, fname]))
                    else:
                        views.add('.'.join([appname, fname]))

        for p in self.apps:
            path = get_app_dir(p)
            #deal with views
            if check_view:
                views_path = os.path.join(path, 'views')
                if os.path.exists(views_path) and os.path.isdir(views_path):
                    enum_views(views_path, p, 'views')
                else:
                    enum_views(path, p, pattern='views*')
            #deal with settings
            inifile =os.path.join(get_app_dir(p), 'settings.ini')
            
            if os.path.exists(inifile):
                settings.append(inifile)

        set_ini = os.path.join(self.apps_dir, self.settings_file)
        if os.path.exists(set_ini):
            settings.append(set_ini)
        
        local_set_ini = os.path.join(self.apps_dir, self.local_settings_file)
        if os.path.exists(local_set_ini):
            settings.append(local_set_ini)
        
        modules['views'] = list(views)
        modules['settings'] = settings
        return modules
コード例 #33
0
ファイル: __init__.py プロジェクト: znanl/uliweb
def startup_installed(sender):
    """
    @LANGUAGE_CODE
    """
    import os
    from uliweb.core.SimpleFrame import get_app_dir
    from uliweb.i18n import install, set_default_language
    from uliweb.utils.common import pkg, expand_path
    
    path = pkg.resource_filename('uliweb', '')
    _dirs = []
    for d in sender.settings.get_var('I18N/LOCALE_DIRS', []):
        _dirs.append(expand_path(d))
    localedir = ([os.path.normpath(sender.apps_dir + '/..')] + 
        [get_app_dir(appname) for appname in sender.apps] + [path] + _dirs)
    install('uliweb', localedir)
    set_default_language(sender.settings.I18N.LANGUAGE_CODE)
コード例 #34
0
ファイル: subcommands.py プロジェクト: limodou/uliweb
    def handle(self, options, global_options, *args):
        from uliweb.utils.common import pkg
        from uliweb import functions
        from uliweb.core.template import template_file
        from uliweb.orm import true
        import time

        self.get_application(global_options)

        Recorder = functions.get_model('uliwebrecorder')

        if args:
            if os.path.exists(args[0]):
                message = "Ths file %s is already exists, do you want to overwrite it?" % args[0]
                ans = 'Y' if global_options.yes else get_answer(message)
                if ans != 'Y':
                    return

            out = open(args[0], 'w')
            relpath = os.path.normpath(os.path.relpath(os.path.dirname(args[0]) or './', '.')).replace('\\', '/')
        else:
            out = sys.stdout
            relpath = '.'

        condition = true()
        if options.begin_time:
            condition = (Recorder.c.begin_datetime >= options.begin_time) & condition
        if options.id:
            condition = (Recorder.c.id >= int(options.id)) & condition

        path = pkg.resource_filename('uliweb.contrib.recorder', 'template_files')
        tplfile = os.path.join(path, options.template).replace('\\', '/')
        row_tplfile = os.path.join(path, options.template_row).replace('\\', '/')

        out.write('#coding=utf8\n')
        if global_options.verbose:
            print '#recorder template is "%s"' % tplfile
            print '#recorder row template is "%s"' % row_tplfile

        begin = time.time()
        rows = []
        for row in Recorder.filter(condition):
            rows.append(template_file(row_tplfile, {'row':row}).rstrip())

        out.write(template_file(tplfile, {'project_dir':relpath, 'rows':rows}))
        out.write('\n#total %d records output, time used %ds\n' % (len(rows), time.time()-begin))
コード例 #35
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}
コード例 #36
0
ファイル: SimpleFrame.py プロジェクト: datakungfu/uliweb
def get_app_dir(app):
    """
    Get an app's directory
    """
    path = __app_dirs__.get(app)
    if path is not None:
        return path
    else:
        p = app.split('.')
        try:
            path = pkg.resource_filename(p[0], '')
        except ImportError, e:
            log.exception(e)
            path = ''
        if len(p) > 1:
            path = os.path.join(path, *p[1:])
        
        __app_dirs__[app] = path
        return path
コード例 #37
0
ファイル: views.py プロジェクト: datakungfu/uliweb
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}
コード例 #38
0
ファイル: SimpleFrame.py プロジェクト: FashtimeDotCom/uliweb
def get_app_dir(app):
    """
    Get an app's directory
    """
    path = __app_dirs__.get(app)
    if path is not None:
        return path
    else:
        p = app.split('.')
        try:
            path = pkg.resource_filename(p[0], '')
        except ImportError, e:
            log.error("Can't import app %s" % p[0])
            log.exception(e)
            path = ''
        if len(p) > 1:
            path = os.path.join(path, *p[1:])
        
        __app_dirs__[app] = path
        return path
コード例 #39
0
ファイル: i18ntool.py プロジェクト: datakungfu/uliweb
 def handle(self, options, global_options, *args):
     opts = {'verbose':global_options.verbose}
     if options.project:
         _process(global_options.project, options.locale, opts)
     elif options.apps or args:
         if options.apps:
             _apps = SimpleFrame.get_apps(global_options.apps_dir)
         else:
             _apps = args
         apps_dir = os.path.normpath(os.path.abspath(global_options.apps_dir))
         for appname in _apps:
             path = SimpleFrame.get_app_dir(appname)
             if not path.startswith(apps_dir):
                 continue
             _process(SimpleFrame.get_app_dir(appname), options.locale, opts)
     elif options.uliweb:
         path = pkg.resource_filename('uliweb', '')
         _process(path, options.locale, opts)
     elif options.directory:
         _process(options.directory, options.locale, opts)
コード例 #40
0
ファイル: i18ntool.py プロジェクト: ArikaChen/uliweb
 def handle(self, options, global_options, *args):
     opts = {'verbose':global_options.verbose, 'template':options.template,
         'exact':options.exact}
     if options.project:
         _process(global_options.project, options.locale, opts)
     elif options.apps or args:
         if options.apps:
             _apps = SimpleFrame.get_apps(global_options.apps_dir)
         else:
             _apps = args
         apps_dir = os.path.normpath(os.path.abspath(global_options.apps_dir))
         for appname in _apps:
             path = SimpleFrame.get_app_dir(appname)
             if global_options.verbose:
                 print 'Processing... app=>[%s] path=>[%s]' % (appname, path)
             _process(path, options.locale, opts)
     elif options.uliweb:
         path = pkg.resource_filename('uliweb', '')
         _process(path, options.locale, opts)
     elif options.directory:
         _process(options.directory, options.locale, opts)
コード例 #41
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)
コード例 #42
0
ファイル: SimpleFrame.py プロジェクト: bluesky4485/uliweb
def collect_settings(project_dir, include_apps=None, settings_file='settings.ini', 
    local_settings_file='local_settings.ini'):
    
    apps_dir = os.path.join(project_dir, 'apps')
    apps = get_apps(apps_dir, None, settings_file=settings_file, local_settings_file=local_settings_file)
    settings_file = os.path.join(apps_dir, settings_file)
    local_settings_file = os.path.join(apps_dir, local_settings_file)
    settings = []
    inifile = pkg.resource_filename('uliweb.core', 'default_settings.ini')
    settings.insert(0, inifile)
    for p in apps:
        path = get_app_dir(p)
        #deal with settings
        inifile =os.path.join(get_app_dir(p), 'settings.ini')
        if os.path.exists(inifile):
            settings.append(inifile)
    
    if os.path.exists(settings_file):
        settings.append(settings_file)
    
    if os.path.exists(local_settings_file):
        settings.append(local_settings_file)
    return settings
コード例 #43
0
ファイル: SimpleFrame.py プロジェクト: datakungfu/uliweb
    def init(self, project_dir, apps_dir):
        if not project_dir:
            project_dir = norm_path(os.path.join(apps_dir, '..'))
        conf.project_dir = project_dir
        conf.apps_dir = norm_path(os.path.join(project_dir, 'apps'))
        Dispatcher.project_dir = project_dir
        Dispatcher.apps_dir = conf.apps_dir
        Dispatcher.apps = get_apps(self.apps_dir, self.include_apps, self.settings_file, self.local_settings_file)
        Dispatcher.modules = self.collect_modules()
        
        self.install_settings(self.modules['settings'])
        Dispatcher.settings = conf.settings
        
        #setup log
        self.set_log()
        
        #set app rules
        rules.set_app_rules(dict(conf.settings.get('URL', {})))
        
        Dispatcher.env = self._prepare_env()
        Dispatcher.template_dirs = self.get_template_dirs()
        
        #begin to start apps
        self.install_apps()
        
        dispatch.call(self, 'after_init_apps')

        Dispatcher.url_map = conf.url_map
        self.install_views(self.modules['views'])
        #process dispatch hooks
        self.dispatch_hooks()
        
        self.debug = conf.settings.GLOBAL.get('DEBUG', False)
        dispatch.call(self, 'prepare_default_env', Dispatcher.env)
        Dispatcher.default_template = pkg.resource_filename('uliweb.core', 'default.html')
        
        Dispatcher.installed = True