def __init__(self, path, themePath=None): self.config = util.read_simple_config_file(path) self.themeDir = os.path.join(ROOT_DIR, 'osx', 'build', 'theme') self.themeConfig = None if themePath is not None: self.extract_theme_content(themePath, self.themeDir) themeConfigPath = os.path.join(self.themeDir, "app.config") self.themeConfig = util.read_simple_config_file(themeConfigPath) elif os.path.exists(self.themeDir): shutil.rmtree(self.themeDir)
def __init__(self, theme=None): self.theme_vars = {} app_config_path = resources.path('app.config') self.default_vars = util.read_simple_config_file(app_config_path) self.load_theme(theme)
def load_theme(self, theme): if theme is not None: logging.info("Using theme %s", theme) theme_app_config = resources.theme_path(theme, 'app.config') try: self.theme_vars = util.read_simple_config_file(theme_app_config) except EnvironmentError: logging.warn("Error loading theme: %s\n%s", theme_app_config, traceback.format_exc())
def load_theme(self, theme): if theme is not None: logging.info("Using theme %s", theme) theme_app_config = resources.theme_path(theme, 'app.config') try: self.theme_vars = util.read_simple_config_file( theme_app_config) except EnvironmentError: logging.warn("Error loading theme: %s\n%s", theme_app_config, traceback.format_exc())
def test_write_simple_config_file(self): fn = os.path.join(self.tempdir, "temp.config") cfg = {"a": "b", "c": "d", "E": "F "} util.write_simple_config_file(fn, cfg) cfg2 = util.read_simple_config_file(fn) self.assertEquals(cfg2["a"], cfg["a"]) self.assertEquals(cfg2["c"], cfg["c"]) self.assertEquals(cfg2["E"], cfg["E"])
def install_app_config(self): source = os.path.join(resource_dir, 'app.config.template') dest = '/usr/share/miro/resources/app.config' config_file = util.read_simple_config_file(source) print "Trying to figure out the git revision...." if config_file["appVersion"].endswith("git"): revision = util.query_revision() if revision is None: revision = "unknown" revisionurl = "unknown" revisionnum = "unknown" else: revisionurl = revision[0] revisionnum = revision[1] revision = "%s - %s" % (revisionurl, revisionnum) else: revisionurl = "" revisionnum = "" revision = "" print "Using %s" % revisionnum if self.root: dest = change_root(self.root, dest) self.mkpath(os.path.dirname(dest)) # We don't use the dist utils copy_file() because it only copies # the file if the timestamp is newer shutil.copyfile(source, dest) expand_file_contents(dest, APP_REVISION=revision, APP_REVISION_NUM=revisionnum, APP_REVISION_URL=revisionurl, APP_PLATFORM='linux', BUILD_MACHINE="%s@%s" % (getlogin(), os.uname()[1]), BUILD_TIME=str(time.time()), MOZILLA_LIB_PATH="") self.outfiles.append(dest) locale_dir = os.path.join(resource_dir, "locale") for source in glob(os.path.join(locale_dir, "*.mo")): lang = os.path.basename(source)[:-3] if 'LINGUAS' in os.environ and lang not in os.environ['LINGUAS']: continue dest = '/usr/share/locale/%s/LC_MESSAGES/miro.mo' % lang if self.root: dest = change_root(self.root, dest) self.mkpath(os.path.dirname(dest)) self.copy_file(source, dest) self.outfiles.append(dest)
def install_app_config(self): source = os.path.join(resource_dir, 'app.config.template') dest = '/usr/share/miro/resources/app.config' config_file = util.read_simple_config_file(source) print "Trying to figure out the git revision...." if config_file["appVersion"].endswith("git"): revision = util.query_revision() if revision is None: revision = "unknown" revisionurl = "unknown" revisionnum = "unknown" else: revisionurl = revision[0] revisionnum = revision[1] revision = "%s - %s" % (revisionurl, revisionnum) else: revisionurl = "" revisionnum = "" revision = "" print "Using %s" % revisionnum if self.root: dest = change_root(self.root, dest) self.mkpath(os.path.dirname(dest)) # We don't use the dist utils copy_file() because it only copies # the file if the timestamp is newer shutil.copyfile(source, dest) expand_file_contents(dest, APP_REVISION=revision, APP_REVISION_NUM=revisionnum, APP_REVISION_URL=revisionurl, APP_PLATFORM='linux', BUILD_MACHINE="%s@%s" % (getlogin(), os.uname()[1]), BUILD_TIME=str(time.time()), MOZILLA_LIB_PATH="") self.outfiles.append(dest) locale_dir = os.path.join (resource_dir, "locale") for source in glob (os.path.join (locale_dir, "*.mo")): lang = os.path.basename(source)[:-3] if 'LINGUAS' in os.environ and lang not in os.environ['LINGUAS']: continue dest = '/usr/share/locale/%s/LC_MESSAGES/miro.mo' % lang if self.root: dest = change_root(self.root, dest) self.mkpath(os.path.dirname(dest)) self.copy_file(source, dest) self.outfiles.append(dest)
def test_read_simple_config_file(self): fn = os.path.join(self.tempdir, "temp.config") f = open(fn, "w") f.write(""" a = b c = dSSS E = F """.strip().replace("S", " ")) f.close() cfg = util.read_simple_config_file(fn) self.assertEquals(cfg["a"], "b") self.assertEquals(cfg["c"], "d ") self.assertEquals(cfg["E"], "F") self.assertEquals(cfg.get("G"), None)
# insert the root_dir to the beginning of sys.path so that we can # pick up portable and other packages sys.path.insert(0, root_dir) # later when we install the portable modules, they will be in the miro # package, but at this point, they are in a package named "lib", so # let's hack it import lib sys.modules['miro'] = lib import plat sys.modules['miro'].plat = plat # little hack to get the version from the current app.config.template from miro import util app_config = os.path.join(resource_dir, 'app.config.template') appVersion = util.read_simple_config_file(app_config)['appVersion'] # RPM hack if 'bdist_rpm' in sys.argv: appVersion = appVersion.replace('-', '_') def getlogin(): """Does a best-effort attempt to return the login of the user running the script. """ try: return os.environ['LOGNAME'] except KeyError: pass try: return os.environ['USER']
locale_files.append((source, dest)) dir_util.create_tree(os.path.dirname(__file__), [dst for src, dst in locale_files]) for source, dest in locale_files: file_util.copy_file(source, dest, update=True, verbose=True) # FIXME - this should be done inside a build command copy_locale_files() data_files.extend( find_data_files(os.path.join("resources", "locale"), locale_temp_dir)) app_config = os.path.join(resources_dir, 'app.config.template') template_vars = util.read_simple_config_file(app_config) # pixmap for the about dialog icon_path = os.path.join("icons", "hicolor", "128x128", "apps") data_files.append((os.path.join("resources", icon_path), [os.path.join(platform_dir, icon_path, "miro.png")])) ########################################################################### #### Our specialized install_data command #### class install_data(distutils.command.install_data.install_data): """install_data extends to default implementation so that it automatically installs app.config from app.config.template. """ def install_app_config(self):
# insert the root_dir to the beginning of sys.path so that we can # pick up portable and other packages sys.path.insert(0, root_dir) # later when we install the portable modules, they will be in the miro # package, but at this point, they are in a package named "lib", so # let's hack it import lib sys.modules['miro'] = lib import plat sys.modules['miro'].plat = plat # little hack to get the version from the current app.config.template from miro import util app_config = os.path.join(resource_dir, 'app.config.template') appVersion = util.read_simple_config_file(app_config)['appVersion'] # RPM hack if 'bdist_rpm' in sys.argv: appVersion = appVersion.replace('-', '_') def getlogin(): """Does a best-effort attempt to return the login of the user running the script. """ try: return os.environ['LOGNAME'] except KeyError: pass try:
dest = os.path.join(locale_temp_dir, lang, "LC_MESSAGES", "miro.mo") locale_files.append((source, dest)) dir_util.create_tree(os.path.dirname(__file__), [dst for src, dst in locale_files]) for source, dest in locale_files: file_util.copy_file(source, dest, update=True, verbose=True) # FIXME - this should be done inside a build command copy_locale_files() data_files.extend(find_data_files(os.path.join("resources", "locale"), locale_temp_dir)) app_config = os.path.join(resources_dir, 'app.config.template') template_vars = util.read_simple_config_file(app_config) # pixmap for the about dialog icon_path = os.path.join("icons", "hicolor", "128x128", "apps") data_files.append((os.path.join("resources", icon_path), [os.path.join(platform_dir, icon_path, "miro.png")])) ########################################################################### #### Our specialized install_data command #### class install_data(distutils.command.install_data.install_data): """install_data extends to default implementation so that it automatically installs app.config from app.config.template. """ def install_app_config(self): template = os.path.join(resources_dir, 'app.config.template')