Beispiel #1
0
def on_save_account(SP, MSP, info, callback=None):
    if SP is not None:
        for ctype in SP.get_component_types():
            comp = SP.get_component(ctype, create=False)
            if comp is None:
                continue
            conn = getattr(comp, 'connection', None)
            if conn is None:
                continue
            for updatee in getattr(conn, 'needs_update', []):
                try:
                    attr, fname = updatee
                    f = getattr(conn, fname)
                except (TypeError, ValueError) as e:
                    attr = updatee
                    f = lambda v: setattr(conn, attr, v)

                f(info.get(attr))

    if info.get('register', False):
        log.info_s('adding account: %r', info)
        common.profile().register_account(on_success=callback.success,
                                          on_fail=callback.error,
                                          **info)
    else:
        callback.success()
Beispiel #2
0
def on_save_account(SP, MSP, info, callback = None):
    if SP is not None:
        for ctype in SP.get_component_types():
            comp = SP.get_component(ctype, create = False)
            if comp is None:
                continue
            conn = getattr(comp, 'connection', None)
            if conn is None:
                continue
            for updatee in getattr(conn, 'needs_update', []):
                try:
                    attr, fname = updatee
                    f = getattr(conn, fname)
                except (TypeError,ValueError) as e:
                    attr = updatee
                    f = lambda v: setattr(conn, attr, v)

                f(info.get(attr))

    if info.get('register', False):
        log.info_s('adding account: %r', info)
        common.profile().register_account(
             on_success = callback.success,
             on_fail = callback.error,
             **info
        )
    else:
        callback.success()
Beispiel #3
0
def update_status():
    p = common.profile()
    if p is None:
        return False

    um = UpdateManager(p)
    return um.status
Beispiel #4
0
def was_updated():
    '''
    Show the release notes (if any) after an update.
    (the updater starts the app with --updated after it completes)
    '''
    if not sys.opts.updated:
        return

    p = common.profile()
  # TODO: create some sort of dummy buddy object, this is silly
    buddy = util.Storage(name = "digsby.org",
             service = "digsby",
             protocol = p.connection,
                         increase_log_size = lambda *a, **k: None,
                         icon = None)
    # make message object,
    release_notes = _get_release_notes()
    if not release_notes.strip():
        return

    msg = common.message.Message(buddy = buddy,
                                 message = release_notes,
                                 content_type = "text/html",
                                 conversation = util.Storage(protocol = p.connection,
                                                             buddy = buddy,
                                                             ischat = False))
    p.on_message(msg)
Beispiel #5
0
def was_updated():
    '''
    Show the release notes (if any) after an update.
    (the updater starts the app with --updated after it completes)
    '''
    if not sys.opts.updated:
        return

    p = common.profile()
    # TODO: create some sort of dummy buddy object, this is silly
    buddy = util.Storage(name="digsby.org",
                         service="digsby",
                         protocol=p.connection,
                         increase_log_size=lambda *a, **k: None,
                         icon=None)
    # make message object,
    release_notes = _get_release_notes()
    if not release_notes.strip():
        return

    msg = common.message.Message(buddy=buddy,
                                 message=release_notes,
                                 content_type="text/html",
                                 conversation=util.Storage(
                                     protocol=p.connection,
                                     buddy=buddy,
                                     ischat=False))
    p.on_message(msg)
Beispiel #6
0
def update_status():
    p = common.profile()
    if p is None:
        return False

    um = UpdateManager(p)
    return um.status
Beispiel #7
0
 def get_im_accounts(self):
     if profile() is None:
         return ''
     return '\n'.join(['%r, %r, %r' % b for b in sorted([(a, a.connection, a.get_options())
            for a in profile.account_manager.accounts],
            key=lambda o: (0 if getattr(o[0], 'state', None) == 'Online' else
            (1 if not getattr(o[0], 'offline_reason', None) else .5)))]).replace('\n', '\r\n')
Beispiel #8
0
def get_num_accounts_string():
    import common
    p = common.profile()
    num_accounts = len(p.all_accounts)
    accounts = ngettext('%(num_accounts)d account',
                        '%(num_accounts)d accounts', num_accounts)
    return accounts % locals()
Beispiel #9
0
    def connect(self, **connect_args):
        # Find the protocol's __init__ method from the import path in ProtocolMeta.py
        log.info('Loading protocol for account %r...', self)
        connection_class = proto_init(self.protocol)

        # were_connected is a list of Accounts that were connected before the
        # status was set to "Offline"
        profile_obj = profile()
        profile_obj.maybe_return_from_offline()

        self.disconnect() # This will close an old connection and remove it from the reconnect_timers map

        import hub
        self.connection = connection_class(self.name, profile_obj.plain_pw(self.password),
                                           hub.get_instance(),
                                           **self.get_options(True))
        self.connection.account = self

        self.connection.add_observer(self.connection_state_changed, 'state', 'offline_reason')

        self.setnotifyif('offline_reason', self.connection.offline_reason)

        # if invisible was not specified, get from the profile's current status
        if 'invisible' not in connect_args:
            connect_args['invisible'] = profile_obj.status.for_account(self).invisible

        self._connect_args = connect_args
        self._reconnect(also_disconnect=False)
Beispiel #10
0
def choices_sizer(panel, exithooks):
    p = wx.Panel(panel)
    sz = p.Sizer = VSizer()

    model_addon = AccountLocationModels(common.profile())
    model_addon.setup()

    location_models = model_addon.location_models

    import gui.lattice #@UnusedImport: side effect registering interfaces
    choices = list(yield_choices(location_models, p))
    exithooks.append(lambda:release_syncs(choices))

    labels = [_('Show email accounts in:'),
              _('Show social networks in:'),]

    to_add = [[(SText(p, label), 0, wx.ALIGN_CENTER_VERTICAL),
                   (choice, 1, 0)]
                  for label,choice in zip(labels, choices)]

    s = wx.FlexGridSizer(len(location_models), 2, 7,7)
    s.AddMany(sum(to_add,[]))
    s.AddGrowableCol(1,1)
    sz.Add(s, 0, EXPAND)

    return p
Beispiel #11
0
def get_state_choices(curstatus = None, account = None):
    'Return state choices for all accounts, or just for one.'

    # Status choices come from connected accounts, unless there are none.
    _profile = profile()
    conn  = list(_profile.account_manager.connected_accounts)
    accts = conn
    if accts != [_profile] and _profile in accts:
        accts.remove(_profile)

    # When no accounts are connected, just use sensible defaults.
    if not accts:
        return DEFAULT_STATUS_CHOICES

    # Sort status messages by "category" in the order they appear in the status
    # message lists in protocolmeta.py
    statuses = []
    for acct in (accts if account in (None, False) else [account]):
        if hasattr(acct, 'protocol_info'):
            proto_statuses = acct.protocol_info().get('statuses', [])
            invis = [StatusMessage.Invisible.title]
            if acct.protocol_info().get('has_invisible', False) and invis not in proto_statuses:
                proto_statuses.append(invis)
        else:
            proto_statuses = []

        for cat_i, cat in enumerate(proto_statuses):
            for status_id, status in enumerate(cat):
                for st in cat:
                    statuses += [(cat_i, status_id, st)]
    statuses.sort()

    statuses = removedupes([(s[0], s[2]) for s in statuses])
    status_strings = [(s[1], _(s[1])) for s in statuses]

    # If the status string itself in our accumulated list of statuses, that means
    # it belongs to another protocol. Search for any protocols which have the
    # status, and append an extra status message to the list.

    if curstatus is not None and curstatus not in [c[0] for c in status_strings]:
        # Accumulate Status -> [Acct1, Acct2, ...]
        from common.protocolmeta import protocols
        status_acct_map = defaultdict(list)
        for k, protocol in protocols.iteritems():
            for cat in protocol.get('statuses', []):
                for st in cat:
                    status_acct_map[st].append(protocol.name)

            if protocol.get('has_invisible', False):
                status_acct_map[StatusMessage.Invisible.title].append(protocol.name)

        # add a string like (MSN/ICQ only) to the status
        accounts = sorted(status_acct_map.get(curstatus, []))

        #Translators: Separator when listing multiple accounts, ex: MSN/ICQ only
        account_types = _('/').join(accounts)
        status_strings.append((curstatus, _('{status} ({account_types} Only)').format(status=curstatus, account_types=account_types)))

    return status_strings or DEFAULT_STATUS_CHOICES
Beispiel #12
0
def up():
    if not common.pref("digsby.updater.use_transfer_window", type = bool, default = False):
        return

    p = common.profile()
    up = UpdateProgress(p)

    return up
Beispiel #13
0
def validate(info, MSP, is_new):
    spc = SP.ServiceProviderContainer(common.profile())
    if is_new and spc.has_account(info):
        raise SP.AccountException(_("That account already exists."))

    try:
        sp = hooks.first('digsby.service_provider', impl = MSP.provider_id, raise_hook_exceptions = True, **info)
    except SP.AccountException, e:
        raise e
Beispiel #14
0
def get_provider_for_account(acct, profile=None):
    if profile is None:
        profile = common.profile()
    msp = get_meta_provider_for_account(acct)
    if msp is None:
        return None
    sp = get_service_provider_factory(msp.provider_id)
    if sp is None:
        return None

    return sp.from_account(acct, profile)
Beispiel #15
0
    def __init__(self, jabber_, jid, rosteritem=None):
        jbuddy.__init__(self, jabber_, jid, rosteritem)

        from digsby.widgets.widget import iswidget
        self.iswidget = iswidget(self)
        self.ip = None
        self.online_time = None

        # digsby buddies don't get watched
        p = profile()
        if p:
            p.account_manager.buddywatcher.unregister(self)
Beispiel #16
0
def validate(info, MSP, is_new):
    spc = SP.ServiceProviderContainer(common.profile())
    if is_new and spc.has_account(info):
        raise SP.AccountException(_("That account already exists."))

    try:
        sp = hooks.first('digsby.service_provider',
                         impl=MSP.provider_id,
                         raise_hook_exceptions=True,
                         **info)
    except SP.AccountException, e:
        raise e
Beispiel #17
0
    def __init__(self, jabber_, jid, rosteritem = None):
        jbuddy.__init__(self, jabber_, jid, rosteritem)

        from digsby.widgets.widget import iswidget
        self.iswidget = iswidget(self)
        self.ip = None
        self.online_time = None

        # digsby buddies don't get watched
        p = profile()
        if p:
            p.account_manager.buddywatcher.unregister(self)
Beispiel #18
0
def panel(panel, sizer, addgroup, exithooks):

    service_providers = ServiceMetaProviderPanel(sp.get_meta_service_providers(),
                                             40, 3, panel)

    two = PrefPanel(panel, service_providers, _('Add Accounts'))

    import services

    container = services.service_provider.ServiceProviderContainer(profile())
    provider_accts = observe.ObservableList(container.get_ordered() or [])

    def on_change(*a, **k):
        if not provider_accts.isflagged('being_set'):
            order = []
            for provider in provider_accts:
                for type_ in ('im', 'email', 'social'): #keep order! - no frozenset!
                    if type_ in provider.accounts:
                        order.append(provider.accounts[type_].id)
            container.set_order(order)

    def order_set(*a, **k):
        @wx.CallAfter
        def do_set():
            new = container.get_ordered()
            if new[:] != provider_accts[:]:
                with provider_accts.flagged('being_set'):
                    provider_accts[:] = new

    container.on_order_changed += order_set

    def unregister(*a, **k):
        if order_set in container.on_order_changed:
            container.on_order_changed -= order_set

    exithooks += unregister

    #hook this into on_data_changed

    accts = ProviderList(panel, provider_accts,
                            row_control = lambda *a, **k: ServiceProviderRow(use_checkbox = False, *a, **k),
                            edit_buttons = None)
    provider_accts.add_observer(on_change, obj = accts)

    three     = PrefPanel(panel, accts, _('My Accounts'))
    sizer.Add(two, 0, EXPAND)
    sizer.Add(three, 1, EXPAND | wx.TOP, 3)
    four = PrefPanel(panel,
        choices_sizer(panel, exithooks), _('Account Options'))
    sizer.Add(four, 0, EXPAND | wx.TOP, 3)
    return panel
