X-Git-Url: http://vcs.maemo.org/git/?a=blobdiff_plain;f=ejpi%2Futil%2Flinux.py;fp=ejpi%2Futil%2Flinux.py;h=21bf959f7789f77f9bf104b6e22f11c8fde3d041;hb=28d4b14d856515ddc057f7a93726c473e89ccfbc;hp=4e77445d6f33c86a98e3529a1859c080d12de03a;hpb=99267d226da2d28d291a328ad255206c37c3c3e3;p=ejpi diff --git a/ejpi/util/linux.py b/ejpi/util/linux.py index 4e77445..21bf959 100644 --- a/ejpi/util/linux.py +++ b/ejpi/util/linux.py @@ -28,13 +28,13 @@ def set_process_name(name): _moduleLogger.warning('Unable to set processName: %s" % e') -def get_new_resource(resourceType, resource, name): +def _get_xdg_path(resourceType): if BaseDirectory is not None: if resourceType == "data": base = BaseDirectory.xdg_data_home if base == "/usr/share/mime": # Ugly hack because somehow Maemo 4.1 seems to be set to this - base = os.path.join(os.path.expanduser("~"), ".%s" % resource) + base = None elif resourceType == "config": base = BaseDirectory.xdg_config_home elif resourceType == "cache": @@ -42,10 +42,26 @@ def get_new_resource(resourceType, resource, name): else: raise RuntimeError("Unknown type: "+resourceType) else: + base = None + + return base + + +def get_resource_path(resourceType, resource, name = None): + base = _get_xdg_path(resourceType) + if base is not None: + dirPath = os.path.join(base, resource) + else: base = os.path.join(os.path.expanduser("~"), ".%s" % resource) + dirPath = base + if name is not None: + dirPath = os.path.join(dirPath, name) + return dirPath + - filePath = os.path.join(base, resource, name) - dirPath = os.path.dirname(filePath) +def get_new_resource(resourceType, resource, name): + dirPath = get_resource_path(resourceType, resource) + filePath = os.path.join(dirPath, name) if not os.path.exists(dirPath): # Looking before I leap to not mask errors os.makedirs(dirPath) @@ -54,17 +70,7 @@ def get_new_resource(resourceType, resource, name): def get_existing_resource(resourceType, resource, name): - if BaseDirectory is not None: - if resourceType == "data": - base = BaseDirectory.xdg_data_home - elif resourceType == "config": - base = BaseDirectory.xdg_config_home - elif resourceType == "cache": - base = BaseDirectory.xdg_cache_home - else: - raise RuntimeError("Unknown type: "+resourceType) - else: - base = None + base = _get_xdg_path(resourceType) if base is not None: finalPath = os.path.join(base, name)