def get_apps(apps_dir, include_apps=None, settings_file='settings.ini', local_settings_file='local_settings.ini'): include_apps = include_apps or [] inifile = norm_path(os.path.join(apps_dir, settings_file)) apps = [] visited = set() if not os.path.exists(apps_dir): return apps if os.path.exists(inifile): x = pyini.Ini(inifile) if x: for app in x.GLOBAL.get('INSTALLED_APPS', []): apps.extend(list(get_app_depends(app, visited))) local_inifile = norm_path(os.path.join(apps_dir, local_settings_file)) if os.path.exists(local_inifile): x = pyini.Ini(local_inifile) if x and 'GLOBAL' in x: for app in x.GLOBAL.get('INSTALLED_APPS', []): apps.extend(list(get_app_depends(app, visited))) if not apps and os.path.exists(apps_dir): for p in os.listdir(apps_dir): if os.path.isdir(os.path.join(apps_dir, p)) and p not in ['.svn', 'CVS', '.git'] and not p.startswith('.') and not p.startswith('_'): apps.append(p) for app in include_apps: apps.extend(list(get_app_depends(app, visited))) return apps
def _process(path, locale, options, output_dir=None): from .pygettext import extrace_files from .po_merge import merge from uliweb.utils import pyini output_dir = output_dir or path output = _get_outputfile(output_dir, locale=locale) try: if options['template']: x = pyini.Ini(options['template']) else: x = pyini.Ini() vars = {} vars['First_Author'] = x.get_var('I18N/First_Author', 'FIRST AUTHOR <EMAIL@ADDRESS>') vars['Project_Id_Version'] = x.get_var('I18N/Project_Id_Version', 'PACKAGE VERSION') vars['Last_Translator'] = x.get_var('I18N/Last_Translator', 'FULL NAME <EMAIL@ADDRESS>') vars['Language_Team'] = x.get_var('I18N/Language_Team', 'LANGUAGE <*****@*****.**>') vars['Content_Type_Charset'] = x.get_var('I18N/Content_Type_Charset', 'utf-8') vars['Content_Transfer_Encoding'] = x.get_var('I18N/Content_Transfer_Encoding', '8bit') vars['Plural_Forms'] = x.get_var('I18N/Plural_Forms', 'nplurals=1; plural=0;') extrace_files(path, output, {'verbose':options['verbose']}, vars=vars) print('Success! output file is %s' % output) merge(output[:-4]+'.po', output, options['exact']) except: raise
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
def install_config(apps_dir): from uliweb.utils import pyini #user can configure custom PYTHONPATH, so that uliweb can add these paths #to sys.path, and user can manage third party or public apps in a separate #directory config_filename = os.path.join(apps_dir, 'config.ini') if os.path.exists(config_filename): c = pyini.Ini(config_filename) paths = c.GLOBAL.get('PYTHONPATH', []) if paths: for p in reversed(paths): p = os.path.abspath(os.path.normpath(p)) if not p in sys.path: sys.path.insert(0, p)
def get_settings(project_dir, include_apps=None, settings_file='settings.ini', local_settings_file='local_settings.ini', default_settings=None): settings = collect_settings(project_dir, include_apps, settings_file, local_settings_file, default_settings) x = pyini.Ini(lazy=True) for v in settings: x.read(v) x.update(default_settings or {}) x.freeze() #process FILESYSTEM_ENCODING if not x.GLOBAL.FILESYSTEM_ENCODING: x.GLOBAL.FILESYSTEM_ENCODING = sys.getfilesystemencoding() or x.GLOBAL.DEFAULT_ENCODING return x
def get_settings(project_dir, include_apps=None, settings_file='settings.ini', local_settings_file='local_settings.ini', default_settings=None): settings = collect_settings(project_dir, include_apps, settings_file, local_settings_file) x = pyini.Ini(lazy=True, basepath=os.path.join(project_dir, 'apps')) for v in settings: x.read(v) d = dict([(k, repr(v)) for k, v in default_settings.items()]) x.update(d or {}) x.freeze() #process FILESYSTEM_ENCODING if not x.GLOBAL.FILESYSTEM_ENCODING: x.GLOBAL.FILESYSTEM_ENCODING = sys.getfilesystemencoding() or x.GLOBAL.DEFAULT_ENCODING return x
def get_app_depends(app, existed_apps=None): if existed_apps is None: s = set() else: s = existed_apps if app in s: raise StopIteration if isinstance(app, (tuple, list)): app, name = app __app_alias__[name+'.'] = app + '.' configfile = os.path.join(get_app_dir(app), 'config.ini') if os.path.exists(configfile): x = pyini.Ini(configfile) apps = x.get_var('DEPENDS/REQUIRED_APPS', []) for i in apps: if i not in s: for j in get_app_depends(i, s): yield j s.add(app) yield app
local_manager = LocalManager([local]) url_map = Map() static_views = [] use_urls = False url_adapters = {} __app_dirs__ = {} __app_alias__ = {} _xhr_redirect_json = True r_callback = re.compile(r'^[\w_]+$') #Initialize pyini env pyini.set_env({ 'env':{'_':gettext_lazy, 'gettext_lazy':gettext_lazy}, 'convertors':i18n_ini_convertor, }) __global__.settings = pyini.Ini(lazy=True) #User can defined decorator functions in settings DECORATORS #and user can user @decorators.function_name in views #and this usage need settings be initialized before decorator invoking class Finder(object): def __init__(self, section): self.__objects = {} self.__section = section def __contains__(self, name): if name in self.__objects: return True if name not in settings[self.__section]: return False
except: from sets import Set as set local = Local() __global__ = Global() local_manager = LocalManager([local]) url_map = Map() static_views = [] use_urls = False url_adapters = {} __app_dirs__ = {} __app_alias__ = {} #Initialize pyini env pyini.set_env({'_': gettext_lazy, 'gettext_lazy': gettext_lazy}) __global__.settings = pyini.Ini() #User can defined decorator functions in settings DECORATORS #and user can user @decorators.function_name in views #and this usage need settings be initialized before decorator invoking class Finder(object): def __init__(self, section): self.__objects = {} self.__section = section def __getattr__(self, name): if name in self.__objects: return self.__objects[name] if name not in settings[self.__section]: