_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
_moduleLogger = logging.getLogger(__name__)
-IS_MAEMO = True
class Dialcentral(object):
for tabIndex, (tabTitle, tabIcon) in enumerate(
zip(self._TAB_TITLES, self._TAB_ICONS)
):
- if IS_MAEMO:
+ if constants.IS_MAEMO:
icon = self._app.get_icon(tabIcon)
if icon is None:
self._tabWidget.addTab(self._tabsContents[tabIndex].toplevel, tabTitle)
self._closeWindowAction.setShortcut(QtGui.QKeySequence("CTRL+w"))
self._closeWindowAction.triggered.connect(self._on_close_window)
- if IS_MAEMO:
+ if constants.IS_MAEMO:
fileMenu = self._window.menuBar().addMenu("&File")
fileMenu.addAction(self._loginTabAction)
fileMenu.addAction(self._refreshTabAction)
def close(self):
for child in self.walk_children():
+ child.window.destroyed.disconnect(self._on_child_close)
child.close()
self._window.close()
import pickle
import contextlib
import itertools
-import functools
+import codecs
+import csv
+try:
+ import cStringIO as StringIO
+except ImportError:
+ import StringIO
@contextlib.contextmanager
return os.path.join(*relParts)
else:
return "."+os.sep
+
+
+class UTF8Recoder(object):
+ """
+ Iterator that reads an encoded stream and reencodes the input to UTF-8
+ """
+ def __init__(self, f, encoding):
+ self.reader = codecs.getreader(encoding)(f)
+
+ def __iter__(self):
+ return self
+
+ def next(self):
+ return self.reader.next().encode("utf-8")
+
+
+class UnicodeReader(object):
+ """
+ A CSV reader which will iterate over lines in the CSV file "f",
+ which is encoded in the given encoding.
+ """
+
+ def __init__(self, f, dialect=csv.excel, encoding="utf-8", **kwds):
+ f = UTF8Recoder(f, encoding)
+ self.reader = csv.reader(f, dialect=dialect, **kwds)
+
+ def next(self):
+ row = self.reader.next()
+ return [unicode(s, "utf-8") for s in row]
+
+ def __iter__(self):
+ return self
+
+class UnicodeWriter(object):
+ """
+ A CSV writer which will write rows to CSV file "f",
+ which is encoded in the given encoding.
+ """
+
+ def __init__(self, f, dialect=csv.excel, encoding="utf-8", **kwds):
+ # Redirect output to a queue
+ self.queue = StringIO.StringIO()
+ self.writer = csv.writer(self.queue, dialect=dialect, **kwds)
+ self.stream = f
+ self.encoder = codecs.getincrementalencoder(encoding)()
+
+ def writerow(self, row):
+ self.writer.writerow([s.encode("utf-8") for s in row])
+ # Fetch UTF-8 output from the queue ...
+ data = self.queue.getvalue()
+ data = data.decode("utf-8")
+ # ... and reencode it into the target encoding
+ data = self.encoder.encode(data)
+ # write to the target stream
+ self.stream.write(data)
+ # empty queue
+ self.queue.truncate(0)
+
+ def writerows(self, rows):
+ for row in rows:
+ self.writerow(row)
+
+
+def unicode_csv_reader(unicode_csv_data, dialect=csv.excel, **kwargs):
+ # csv.py doesn't do Unicode; encode temporarily as UTF-8:
+ csv_reader = csv.reader(utf_8_encoder(unicode_csv_data),
+ dialect=dialect, **kwargs)
+ for row in csv_reader:
+ # decode UTF-8 back to Unicode, cell by cell:
+ yield [unicode(cell, 'utf-8') for cell in row]
+
+
+def utf_8_encoder(unicode_csv_data):
+ for line in unicode_csv_data:
+ yield line.encode('utf-8')
#!/usr/bin/env python
+import os
import logging
+try:
+ from xdg import BaseDirectory as _BaseDirectory
+ BaseDirectory = _BaseDirectory
+except ImportError:
+ BaseDirectory = None
+
+
+_moduleLogger = logging.getLogger(__name__)
+
+
+_libc = None
+
def set_process_name(name):
try: # change process name for killall
- import ctypes
- libc = ctypes.CDLL('libc.so.6')
- libc.prctl(15, name, 0, 0, 0)
+ global _libc
+ if _libc is None:
+ import ctypes
+ _libc = ctypes.CDLL('libc.so.6')
+ _libc.prctl(15, name, 0, 0, 0)
except Exception, e:
- logging.warning('Unable to set processName: %s" % e')
+ _moduleLogger.warning('Unable to set processName: %s" % e')
+
+
+def get_new_resource(resourceType, resource, name):
+ 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)
+ elif resourceType == "config":
+ base = BaseDirectory.xdg_config_home
+ elif resourceType == "cache":
+ base = BaseDirectory.xdg_cache_home
+ else:
+ raise RuntimeError("Unknown type: "+resourceType)
+ else:
+ base = os.path.join(os.path.expanduser("~"), ".%s" % resource)
+
+ filePath = os.path.join(base, resource, name)
+ dirPath = os.path.dirname(filePath)
+ if not os.path.exists(dirPath):
+ # Looking before I leap to not mask errors
+ os.makedirs(dirPath)
+
+ return filePath
+
+
+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
+
+ if base is not None:
+ finalPath = os.path.join(base, name)
+ if os.path.exists(finalPath):
+ return finalPath
+
+ altBase = os.path.join(os.path.expanduser("~"), ".%s" % resource)
+ finalPath = os.path.join(altBase, name)
+ if os.path.exists(finalPath):
+ return finalPath
+ else:
+ raise RuntimeError("Resource not found: %r" % ((resourceType, resource, name), ))
self._didReport = False
self._onTimeout = gobject_utils.Timeout(self._on_timeout)
- self._onTimeout.start(seconds=10)
+ self._onTimeout.start(seconds=60)
chan[telepathy.interfaces.CHANNEL_INTERFACE_GROUP].connect_to_signal(
"MembersChanged",
p["/usr/share/icons/hicolor/64x64/hildon"] = ["64x64-dialcentral.png|dialcentral.png"]
p["/usr/share/icons/hicolor/scalable/hildon"] = ["scale-dialcentral.png|dialcentral.png"]
+ print p
if distribution == "debian":
- print p
print p.generate(
version="%s-%s" % (__version__, __build__),
changelog=__changelog__,
changes=False,
dsc=False,
)
- print "Building for %s finished" % distribution
else:
- print p
print p.generate(
version="%s-%s" % (__version__, __build__),
changelog=__changelog__,
changes=True,
dsc=True,
)
- print "Building for %s finished" % distribution
+ print "Building for %s finished" % distribution
if __name__ == "__main__":
- if len(sys.argv) > 1:
- try:
- import optparse
- except ImportError:
- optparse = None
-
- if optparse is not None:
- parser = optparse.OptionParser()
- (commandOptions, commandArgs) = parser.parse_args()
+ if len(sys.argv) == 1:
+ distribution = "fremantle"
else:
- commandArgs = None
- commandArgs = ["diablo"]
- build_package(commandArgs[0])
+ distribution = sys.argv[1]
+ build_package(distribution)