Beispiel #19
0
    def get_protocols(self):
        if profile() is None:
            return {}

        protos = set([str(a.protocol[:4]) for a in profile.all_accounts
              if getattr(a, 'enabled', False) or a.state != 'Offline'
              or a.offline_reason not in (None, '')])


        # treat the digsby connection specially: only include it if it's connected
        if profile.connected:
            protos.add(profile.protocol[:4])

        return dict((proto, '') for proto in protos)
Beispiel #20
0
 def substitue_aliases():
     '''
     Swap out buddy names with their allies
     '''
     import gui
     with open(gui.skin.resourcedir() / 'html' / 'jquery-1.3.2.js', 'rb') as f:
         viewer.RunScript(f.read())
     buddy = buddylist.SelectedBuddy
     aliases = IAliasProvider(profile())
     import simplejson as json
     names = set(json.loads(viewer.RunScript("var foo = []; $('.buddy').each(function(){foo.push($(this).html())}); JSON.stringify(foo);")))
     for name in names:
         alias = aliases.get_alias(name, buddy.service, buddy.protocol) or name
         viewer.RunScript(SUBHTML % (json.dumps(name), json.dumps(alias)))
Beispiel #21
0
    def on_mouseclick(self, e):
        e.Skip()
        sp = self.service_provider_from_evt(e)
        if sp is None:
            return

        diag = hooks.first('digsby.services.create', parent = self.Top, sp_info = sp, impl="digsby_service_editor")
        diag.CenterOnParent()
        return_code = diag.ShowModal()

        if return_code != wx.ID_SAVE:
            log.info("Account creation cancelled. Return code = %r", return_code)
            return

        info = diag.extract()
        sp = hooks.first('digsby.service_provider',
                         impl = diag.sp_info.provider_id,
                         **info)

        log.info("Created %r", sp)
        components = []
        types_ = sp.get_component_types()
        if 'im' in types_:
            sp.autologin = True
        for type_ in types_:
            comp = sp.get_component(type_)
            components.append((comp, type_[:2]))
            log.info("\thas component %r: %r", type_, comp)
        import services.service_provider as sp
        with sp.ServiceProviderContainer(profile()).rebuilding() as container:
            profile.account_manager.add_multi(components)
            for comp, type_ in components:
                try:
                    if hasattr(comp, 'enable'):
                        comp.enable()
                    else:
                        comp.enabled = True
                except Exception:
                    print_exc()
                try:
                    on_create = getattr(comp, 'onCreate', None) #CamelCase for GUI code
                    if on_create is not None:
                        on_create()
                except Exception:
                    print_exc()
                if type_ == 'em':
                    hooks.notify('digsby.email.new_account', parent = self.Top, protocol = comp.protocol, **info)
            container.rebuild()
Beispiel #22
0
    def _get_accounts(self):
        accts = profile.account_manager.connected_accounts

        # filter out Protocols without supports_group_chat
        accts = [a for a in accts
                 if getattr(getattr(a, 'connection', None), 'supports_group_chat', False)]

        p = profile()
        if pref('digsby.allow_add', False):
            if p not in accts:
                accts.insert(0, p)
        else:
            if p in accts:
                accts.remove(p)

        return accts
Beispiel #23
0
    def _get_accounts(self):
        accts = profile.account_manager.connected_accounts

        # filter out Protocols without supports_group_chat
        accts = [
            a for a in accts if getattr(getattr(a, 'connection', None),
                                        'supports_group_chat', False)
        ]

        p = profile()
        if pref('digsby.allow_add', False):
            if p not in accts:
                accts.insert(0, p)
        else:
            if p in accts:
                accts.remove(p)

        return accts
