Example #1
0
    def __init__(self, lang_override=None):

        #L_O_G.info('init spellchecker')

        self.spellengine = None
        self.lang = None
        self._need_to_download = None
        self.currentDownloads = set()
        self.expectedNext = None

        # load YAML file describing the dictionaries

        filename = program_dir() / 'res' / ('dictionaries-%s.yaml' %
                                            Aspell.VERSION)
        try:
            with open(filename) as f:
                self.dict_info = syck.load(f)
                if not isinstance(self.dict_info, dict):
                    raise ValueError('invalid YAML in %s' % filename)
        except Exception:
            print_exc()
            self.dict_info = {}

        # load an engine using swap engine, if no engine is failed use the NullSpellEngine
        if not self.SwapEngine(lang_override):
            self.spellengine = NullSpellEngine()

        profile.prefs.add_observer(
            self.on_prefs_change,  #@UndefinedVariable
            'messaging.spellcheck.enabled',
            'messaging.spellcheck.engineoptions.lang',
            'messaging.spellcheck.engineoptions.encoding',
            'messaging.spellcheck.engineoptions.keyboard',
            'messaging.spellcheck.engineoptions.sug-mode')  #@UndefinedVariable
Example #2
0
    def check_manifest_integrity(self, req, resp):
        headers = resp.headers

        rmtime = headers.get('x-amz-meta-mtime', None)

        if rmtime is None:
            rmtime = headers.get('last-modified', None)
            if rmtime is not None:
                rmtime = net.http_date_to_timestamp(rmtime)

        if rmtime is not None:
            try:
                rmtime = int(rmtime)
            except (TypeError, ValueError):
                rmtime = None

        prog_dir = util.program_dir()
        self.local_manifest_path = path.path(prog_dir) / path.path(self.remote_manifest_path).splitpath()[-1]

        needs_update = True

        if self.local_manifest_path.isfile():
            lmtime = int(self.local_manifest_path.mtime)
        else:
            lmtime = 0

        if sys.opts.force_update or lmtime != rmtime:
            log.info("MTime mismatch or sys.opts.force_update is True. Downloading manifest. (local=%r, remote=%r)", lmtime, rmtime)
            downloader.httpopen(self.remote_manifest_path, success = self.got_manifest_response, error = self.manifest_request_error)
        else:
            log.info("Local MTime matches remote. Not downloading manifest. (local=%r, remote=%r)", lmtime, rmtime)
            self.update_check_complete(False, None)
Example #3
0
def LoadDigsbyInfo(site_path = 'http://update.digsby.com/', callback = None):

    feature_name = 'digsby'

    import features.featuresite as FS
    import features.pluginresource as PR
    import util
    feature_site = FS.DigsbyFeatureSite(feature_name, 'update.yaml', site_path, 'digsby-1_0_0', feature_name,
                                        updatesite = site_path, localdir = util.program_dir())

    def _after_load_feature(*a):
        plugin_site = feature_site.get_plugin_site(config.platform, sys.TAG)

        def _after_load_plugin(*a):
            plugin_site.content = {'plugins':
                                   {feature_name:
                                    {'dist_types': ['manifest'],
                                     'manifest': {'location': plugin_site.remote.content_location},
                                     'meta' : ''}}}

            plugin_info = plugin_site.get_plugin_info(feature_name)
            distribution_info = plugin_info.get_best_distribution()

            #dist_info = feature_site.get_plugin_site('win', 'release').get_plugin_info('digsby').get_distribution('manifest')

            distribution_info.load(callback = callback)

        plugin_site.load(success = _after_load_plugin, error = callback.error)
    feature_site.load(success = _after_load_feature, error = callback.error)
    return feature_site
