#!/usr/bin/env python
+from __future__ import with_statement
+
import os
import time
import datetime
import ConfigParser
import logging
+import dbus
+
import util.qt_compat as qt_compat
QtCore = qt_compat.QtCore
-import dbus
+from util import linux as linux_utils
_FREMANTLE_ALARM = "Fremantle"
parser.add_option("-r", "--recurrence", action="store", type="int", dest="recurrence", help="How often the alarm occurs", default=5)
(commandOptions, commandArgs) = parser.parse_args()
+ settingsPath = linux_utils.get_resource_path("config", constants.__app_name__, "settings.ini")
+
alarmHandler = AlarmHandler()
config = ConfigParser.SafeConfigParser()
- config.read(constants._user_settings_)
+ config.read(settingsPath)
alarmHandler.load_settings(config, "alarm")
if commandOptions.display:
alarmHandler.apply_settings(isEnabled, recurrence)
alarmHandler.save_settings(config, "alarm")
- configFile = open(constants._user_settings_, "wb")
- try:
+ with open(settingsPath, "wb") as configFile:
config.write(configFile)
- finally:
- configFile.close()
if __name__ == "__main__":
import logging.handlers
import constants
+from util import linux as linux_utils
from backends.gvoice import gvoice
+CACHE_PATH = linux_utils.get_resource_path("cache", constants.__app_name__)
+
+
def get_missed(backend):
missedPage = backend._browser.download(backend._XML_MISSED_URL)
missedJson = backend._grab_json(missedPage)
jsonMaterial = get_material(backend)
unreadCount = jsonMaterial["unreadCounts"][type]
- previousSnapshotPath = os.path.join(constants._data_path_, "snapshot_%s.old.json" % type)
- currentSnapshotPath = os.path.join(constants._data_path_, "snapshot_%s.json" % type)
+ previousSnapshotPath = os.path.join(CACHE_PATH, "snapshot_%s.old.json" % type)
+ currentSnapshotPath = os.path.join(CACHE_PATH, "snapshot_%s.json" % type)
try:
os.remove(previousSnapshotPath)
def create_backend(config):
- gvCookiePath = os.path.join(constants._data_path_, "gv_cookies.txt")
+ gvCookiePath = os.path.join(CACHE_PATH, "gv_cookies.txt")
backend = gvoice.GVoiceBackend(gvCookiePath)
loggedIn = False
def notify_on_change():
+ settingsPath = linux_utils.get_resource_path("config", constants.__app_name__, "settings.ini")
+
config = ConfigParser.SafeConfigParser()
- config.read(constants._user_settings_)
+ config.read(settingsPath)
backend = create_backend(config)
notifyUser = is_changed(config, backend)
if __name__ == "__main__":
+ notifierPath = os.path.join(CACHE_PATH, "notifier.log")
+
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._notifier_logpath_, maxBytes=512*1024, backupCount=1)
+ rotating = logging.handlers.RotatingFileHandler(notifierPath, maxBytes=512*1024, backupCount=1)
rotating.setFormatter(logging.Formatter(logFormat))
root = logging.getLogger()
root.addHandler(rotating)
-import os
-
__pretty_app_name__ = "DialCentral"
__app_name__ = "dialcentral"
__version__ = "1.3.6"
__build__ = 0
__app_magic__ = 0xdeadbeef
-_data_path_ = os.path.join(os.path.expanduser("~"), ".%s" % __app_name__)
-_user_settings_ = "%s/settings.ini" % _data_path_
-_custom_notifier_settings_ = "%s/notifier.ini" % _data_path_
-_user_logpath_ = "%s/%s.log" % (_data_path_, __app_name__)
-_notifier_logpath_ = "%s/notifier.log" % _data_path_
IS_MAEMO = True
from util import qtpie
from util import qwrappers
from util import qui_utils
+from util import linux as linux_utils
from util import misc as misc_utils
import session
def load_settings(self):
try:
+ settingsPath = linux_utils.get_resource_path("config", constants.__app_name__, "settings.ini")
config = ConfigParser.SafeConfigParser()
- config.read(constants._user_settings_)
+ config.read(settingsPath)
except IOError, e:
_moduleLogger.info("No settings")
return
self._mainWindow.save_settings(config)
- with open(constants._user_settings_, "wb") as configFile:
+ settingsPath = linux_utils.get_resource_path("config", constants.__app_name__, "settings.ini")
+ with open(settingsPath, "wb") as configFile:
config.write(configFile)
def get_icon(self, name):
@property
def fsContactsPath(self):
- return os.path.join(constants._data_path_, "contacts")
+ return linux_utils.get_resource_path("data", constants.__app_name__, "contacts")
@property
def streamHandler(self):
self._window.resized.connect(self._on_window_resized)
self._errorLog = self._app.errorLog
- self._session = session.Session(self._errorLog, constants._data_path_)
+ cachePath = linux_utils.get_resource_path("cache", constants.__app_name__)
+ self._session = session.Session(self._errorLog, cachePath)
self._session.error.connect(self._on_session_error)
self._session.loggedIn.connect(self._on_login)
self._session.loggedOut.connect(self._on_logout)
orientation = config.get(constants.__pretty_app_name__, "orientation")
except ConfigParser.NoOptionError, e:
_moduleLogger.info(
- "Settings file %s is missing option %s" % (
- constants._user_settings_,
+ "Settings file is missing option %s" % (
e.option,
),
)
except ConfigParser.NoSectionError, e:
_moduleLogger.info(
- "Settings file %s is missing section %s" % (
- constants._user_settings_,
+ "Settings file is missing section %s" % (
e.section,
),
)
self._updateVoicemailOnMissedCall = config.getboolean("2 - Account Info", "updateVoicemailOnMissedCall")
except ConfigParser.NoOptionError, e:
_moduleLogger.info(
- "Settings file %s is missing option %s" % (
- constants._user_settings_,
+ "Settings file is missing option %s" % (
e.option,
),
)
except ConfigParser.NoSectionError, e:
_moduleLogger.info(
- "Settings file %s is missing section %s" % (
- constants._user_settings_,
+ "Settings file is missing section %s" % (
e.section,
),
)
settingValue = config.get(sectionName, settingName)
except ConfigParser.NoOptionError, e:
_moduleLogger.info(
- "Settings file %s is missing section %s" % (
- constants._user_settings_,
+ "Settings file is missing section %s" % (
e.section,
),
)
return
except ConfigParser.NoSectionError, e:
_moduleLogger.info(
- "Settings file %s is missing section %s" % (
- constants._user_settings_,
+ "Settings file is missing section %s" % (
e.section,
),
)
def run():
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)
from __future__ import with_statement
-import sys
import datetime
import ConfigParser
-
-sys.path.insert(0,"/usr/lib/dialcentral/")
-
-
-import constants
-import alarm_notify
+from dialcentral import constants
+from dialcentral.util import linux as linux_utils
+from dialcentral import alarm_notify
def notify_on_change():
- with open(constants._notifier_logpath_, "a") as file:
+ notifierLogPath = linux_utils.get_resource_path("cache", constants.__app_name__, "notifier.log")
+ settingsPath = linux_utils.get_resource_path("config", constants.__app_name__, "settings.ini")
+ with open(notifierLogPath, "a") as file:
file.write("Notification: %r\n" % (datetime.datetime.now(), ))
config = ConfigParser.SafeConfigParser()
- config.read(constants._user_settings_)
+ config.read(settingsPath)
backend = alarm_notify.create_backend(config)
notifyUser = alarm_notify.is_changed(config, backend)
#!/usr/bin/env python
import os
-import sys
import ConfigParser
import logging
-sys.path.insert(0,"/usr/lib/dialcentral/")
-
-
-import constants
-import alarm_notify
+from dialcentral import constants
+from dialcentral.util import linux as linux_utils
+from dialcentral import alarm_notify
def notify_on_change():
+ settingsPath = linux_utils.get_resource_path("config", constants.__app_name__, "settings.ini")
+ notifierSettingsPath = linux_utils.get_resource_path("config", constants.__app_name__, "notifier.ini")
+
config = ConfigParser.SafeConfigParser()
- config.read(constants._user_settings_)
+ config.read(settingsPath)
backend = alarm_notify.create_backend(config)
notifyUser = alarm_notify.is_changed(config, backend)
config = ConfigParser.SafeConfigParser()
- config.read(constants._custom_notifier_settings_)
+ config.read(notifierSettingsPath)
soundFile = config.get("Sound Notifier", "soundfile")
soundFile = "/usr/lib/gv-notifier/alert.mp3"
if __name__ == "__main__":
- logging.basicConfig(level=logging.WARNING, filename=constants._notifier_logpath_)
+ notifierLogPath = linux_utils.get_resource_path("cache", constants.__app_name__, "notifier.log")
+
+ logging.basicConfig(level=logging.WARNING, filename=notifierLogPath)
logging.info("Sound Notifier %s-%s" % (constants.__version__, constants.__build__))
logging.info("OS: %s" % (os.uname()[0], ))
logging.info("Kernel: %s (%s) for %s" % os.uname()[2:])
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)