Exemplo n.º 1
0
def print_updates():
    """ Print a sig message with embedded update strings or nothing
        at all if there's an error. """
    try:
        stored_cfg = Config.from_file(CFG_PATH)
        updates = []
        for usk_hash in USK_HASHES:
            index = stored_cfg.get_index(usk_hash)
            if index is None:
                # Uncomment this and run from the command line if
                # you get no output.
                #print "No stored index for usk hash: ", usk_hash
                continue
            updates.append((usk_hash, index))
        updates.sort()
        # Hmmm... silently truncate
        updates = updates[:MAX_UPDATES]
        if len(updates) > 0:
            print STATIC_TEXT
            print to_msg_string(updates, None, ':')
    except:
        # Better to exit() with the correct exit code?
        # Fail silently, rather than spewing garbage into sig.
        return
Exemplo n.º 2
0
def print_updates():
    """ Print a sig message with embedded update strings or nothing
        at all if there's an error. """
    try:
        stored_cfg = Config.from_file(CFG_PATH)
        updates = []
        for usk_hash in USK_HASHES:
            index = stored_cfg.get_index(usk_hash)
            if index is None:
                # Uncomment this and run from the command line if
                # you get no output.
                #print "No stored index for usk hash: ", usk_hash
                continue
            updates.append((usk_hash, index))
        updates.sort()
        # Hmmm... silently truncate
        updates = updates[:MAX_UPDATES]
        if len(updates) > 0:
            print STATIC_TEXT
            print to_msg_string(updates, None, ':')
    except:
        # Better to exit() with the correct exit code?
        # Fail silently, rather than spewing garbage into sig.
        return
Exemplo n.º 3
0
    def _send_update_notification(self):
        """ INTERNAL: Send an FMS notification for the latest repo index. """
        self.trace("send_update_notification -- repo index: %i" %
                   self.ctx.store_info['LATEST_INDEX'])

        subject = ('Wikitext Update:' +
                   '/'.join(self.ctx.request_uri().split('/')[1:]))
        text = to_msg_string(((self.params['USK_HASH'],
                               self.ctx.store_info['LATEST_INDEX']), )) + '\n'
        groups = self.params['FMS_GROUP']
        if self.params.get('FMS_NOTIFY_GROUP', ''):
            groups = "%s, %s" % (groups, self.params['FMS_NOTIFY_GROUP'])
            self.trace("send_update_notification -- groups: %s" % groups)

        self.parent.queue_msg((self.params['FMS_ID'], groups, subject, text))
        # DCI: better to use send confirm callback?
        self.ctx.clear_timeout('NOTIFY_COALESCE_SECS')
Exemplo n.º 4
0
    def _send_update_notification(self):
        """ INTERNAL: Send an FMS notification for the latest repo index. """
        self.trace("send_update_notification -- repo index: %i" %
                   self.ctx.store_info['LATEST_INDEX'])

        subject = ('Wikitext Update:' +
                   '/'.join(self.ctx.request_uri().split('/')[1:]))
        text = to_msg_string(((self.params['USK_HASH'],
                              self.ctx.store_info['LATEST_INDEX']), )) + '\n'
        groups = self.params['FMS_GROUP']
        if self.params.get('FMS_NOTIFY_GROUP', ''):
            groups = "%s, %s" % (groups, self.params['FMS_NOTIFY_GROUP'])
            self.trace("send_update_notification -- groups: %s" % groups)

        self.parent.queue_msg((self.params['FMS_ID'],
                               groups,
                               subject,
                               text))
        # DCI: better to use send confirm callback?
        self.ctx.clear_timeout('NOTIFY_COALESCE_SECS')
Exemplo n.º 5
0
def execute_fmsnotify(ui_, repo, params, stored_cfg):
    """ Run fmsnotify command. """
    update_sm = None
    try:
        # Insert URI MUST be stored.
        update_sm = setup(ui_, repo, params, stored_cfg)
        request_uri, dummy = do_key_setup(ui_, update_sm,
                                          params, stored_cfg)

        if request_uri is None: # Just assert?
            ui_.warn("Only works for USK file URIs.\n")
            return

        check_fms_cfg(ui_, params, stored_cfg)

        usk_hash = get_usk_hash(request_uri)
        index = stored_cfg.get_index(usk_hash)
        if index is None and not (params.get('SUBMIT_BUNDLE', False) or
                                  params.get('SUBMIT_WIKI', False)):
            ui_.warn("Can't notify because there's no stored index "
                     + "for %s.\n" % usk_hash)
            return

        group = stored_cfg.defaults.get('FMSNOTIFY_GROUP', None)
        subject = 'Update:' + '/'.join(request_uri.split('/')[1:])
        if params['ANNOUNCE']:
            text = to_msg_string(None, (request_uri, ))
        elif params['SUBMIT_BUNDLE']:
            params['REQUEST_URI'] = request_uri # REDFLAG: Think through.
            text = execute_insert_patch(ui_, repo, params, stored_cfg)
            subject = 'Patch:' + '/'.join(request_uri.split('/')[1:])
        elif params['SUBMIT_WIKI']:
            params['REQUEST_URI'] = request_uri # REDFLAG: Think through.
            text, group = execute_wiki_submit(ui_, repo, params, stored_cfg)
            subject = 'Submit:' + '/'.join(request_uri.split('/')[1:])
        else:
            text = to_msg_string(((usk_hash, index), ))

        msg_tuple = (stored_cfg.defaults['FMS_ID'],
                     group,
                     subject,
                     text)

        show_fms_info(ui_, params, stored_cfg, False)

        ui_.status('Sender : %s\nGroup  : %s\nSubject: %s\n%s\n' %
                   (stored_cfg.defaults['FMS_ID'],
                    group,
                    subject, text))

        if params['VERBOSITY'] >= 5:
            ui_.status('--- Raw Message ---\n%s\n---\n' % (
                MSG_TEMPLATE % (msg_tuple[0], msg_tuple[1],
                                msg_tuple[2], msg_tuple[3])))

        if params['DRYRUN']:
            ui_.status('Exiting without sending because --dryrun was set.\n')
            return

        # REDFLAG: for testing!
        if 'MSG_SPOOL_DIR' in params:
            ui_.warn("DEBUG HACK!!! Writing fms msg to local spool:\n%s\n" %
                      params['MSG_SPOOL_DIR'])
            import fmsstub

            # LATER: fix config file to store full fmsid?
            # grrrr... hacks piled upon hacks.
            lut = {'djk':'djk@isFiaD04zgAgnrEC5XJt1i4IE7AkNPqhBG5bONi6Yks'}
            fmsstub.FMSStub(params['MSG_SPOOL_DIR'], group,
                            lut).send_msgs(
                get_connection(stored_cfg.defaults['FMS_HOST'],
                               stored_cfg.defaults['FMS_PORT'],
                               None),
                (msg_tuple, ), True)
        else:
            send_msgs(get_connection(stored_cfg.defaults['FMS_HOST'],
                                     stored_cfg.defaults['FMS_PORT'],
                                     None),
                                     (msg_tuple, ), True)

        ui_.status('Notification message sent.\n'
                   'Be patient.  It may take up to a day to show up.\n')
    finally:
        cleanup(update_sm)