Example #4
0
    def __init__(self, lang_override=None):

        # L_O_G.info('init spellchecker')

        self.spellengine = None
        self.lang = None
        self._need_to_download = None
        self.currentDownloads = set()
        self.expectedNext = None

        # load YAML file describing the dictionaries

        filename = program_dir() / "res" / ("dictionaries-%s.yaml" % Aspell.VERSION)
        try:
            with open(filename) as f:
                self.dict_info = syck.load(f)
                if not isinstance(self.dict_info, dict):
                    raise ValueError("invalid YAML in %s" % filename)
        except Exception:
            print_exc()
            self.dict_info = {}

        # load an engine using swap engine, if no engine is failed use the NullSpellEngine
        if not self.SwapEngine(lang_override):
            self.spellengine = NullSpellEngine()

        profile.prefs.add_observer(
            self.on_prefs_change,  # @UndefinedVariable
            "messaging.spellcheck.enabled",
            "messaging.spellcheck.engineoptions.lang",
            "messaging.spellcheck.engineoptions.encoding",
            "messaging.spellcheck.engineoptions.keyboard",
            "messaging.spellcheck.engineoptions.sug-mode",
        )  # @UndefinedVariable
Example #5
0
    def __init__(self, local_dir = None, temp_dir = None, manifest_path = None, manifest_data = None,
                 whitelist = None):

        self.cancelling = False
        self.fast_mode = False
        self.quiet_mode = False
        self.unchecked_files = None
        self.delete_files = []
        self.update_files = []
        self.good_files = []

        if local_dir is None:
            local_dir = util.program_dir()
        if manifest_path is None:
            manifest_path =  local_dir / 'manifest'
        if manifest_data is None and manifest_path.isfile():
            manifest_data = manifest_path.bytes()

        self.manifest_path = manifest_path
        self.temp_dir = temp_dir or path.path(GetUserTempDir())
        self.local_dir = local_dir

        self.got_manifest_data(manifest_data)

        if whitelist is not None:
            self.whitelist = set(whitelist)

        known_files = set((self.local_dir/file.path).abspath() for file in self.unchecked_files)
        known_files.update((self.local_dir / file).abspath() for file in self.whitelist)
        self.delete_files = Cleanup(self.local_dir, known_files)
        self.callback = None
Example #6
0
 def _cache_parts(self, temp):
     import util
     import digsby_updater.file_integrity as FI
     self._location = './manifest'
     if temp:
         return (FI.GetUserTempDir(), self._location)
     else:
         return (util.program_dir(), self._location)
Example #7
0
 def _cache_parts(self, temp):
     import util
     import digsby_updater.file_integrity as FI
     self._location = './manifest'
     if temp:
         return (FI.GetUserTempDir(), self._location)
     else:
         return (util.program_dir(), self._location)
Example #8
0
def _get_release_notes():
    try:
        with open(util.program_dir() / 'res' / "release_notes.html", 'rb') as f:
            data = f.read()

        return data
    except Exception, e:
        log.error("Release notes not found. %r", e)
        return ''
Example #9
0
def _get_release_notes():
    try:
        with open(util.program_dir() / 'res' / "release_notes.html",
                  'rb') as f:
            data = f.read()

        return data
    except Exception, e:
        log.error("Release notes not found. %r", e)
        return ''
Example #10
0
    def prepare_data(self, fast = False):
        meths = [getattr(self, meth) for meth in filter(lambda k: not k.startswith('_'),
                                                           self.__class__.__dict__.keys())]
        meths = filter((lambda meth: hasattr(meth, 'priority')), meths)

        if fast:
            meths = filter((lambda meth: not getattr(meth, 'slow', False)), meths)

        meths.sort(key = attrgetter('priority'))

        for meth in meths:
            arg_name = getattr(meth, 'arg_name', False)
            file_name = getattr(meth, 'file_name', False)
            raw_args = getattr(meth, 'raw_args', False)
            raw_files = getattr(meth, 'raw_files', False)

            if not any((arg_name, file_name, raw_args, raw_files)):
                continue

            try:
                INFO('diagnostic func: %r', meth.__name__)
                val = meth()
            except Exception:
                print_exc()
                val = format_exc()
            else:
                if raw_args:
                    self.prepared_args.update(val)
                if raw_files:
                    self.prepared_files.update(val)

            if arg_name or file_name:
                if arg_name:  self.prepared_args[arg_name]   = val
                if file_name: self.prepared_files[file_name] = val

        pdir = program_dir()
        self.fnames = self.fnames + \
                      [(pdir/'digsby_updater.log', 'digsby_updater.log'),
                       (pdir/'digsby.exe.log', 'digsby.exe.log'),
                       (pdir/'digsby_post_update.log', 'digsby_post_update.log')]

        # also include wx log message
        with traceguard:
            if hasattr(sys, 'STDERR_LOGFILE'):
                errfile = sys.STDERR_LOGFILE
                self.fnames.append((errfile, os.path.basename(errfile)))

        with traceguard:
            cstderr = getattr(sys, 'CSTDERR_FILE', None)
            if cstderr is not None:
                self.fnames.append((cstderr, os.path.basename(cstderr)))