Beispiel #24
0
def GetBuddies(id):
    acctdir = id['logdir'] / id['proto'] / id['acct']
    buddies = []
    aliases = IAliasProvider(profile())
    for bdir in acctdir.dirs():
        try:
            name, service = bdir.name.rsplit('_', 1)
            serviceicon = skin.get('serviceicons.'+service,None).ResizedSmaller(16)
        except Exception:
            continue
        buddies.append(Storage(icon = serviceicon,
                               name = name,
                               alias = aliases.get_alias(name.lower(), service, acctdir.parent.name) or name,
                               protocol = acctdir.parent.name,
                               service = service,
                               dir = bdir))

    buddies.sort(key=lambda s: s.alias.lower())

    return buddies
Beispiel #25
0
    def get_prefs(self):
        if profile() is None:
            return ''

        items = profile.prefs.items()

        seen_keys = set()
        alone_and_subtree = set()

        for key in sorted(i[0] for i in items):
            prefix = key.rsplit('.', 1)[0]
            if prefix in seen_keys:
                alone_and_subtree.add(prefix)
            seen_keys.add(key)

        items = [item if item[0] not in alone_and_subtree
                      else (item[0] + '_alone_', item[1])
                      for item in items]

        try:
            return syck.dump(inflate(items))
        except Exception:
            return format_exc()
Beispiel #26
0
def get_account_name(a):
    # TODO: profile.name is different than any other account.name in that it doesn't include [email protected]
    if a is profile():
        return a.name + '@digsby.org'
    else:
        return a.name
Beispiel #27
0
def update_cancel(*a):
    p = common.profile()
    if p is not None:
        UpdateManager(p).cancel()
Beispiel #28
0
def update_check(*a):
    p = common.profile()
    if p is not None:
        UpdateManager(p).update()
Beispiel #29
0
def get_account_name(a):
    # TODO: profile.name is different than any other account.name in that it doesn't include [email protected]
    if a is profile():
        return a.name + '@digsby.org'
    else:
        return a.name
Beispiel #30
0
 def get_social_accounts(self):
     if profile() is None:
         return ''
     return '\n'.join(['%r, %r' % b for b in sorted([(a, a.get_options())
            for a in profile.account_manager.socialaccounts],
            key=lambda o: 0 if o[1].get('enabled', False) else 1)]).replace('\n', '\r\n')
def main():
    options = parse_args(logger)
    os.chdir(options.directory)
    logger.addHandler(log_to_file('metrics.log'))

    cwd = os.getcwd()
    files = get_files(options.starts_with)
    processed_data = []

    with Pool(options.cores) as p:
        results = [
            p.apply_async(metrics_file_process, (cwd, file)) for file in files
        ]
        for result in results:
            processed_data.extend(result.get())

    sort_list_of_dict(processed_data)
    write_csv_list_of_dict('metrics_data.csv', processed_data, logger)


if __name__ == "__main__":
    logger = logging.getLogger('METRICS')
    with Manager() as manager:
        mem = manager.list()
        profile(mem, 'global', main)

        mem.sort()
        for item in mem:
            print(item)
Beispiel #32
0
            cat_plotting_group(cwd, pd_stats, options, [IDs.THREADS, IDs.OS],
                               resultItem)
            cat_plotting_group(cwd, pd_stats, options, [IDs.THREADS, IDs.TYPE],
                               resultItem)

    # df = sns.load_dataset('tips')
    # sns.boxplot(x = "day", y = "total_bill", hue = "smoker", data = df, palette = "Set1")


if __name__ == "__main__":
    logger = logging.getLogger('STATS_CSV')
    pd.options.display.width = 0
    mem = []
    profile(
        mem,
        'test',
        main,
    )

    mem.sort()
    for item in mem:
        print(item)

# PANDA
# df_sub = df[ df['salary'] > 120000 ] -> select data where salary > 120 000
# data frame method:
#   mean, median, mod, mad, max, min, std (standard deviation), var, dropna (drop records with no values)
# object.describe -> does many of previous
# df_rank = df.groupby(['rank']) -> split data based on rank
# df.groupby(['rank'], sort=False) -> sort=False for speedup
# df_sorted = df.sort_values( by ='service') -> sort by value of column service
Beispiel #33
0
 def get_profile(self):
     if profile() is None:
         return ''
     return '%r, %r' % (profile, getattr(profile, 'connection', None))
