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