Example #11
0
    def get_manifest_path(self):
        '''
        Figure out where the manfiest is supposed to be. Since this may make an HTTP request, control flow
        continues asynchronously into got_updateyaml(file_obj).
        '''
        program_dir = util.program_dir()

        local_info_file = program_dir / 'update.yaml'
        if local_info_file.isfile():
            try:
                local_info = open(local_info_file, 'rb')
            except Exception:
                pass
            else:
                self.got_updateyaml(fobj = local_info)
                return

        log.info("Manifest path not found in %r. checking web for update.yaml", local_info_file)
        asynchttp.httpopen("http://update.digsby.com/update.yaml?%s" % int(time.time()), success = self.got_updateyaml, error = self.manifest_path_error)
Example #12
0
def LoadDigsbyInfo(site_path='http://update.digsby.com/', callback=None):

    feature_name = 'digsby'

    import features.featuresite as FS
    import features.pluginresource as PR
    import util
    feature_site = FS.DigsbyFeatureSite(feature_name,
                                        'update.yaml',
                                        site_path,
                                        'digsby-1_0_0',
                                        feature_name,
                                        updatesite=site_path,
                                        localdir=util.program_dir())

    def _after_load_feature(*a):
        plugin_site = feature_site.get_plugin_site(config.platform, sys.TAG)

        def _after_load_plugin(*a):
            plugin_site.content = {
                'plugins': {
                    feature_name: {
                        'dist_types': ['manifest'],
                        'manifest': {
                            'location': plugin_site.remote.content_location
                        },
                        'meta': ''
                    }
                }
            }

            plugin_info = plugin_site.get_plugin_info(feature_name)
            distribution_info = plugin_info.get_best_distribution()

            #dist_info = feature_site.get_plugin_site('win', 'release').get_plugin_info('digsby').get_distribution('manifest')

            distribution_info.load(callback=callback)

        plugin_site.load(success=_after_load_plugin, error=callback.error)

    feature_site.load(success=_after_load_feature, error=callback.error)
    return feature_site
Example #13
0
def get_client_tag():
    if getattr(sys, 'DEV', False):
        tag = ''
    else:
        tag = 'release'

    tag_fname = 'tag.yaml'
    for fpath in ((stdpaths.userlocaldata / tag_fname), (util.program_dir() / tag_fname)):
        try:
            # If the location or name of this file changes, also update the installer (DigsbyInstaller/DigsbyInstall.nsi)
            # since it deletes it.
            with open(fpath, 'rb') as f:
                yaml = syck.load(f)
                tag = yaml['tag']

        except Exception, e:
            log.debug('Didn\'t get a release tag from %r: %r', fpath, e)
        else:
            log.info("Got release tag %r from %r", tag, fpath)
            break
Example #14
0
    def for_feature(cls, feat, meta_filepath="./update.yaml", remote_root=None):
        if feat.feature_id == "digsby":
            import util

            assert cls is DigsbyFeatureSite
            remote_path = "http://update.digsby.com/"
            local_path = util.program_dir()
        else:
            remote_path = feat.remote_path
            local_path = feat.local_path

        return cls(
            feat.feature_id,
            meta_filepath,
            remote_path,
            feat.platform_version,
            feat.feature_id,
            localdir=local_path,
            updatesite=feat.updatesite,
        )
