-import os
-
__pretty_app_name__ = "Gonvert"
__app_name__ = "gonvert"
__version__ = "1.1.4"
__build__ = 3
__app_magic__ = 0xdeadbeef
-_data_path_ = os.path.join(os.path.expanduser("~"), ".%s" % __app_name__)
-_user_settings_ = "%s/settings.json" % _data_path_
-_user_logpath_ = "%s/%s.log" % (_data_path_, __app_name__)
PROFILE_STARTUP = False
IS_MAEMO = True
import constants
from util import qui_utils
from util import misc as misc_utils
+from util import linux as linux_utils
+
import unit_data
return self._hiddenUnits[categoryName]
def load_settings(self):
+ settingsPath = linux_utils.get_resource_path(
+ "config", constants.__app_name__, "settings.json"
+ )
try:
- with open(constants._user_settings_, "r") as settingsFile:
+ with open(settingsPath, "r") as settingsFile:
settings = simplejson.load(settingsFile)
except IOError, e:
_moduleLogger.info("No settings")
"useQuick": self._condensedAction.isChecked(),
"sortBy": sortBy,
}
- with open(constants._user_settings_, "w") as settingsFile:
+
+ settingsPath = linux_utils.get_resource_path(
+ "config", constants.__app_name__, "settings.json"
+ )
+ with open(settingsPath, "w") as settingsFile:
simplejson.dump(settings, settingsFile)
@property
@misc_utils.log_exception(_moduleLogger)
def _on_log(self, checked = False):
- with open(constants._user_logpath_, "r") as f:
+ logPath = linux_utils.get_resource_path(
+ "cache", self._constants.__app_name__, "%s.log" % self._constants.__app_name__
+ )
+ with open(logPath, "r") as f:
logLines = f.xreadlines()
log = "".join(logLines)
self._clipboard.setText(log)
def run_gonvert():
try:
- os.makedirs(constants._data_path_)
+ os.makedirs(linux_utils.get_resource_path("config", constants.__app_name__))
+ except OSError, e:
+ if e.errno != 17:
+ raise
+ try:
+ os.makedirs(linux_utils.get_resource_path("cache", constants.__app_name__))
+ except OSError, e:
+ if e.errno != 17:
+ raise
+ try:
+ os.makedirs(linux_utils.get_resource_path("data", constants.__app_name__))
except OSError, e:
if e.errno != 17:
raise
+ logPath = linux_utils.get_resource_path("cache", constants.__app_name__, "%s.log" % constants.__app_name__)
logFormat = '(%(relativeCreated)5d) %(levelname)-5s %(threadName)s.%(name)s.%(funcName)s: %(message)s'
logging.basicConfig(level=logging.DEBUG, format=logFormat)
- rotating = logging.handlers.RotatingFileHandler(constants._user_logpath_, maxBytes=512*1024, backupCount=1)
+ rotating = logging.handlers.RotatingFileHandler(logPath, maxBytes=512*1024, backupCount=1)
rotating.setFormatter(logging.Formatter(logFormat))
root = logging.getLogger()
root.addHandler(rotating)
_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":
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)
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)
import qui_utils
import misc as misc_utils
+import linux as linux_utils
_moduleLogger = logging.getLogger(__name__)
@misc_utils.log_exception(_moduleLogger)
def _on_log(self, checked = False):
with qui_utils.notify_error(self._errorLog):
- with open(self._constants._user_logpath_, "r") as f:
+ logPath = linux_utils.get_resource_path(
+ "cache", self._constants.__app_name__, "%s.log" % self._constants.__app_name__
+ )
+ with open(logPath, "r") as f:
logLines = f.xreadlines()
log = "".join(logLines)
self._clipboard.setText(log)
],
requires=[
"PySide",
+ "pyxdg",
"simplejson",
],
cmdclass={
"copyright": "gpl",
"changelog": CHANGES,
"buildversion": str(BUILD),
- "depends": "python, python-pyside.qtcore, python-pyside.qtgui, python-simplejson",
+ "depends": "python, python-pyside.qtcore, python-pyside.qtgui, python-xdg, python-simplejson",
"architecture": "any",
},
"sdist_diablo": {
"copyright": "gpl",
"changelog": CHANGES,
"buildversion": str(BUILD),
- "depends": "python2.5, python2.5-qt4-core, python2.5-qt4-gui, python-simplejson",
+ "depends": "python2.5, python2.5-qt4-core, python2.5-qt4-gui, python-xdg, python-simplejson",
"architecture": "any",
},
"sdist_fremantle": {
"copyright": "gpl",
"changelog": CHANGES,
"buildversion": str(BUILD),
- "depends": "python2.5, python2.5-qt4-core, python2.5-qt4-gui, python2.5-qt4-maemo5, python-simplejson",
- #"depends": "python, python-pyside.qtcore, python-pyside.qtgui, python-pyside.qtmaemo5, python-simplejson",
+ "depends": "python2.5, python2.5-qt4-core, python2.5-qt4-gui, python2.5-qt4-maemo5, python-xdg, python-simplejson",
+ #"depends": "python, python-pyside.qtcore, python-pyside.qtgui, python-pyside.qtmaemo5, python-xdg, python-simplejson",
"architecture": "any",
},
"sdist_harmattan": {
"copyright": "gpl",
"changelog": CHANGES,
"buildversion": str(BUILD),
- "depends": "python, python-pyside.qtcore, python-pyside.qtgui, python-simplejson",
+ "depends": "python, python-pyside.qtcore, python-pyside.qtgui, python-xdg, python-simplejson",
"architecture": "any",
},
"bdist_rpm": {