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)
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'))
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)
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'))