Example #15
0
def get_client_tag():
    if getattr(sys, 'DEV', False):
        tag = ''
    else:
        tag = 'release'

    tag_fname = 'tag.yaml'
    for fpath in ((stdpaths.userlocaldata / tag_fname),
                  (util.program_dir() / tag_fname)):
        try:
            # If the location or name of this file changes, also update the installer (DigsbyInstaller/DigsbyInstall.nsi)
            # since it deletes it.
            with open(fpath, 'rb') as f:
                yaml = syck.load(f)
                tag = yaml['tag']

        except Exception, e:
            log.debug('Didn\'t get a release tag from %r: %r', fpath, e)
        else:
            log.info("Got release tag %r from %r", tag, fpath)
            break
Example #16
0
    def for_feature(cls,
                    feat,
                    meta_filepath='./update.yaml',
                    remote_root=None):
        if feat.feature_id == 'digsby':
            import util
            assert cls is DigsbyFeatureSite
            remote_path = 'http://update.digsby.com/'
            local_path = util.program_dir()
        else:
            remote_path = feat.remote_path
            local_path = feat.local_path

        return cls(
            feat.feature_id,
            meta_filepath,
            remote_path,
            feat.platform_version,
            feat.feature_id,
            localdir=local_path,
            updatesite=feat.updatesite,
        )
Example #17
0
    def check_manifest_integrity(self, req, resp):
        headers = resp.headers

        rmtime = headers.get('x-amz-meta-mtime', None)

        if rmtime is None:
            rmtime = headers.get('last-modified', None)
            if rmtime is not None:
                rmtime = net.http_date_to_timestamp(rmtime)

        if rmtime is not None:
            try:
                rmtime = int(rmtime)
            except (TypeError, ValueError):
                rmtime = None

        prog_dir = util.program_dir()
        self.local_manifest_path = path.path(prog_dir) / path.path(
            self.remote_manifest_path).splitpath()[-1]

        needs_update = True

        if self.local_manifest_path.isfile():
            lmtime = int(self.local_manifest_path.mtime)
        else:
            lmtime = 0

        if sys.opts.force_update or lmtime != rmtime:
            log.info(
                "MTime mismatch or sys.opts.force_update is True. Downloading manifest. (local=%r, remote=%r)",
                lmtime, rmtime)
            downloader.httpopen(self.remote_manifest_path,
                                success=self.got_manifest_response,
                                error=self.manifest_request_error)
        else:
            log.info(
                "Local MTime matches remote. Not downloading manifest. (local=%r, remote=%r)",
                lmtime, rmtime)
            self.update_check_complete(False, None)
Example #18
0
    def get_manifest_path(self):
        '''
        Figure out where the manfiest is supposed to be. Since this may make an HTTP request, control flow
        continues asynchronously into got_updateyaml(file_obj).
        '''
        program_dir = util.program_dir()

        local_info_file = program_dir / 'update.yaml'
        if local_info_file.isfile():
            try:
                local_info = open(local_info_file, 'rb')
            except Exception:
                pass
            else:
                self.got_updateyaml(fobj=local_info)
                return

        log.info("Manifest path not found in %r. checking web for update.yaml",
                 local_info_file)
        asynchttp.httpopen("http://update.digsby.com/update.yaml?%s" %
                           int(time.time()),
                           success=self.got_updateyaml,
                           error=self.manifest_path_error)
Example #19
0
    def __init__(self,
                 local_dir=None,
                 temp_dir=None,
                 manifest_path=None,
                 manifest_data=None,
                 whitelist=None):

        self.cancelling = False
        self.fast_mode = False
        self.quiet_mode = False
        self.unchecked_files = None
        self.delete_files = []
        self.update_files = []
        self.good_files = []

        if local_dir is None:
            local_dir = util.program_dir()
        if manifest_path is None:
            manifest_path = local_dir / 'manifest'
        if manifest_data is None and manifest_path.isfile():
            manifest_data = manifest_path.bytes()

        self.manifest_path = manifest_path
        self.temp_dir = temp_dir or path.path(GetUserTempDir())
        self.local_dir = local_dir

        self.got_manifest_data(manifest_data)

        if whitelist is not None:
            self.whitelist = set(whitelist)

        known_files = set((self.local_dir / file.path).abspath()
                          for file in self.unchecked_files)
        known_files.update(
            (self.local_dir / file).abspath() for file in self.whitelist)
        self.delete_files = Cleanup(self.local_dir, known_files)
        self.callback = None