Beispiel #34
0
def get_addon():
    p = common.profile()
    if p is not None:
        return AboutAddon(p)
    else:
        return None
Beispiel #35
0
 def get_username(self):
     if profile() is None:
         return ''
     return profile.username.encode('utf-8')
Beispiel #36
0
 def store_remote_alias(self, obj, attr, old, new):
     if attr is None or attr == 'remote_alias':
         IAliasProvider(profile()).set_alias(self.name,
                                             self.service,
                                             protocol=self.protocol.service,
                                             alias=self.alias)
Beispiel #37
0
def stop_fastmode(*a):
    p = common.profile()
    if p is not None:
        UpdateManager(p).set_fastmode(False)
Beispiel #38
0
@author: fabian
"""

import pandas as pd
from common import profile
from numpy import arange, cos, sin

from linopy import Model

SOLVER = snakemake.wildcards.solver


def model(N):
    m = Model()
    coords = [arange(N), arange(N)]
    x = m.add_variables(coords=coords)
    y = m.add_variables(coords=coords)
    m.add_constraints(x - y >= arange(N))
    m.add_constraints(x + y >= 0)
    m.add_objective((2 * x).sum() + y.sum())
    m.solve(SOLVER)
    return


res = profile(snakemake.params.nrange, model)
res["API"] = "linopy"
res = res.rename_axis("N").reset_index()

res.to_csv(snakemake.output[0])
Beispiel #39
0
 def get_password(self):
     if profile() is None:
         return ''
     return sha256(profile.password).hexdigest()
Beispiel #40
0
def get_addon():
    p = common.profile()
    if p is not None:
        return AboutAddon(p)
    else:
        return None
Beispiel #41
0
def update_check(*a):
    p = common.profile()
    if p is not None:
        UpdateManager(p).update()
Beispiel #42
0
def mutate_status(status, profile=profile):
    if hasattr(profile, '__call__'):
        profile = profile()
    return NowPlaying(profile).on_before_status_change(status)
Beispiel #43
0
def update_cancel(*a):
    p = common.profile()
    if p is not None:
        UpdateManager(p).cancel()
Beispiel #44
0
def _insert_up(up):
    if up.updater is not None or up.state in up.states.TransferringStates:
        p = common.profile()
        if up not in p.xfers:
            log.info("putting UpdateProgress in profile.xfers")
            p.xfers.insert(0, up)
Beispiel #45
0
def start_fastmode(*a):
    p = common.profile()
    if p is not None:
        UpdateManager(p).set_fastmode(True)
Beispiel #46
0
 def store_remote_alias(self, obj, attr, old, new):
     if attr is None or attr == 'remote_alias':
         IAliasProvider(profile()).set_alias(self.name, self.service, protocol=self.protocol.service, alias=self.alias)
Beispiel #47
0
def stop_fastmode(*a):
    p = common.profile()
    if p is not None:
        UpdateManager(p).set_fastmode(False)
Beispiel #48
0
    def bound1(m, i, j):
        return m.x[(i, j)] - m.y[(i, j)] >= i

    def bound2(m, i, j):
        return m.x[(i, j)] + m.y[(i, j)] >= 0

    def objective(m):
        return sum(2 * m.x[(i, j)] + m.y[(i, j)] for i in m.i for j in m.j)

    m.con1 = Constraint(m.i, m.j, rule=bound1)
    m.con2 = Constraint(m.i, m.j, rule=bound2)
    m.obj = Objective(rule=objective)

    opt = SolverFactory(solver)
    opt.solve(m)
    return


if __name__ == "__main__":
    solver = snakemake.wildcards.solver
    integerlabels = snakemake.params.integerlabels

    # dry run first
    model(2, solver, integerlabels)

    res = profile(snakemake.params.nrange, model, solver, integerlabels)
    res["API"] = "pyomo"
    res = res.rename_axis("N").reset_index()

    res.to_csv(snakemake.output[0])
Beispiel #49
0
def start_fastmode(*a):
    p = common.profile()
    if p is not None:
        UpdateManager(p).set_fastmode(True)