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 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 #3
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 #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)):
                        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 #5
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))