Example #20
0
def defaultprefs():
    '''
    Returns the default prefs as a Storage object
    '''
    import prefs
    import stdpaths
    import config

    the_prefs = util.Storage()

    resdir = os.path.join(util.program_dir(), 'res')
    filenames = [
        os.path.join(resdir, 'defaults.yaml'),
        os.path.join(resdir, config.platformName, 'defaults.yaml'),
        stdpaths.config / 'prefs.yaml',
        stdpaths.userdata / 'prefs.yaml',
    ]

    for filename in filenames:
        info('loading prefs from %r', filename)

        try:
            with open(filename, 'rb') as f:
                prefdict = syck.load(f)
        except Exception, e:
            log.info('Error loading prefs from %r: %r', filename, e)
            continue

        if not isinstance(prefdict, dict):
            continue

        if not sys.DEV:
            prefdict.pop('debug', None)

        prefdict = prefs.flatten(prefdict)
        the_prefs.update(prefdict)
Example #21
0
def defaultprefs():
    '''
    Returns the default prefs as a Storage object
    '''
    import prefs
    import stdpaths
    import config

    the_prefs = util.Storage()

    resdir = os.path.join(util.program_dir(), 'res')
    filenames = [
                 os.path.join(resdir, 'defaults.yaml'),
                 os.path.join(resdir, config.platformName, 'defaults.yaml'),
                 stdpaths.config / 'prefs.yaml',
                 stdpaths.userdata / 'prefs.yaml',
                 ]

    for filename in filenames:
        info('loading prefs from %r', filename)

        try:
            with open(filename, 'rb') as f:
                prefdict = syck.load(f)
        except Exception, e:
            log.info('Error loading prefs from %r: %r', filename, e)
            continue

        if not isinstance(prefdict, dict):
            continue

        if not sys.DEV:
            prefdict.pop('debug', None)

        prefdict = prefs.flatten(prefdict)
        the_prefs.update(prefdict)
Example #22
0
import syck
import tarfile
import subprocess, _subprocess
from path import path

from util import callsback, threaded, autoassign, program_dir
import stdpaths
from common import setpref
from traceback import print_exc

import logging
log = logging.getLogger('spellchecker')

#L_O_G = log

ASPELLBINDIR = (program_dir() / 'lib' / Aspell.LIBNAME).parent

from subprocess import Popen, PIPE, CalledProcessError

ASPELL_CMD = './lib/aspell/bin/aspell %s -a --ignore-case'
ASPELL_OPT = '--%s="%s"'
ASPELL_DFT = ASPELL_CMD % '--lang=en --encoding=utf-8 --keyboard=standard --sugMode=normal'


def FormAspellCommand(parameters):

    options = ' '.join([
        ASPELL_OPT % (key, parameters[key].replace('\\', '/'))
        for key in parameters
    ])
    cmd = ASPELL_CMD % options
Example #23
0
def get_exe_name():
    # XXX: this is horrible, can't we have this in a nice clean attribute somewhere?
    return util.program_dir().relpathto(path.path(sys._real_exe.decode(locale.getpreferredencoding())))
Example #24
0
import tarfile
import subprocess, _subprocess
from path import path

from util import callsback, threaded, autoassign, program_dir
import stdpaths
from common import setpref
from traceback import print_exc

import logging

log = logging.getLogger("spellchecker")

# L_O_G = log

ASPELLBINDIR = (program_dir() / "lib" / Aspell.LIBNAME).parent

from subprocess import Popen, PIPE, CalledProcessError

ASPELL_CMD = "./lib/aspell/bin/aspell %s -a --ignore-case"
ASPELL_OPT = '--%s="%s"'
ASPELL_DFT = ASPELL_CMD % "--lang=en --encoding=utf-8 --keyboard=standard --sugMode=normal"


def FormAspellCommand(parameters):

    options = " ".join([ASPELL_OPT % (key, parameters[key].replace("\\", "/")) for key in parameters])
    cmd = ASPELL_CMD % options

    return cmd
Example #25
0
 def __init__(self):
     import util
     super(DigsbyFeature, self).__init__('digsby',
                                         'digsby',
                                         updatesite=digsby_update_site,
                                         dir=util.program_dir())
Example #26
0
 def __init__(self):
     import util
     super(DigsbyFeature, self).__init__('digsby', 'digsby', updatesite = digsby_update_site, dir = util.program_dir())
Example #27
0
def testapp(pypath = None, appname = 'Digsby', skinname = 'default', prefs = None, username = '******',
            on_message = lambda message: None,
            plugins = True, logging = True):
    'A test application framework for test __main__s.'


    if wxMSW: preload_comctrls()

    import gettext, os.path

    import options
    sys.opts, _args = options.parser.parse_args()
    import logextensions

    digsbysite.COLORIZE_EXCEPTIONS = sys.opts.console_color

    # Install gui elements
    gettext.install(appname, unicode=True)

    from bootstrap import install_N_
    install_N_()

    # Create the app
    app = TestApp()
    app.SetAppName(appname)

    # initialize stdpaths
    from stdpaths import init
    init()

    if wxMSW:
        import gui.native.win.winutil as winutil
        winutil.disable_callback_filter()

    from gui import skin
    from gui.toolbox import setuplogging
    if logging:
        import logging
        setuplogging(level=logging.INFO)


    # make wxLogError go to stderr, not popup dialogs
    wx.Log.SetActiveTarget(wx.LogStderr())

    app.PreShutdown = Delegate()

    if pypath is None:
        pypath = discover_digsby_root()

    sys.path.insert(0, pypath)

    skin.set_resource_paths([
                             util.program_dir() / 'res', # Apparently this has to be first?
                             stdpaths.userdata,
                             stdpaths.config,
                             ])

    if plugins:
        from main import init_plugins
        app.plugins = init_plugins()
    else:
        app.plugins = []


    skin.skininit(os.path.join(pypath, 'res'), skinname = skinname)

    from util.threads.threadpool import ThreadPool
    ThreadPool(5)

    from prefs.prefsdata import flatten
    import syck
    from util.observe import ObservableDict


    prefs_path = os.path.join(pypath, 'res', 'defaults.yaml')

    prefs = ObservableDict(prefs) if prefs is not None else ObservableDict()
    prefs.update({'appearance.skin': skinname,
                  'appearance.variant': None,
                  'debug.shell.font': shellfont()})
    import common
    common.set_active_prefs(prefs, {})

    from util.observe import ObservableDict

    sys.modules['digsbyprofile'] = Storage()
    import digsbyprofile
    from common.notifications import default_notifications
    p = digsbyprofile.profile = Storage(name     = username,
                                    username = username,
                                    prefs    = prefs,
                                    on_message = on_message,
                                    notifications = default_notifications)



    f = file(prefs_path)
    defaults = Storage(flatten(syck.load(f)))
    f.close()
    user = ObservableDict(defaults)
    user.update(prefs)

    from prefs.prefsdata import localprefs
    import prefs
    p.defaultprefs = prefs.defaultprefs()
    p.localprefs = localprefs()

    import common
    common.setfakeprefs(user)

    def toggle_prefs(user=user, defaults=defaults):
        import prefs
        prefs.edit(user, defaults, None)

    def toggle_crust(app=app):
        if not getattr(app, 'crust', None):
            import gui.shell
            wins =  wx.GetTopLevelWindows()
            parent = wins[0] if wins else None
            app.crust = gui.shell.PyCrustFrame(None)
            if parent is not None:
                parent.crust = app.crust
            app.crust.Bind(wx.EVT_CLOSE, lambda evt: app.Exit())
        app.crust.toggle_shown()

        # keyboard focus goes to shell prompt
        if app.crust.IsShown():
            app.crust.crust.SetFocus()

    def on_key(e):
        code = e.GetKeyCode()
        if code == wx.WXK_F11:
            toggle_prefs()
        elif code == wx.WXK_F12:
            toggle_crust()
        elif code == wx.WXK_F5:
            from gui import skin
            skin.reload()
        else:
            e.Skip()

    app.Bind(wx.EVT_KEY_DOWN, on_key)
    app.toggle_crust = toggle_crust

    from main import initialize_webkit, SetStatusPrompt
    initialize_webkit()
    app.SetStatusPrompt = SetStatusPrompt

    return app