Example #1
0
    def execute(self, timeperiod):

        # TODO validate time period
        l = self.function.load_latest()

        actions = [("Add...", "log add %Log_entry")]

        data = []
        if not len(l):
            if len(timeperiod) and len(timeperiod[0]):
                note = "No log entries found, try a different time period"
            else:
                note = "No log entries found"

            return function.response(function.STATE_FAILURE, note, data, actions)

        for item in l:
            item_actions    = {'Delete':  'log remove %s' % (item.id)}
            item_meta       = {'id': item.id}

            item_time       = self.function.kernel.inClientTimezone(item.entrytime).strftime('%y/%m/%d %I:%M%P')
            item_text       = "%s - %s" % (item_time, item.description)

            data.append([item_text, None, item_actions, item_meta])

        if len(timeperiod) and len(timeperiod[0]):
            note = "Viewing log entries for %s" % timeperiod[0]
        else:
            note = "Viewing latest log entries"

        return function.response(function.STATE_SUCCESS, note, data, actions)
Example #2
0
    def execute(self, data):
        itemid = data[0]
        oldtag = normalise_tag(data[1])
        newtag = normalise_tag(data[2])

        if oldtag.strip() == '':
            return function.response(function.STATE_FAILURE,
                                     'No old tag specified')

        if newtag.strip() == '':
            return function.response(function.STATE_FAILURE,
                                     'No new tag specified')

        l = lstobj(self.function, oldtag)
        itemdata = l.get(itemid, oldtag)

        if not itemdata:
            return function.response(function.STATE_FAILURE,
                                     'No item to move from tag "%s"' % oldtag)

        l.remove_tag(itemid, oldtag)
        l.add_tag(itemid, newtag)

        return function.redirect(
            self, ('list', 'view', [newtag]), 'Moved "%s" from "%s" to "%s"' %
            (itemdata['item'], oldtag, newtag))
Example #3
0
    def execute(self, data):
        timestamp = ' '.join(data[0:2])
        title = ' '.join(data[2:])

        if title.strip() == '':
            return function.response(function.STATE_FAILURE,
                                     'No title supplied')

        # Check timestamp is valid
        try:
            raw = datetime.datetime.strptime(timestamp, '%Y-%m-%d %H:%M:%S')
        except ValueError:
            to_fix = [[
                'reminder add %s %s' % (timestamp, title),
                'reminder add %%timestamp{{%s}} %%title{{%s}}' %
                (timestamp, title)
            ]]
            return function.response(
                function.STATE_FAILURE,
                'Invalid format for timestamp (%s)' % timestamp, to_fix)

        e = self.function.create(timestamp, title)

        return function.redirect(
            self, ('reminder', 'list'),
            notification='Added reminder event "%s" with timestamp "%s"' %
            (e.title, e.get_nice_time()))
Example #4
0
    def execute(self, data):
        itemid = data[0]
        timestamp = ' '.join(data[1:3])
        title = ' '.join(data[3:])

        if title.strip() == '':
            return function.response(function.STATE_FAILURE,
                                     'No title supplied')

        # Check timestamp is valid
        try:
            raw = datetime.datetime.strptime(timestamp, '%Y-%m-%d %H:%M:%S')
        except ValueError:
            to_fix = [[
                'reminder update %s %s %s' % (itemid, timestamp, title),
                'reminder update %s %%Timestamp{{%s}} %%Title{{%s}}' %
                (itemid, timestamp, title)
            ]]
            return function.response(
                function.STATE_FAILURE,
                'Invalid format for timestamp (%s)' % timestamp, to_fix)

        e = self.function.get(itemid)
        e.update({'timestamp': timestamp, 'title': title})

        return function.redirect(
            self, ('reminder', 'list'),
            notification='Updated reminder event "%s" with timestamp "%s"' %
            (e.title, e.get_nice_time()),
            context='reminder item %s' % e.id)
Example #5
0
    def execute(self, data):

        command = ' '.join(data)
        newitem, tags = extract_tags(command)

        tags = normalise_tags(tags)
        tagstr = tags_as_readable_string(tags)

        if not len(tags):
            return function.response(function.STATE_FAILURE, 'No tag specified')

        if newitem.strip() == '':
            return function.response(function.STATE_FAILURE, 'No item to add')

        l = lstobj(self.function, tags[0])
        itemid = l.add_new(newitem)

        for tag in tags[1:]:
            l.add_tag(itemid, tag)

        return function.redirect(
            self,
            ('list', 'view', tags),
            notification='Added "%s" with tags %s' % (newitem, tagstr),
            context='list item %s' % itemid
        )
Example #6
0
    def execute(self, data):
        itemid = data[0]
        oldtag = normalise_tag(data[1])
        newtags = data[2:]
        newtags = normalise_tags(newtags)
        newtagstr = tags_as_readable_string(newtags)

        if oldtag.strip() == '':
            return function.response(function.STATE_FAILURE, 'No old tag specified')

        if len(newtags) == 0 or newtags[0].strip() == '':
            return function.response(function.STATE_FAILURE, 'No new tag specified')

        l = lstobj(self.function, oldtag)
        itemdata = l.get(itemid, oldtag)

        if not itemdata:
            return function.response(function.STATE_FAILURE, 'No item to move from tag "%s"' % oldtag)

        l.remove_tag(itemid, oldtag)

        for newtag in newtags:
            l.add_tag(itemid, newtag)

        return function.redirect(
            self,
            ('list', 'view', newtags),
            notification='Moved "%s" from "%s" to %s' % (itemdata['item'], oldtag, newtagstr),
            context='list item %s' % itemid
        )
Example #7
0
    def execute(self, data):
        contactid = data[0]

        c = self.function.get_model_instance(Contact, contactid)
        if not c:
            return function.response(
                function.STATE_FAILURE,
                'Contact with id "%s" cannot be found' % contactid)

        accounts = c.get_accounts()
        data = []
        for a in accounts:
            data.append([
                '%s: %s' % (a.type, a.uid), None, {
                    'Delete':
                    'contact accountdelete %s %s' % (a.contact_id, a.id)
                }, {
                    'context': 'contact account %s' % a.id
                }
            ])

        actions = [('Add new account...',
                    'contact accountadd %s %%Type %%UID' % (contactid)),
                   ('Delete', 'contact delete %s' % (contactid)),
                   ('Edit...',
                    'contact edit %s %%Name{{%s}}' % (contactid, c.name)),
                   ('Contact list', 'contact list')]

        return function.response(function.STATE_SUCCESS, c.name, data, actions)
Example #8
0
    def execute(self, timeperiod):

        # TODO validate time period
        l = self.function.load_latest()

        actions = [("Add...", "log add %Log_entry")]

        data = []
        if not len(l):
            if len(timeperiod) and len(timeperiod[0]):
                note = "No log entries found, try a different time period"
            else:
                note = "No log entries found"

            return function.response(function.STATE_FAILURE, note, data,
                                     actions)

        for item in l:
            item_actions = {'Delete': 'log remove %s' % (item.id)}
            item_meta = {'id': item.id}

            item_time = self.function.kernel.inClientTimezone(
                item.entrytime).strftime('%y/%m/%d %I:%M%P')
            item_text = "%s - %s" % (item_time, item.description)

            data.append([item_text, None, item_actions, item_meta])

        if len(timeperiod) and len(timeperiod[0]):
            note = "Viewing log entries for %s" % timeperiod[0]
        else:
            note = "Viewing latest log entries"

        return function.response(function.STATE_SUCCESS, note, data, actions)
Example #9
0
    def _no_items_in_list(self, tags):
        actions = [
            ["List all lists", 'list list']
        ]
        if len(tags) == 0:
            return function.response(function.STATE_SUCCESS, 'No items found', [], actions)

        tagstr = tags_as_readable_string(tags)
        actions = [["Add...", "list add %s %%List_item" % tags_as_string(tags)]] + actions
        return function.response(function.STATE_SUCCESS, 'No items in list %s' % tagstr, [], actions)
Example #10
0
    def execute(self, data):

        # TODO validate date
        if len(data) < 1 or data[0] == '':
            date = self.function.date_today()
        else:
            date = data[0]

        today = date == self.function.date_today()

        h = self.function.kernel.call('list', 'view', ['!habits'])

        actions = [
            ("Habit overview", "habit overview"),
            ("Add new habit...", "list add #!habits %Habit_name"),
            ('Previous', 'habit view %s' % self.function.date_previous(date)),
        ]

        data = []
        if h.state != function.STATE_SUCCESS:
            note = "No habits found. Add one!"
            return function.response(function.STATE_FAILURE, note, data,
                                     actions)

        complete = self.function.states(date)
        for item in h.data:
            item_id = str(item[3]['id'])
            # Check if complete
            c = complete[item_id]['status'] if item_id in complete.keys(
            ) else 'N'

            if c == 'N':
                item_actions = {
                    'Completed!': 'habit update %s %s Y' % (item_id, date)
                }
                icon = u'\u2717'
            else:
                item_actions = {
                    'Uncomplete': 'habit update %s %s N' % (item_id, date)
                }
                icon = u'\u2713'

            item_meta = {'id': item_id, 'context': 'list item %s' % item_id}
            item_text = u'%s %s' % (icon, item[0])
            data.append([item_text, None, item_actions, item_meta])

        if today:
            note = 'Viewing today\'s habits'
        else:
            note = 'Viewing %s habits' % date

        return function.response(function.STATE_SUCCESS, note, data, actions)
Example #11
0
    def execute(self, data):

        # TODO validate date
        if len(data) < 1 or data[0] == '':
            date = self.function.date_today()
        else:
            date = data[0]

        h = self.function.kernel.call('list', 'view', ['!habits'])

        data = []
        if h.state != function.STATE_SUCCESS:
            note = "No habits found. Add one!"
            return function.response(function.STATE_FAILURE, note, data,
                                     actions)

        dates = []
        dates.append(date)
        while len(dates) < 7:
            dates.append(self.function.date_previous(dates[-1]))

        dates.reverse()

        complete = {}
        for d in dates:
            complete[d] = self.function.states(d)

        for item in h.data:
            item_id = str(item[3]['id'])

            item_text = u''

            # Check if complete for each date
            for d in dates:
                comp = complete[d]
                c = comp[item_id]['status'] if item_id in comp.keys() else 'N'

                if c == 'N':
                    icon = u'\u2717'  # unicode cross
                else:
                    icon = u'\u2713'  # unicode tick

                item_text += icon

            item_text += ' %s' % item[0]

            data.append([item_text, None])

        note = 'Summary of habits over last 7 days'

        return function.response(function.STATE_SUCCESS, note, data)
Example #12
0
    def execute(self, data):
        if not len(data):
            return function.response(function.STATE_FAILURE, 'No log entry ID specified')

        id = int(data[0])
        l = self.function.remove(id)
        if not l:
            return function.response(function.STATE_FAILURE, 'Log ID %d not found' % id)

        return function.redirect(
            self,
            ('log', 'view'),
            notification='Deleted log entry "%s" with timestamp "%s" (ID: %d)' % (l.description, l.entrytime, l.id)
        )
Example #13
0
    def execute(self, data):
        name = data[0]

        loc = location(self.function)
        loc.get_latest(name)

        if not loc.id:
            return function.response(function.STATE_FAILURE, 'No locations reported for "%s"' % name)

        data = []
        data.append([loc.place])
        data.append([self.function.kernel.inClientTimezone(loc.time).strftime('%y/%m/%d %I:%M%P')])

        return function.response(function.STATE_SUCCESS, 'Last reported location for "%s"' % name, data)
Example #14
0
    def execute(self, data):

        # TODO validate date
        if len(data) < 1 or data[0] == '':
            date = self.function.date_today()
        else:
            date = data[0]

        h = self.function.kernel.call('list', 'view', ['!habits'])

        data = []
        if h.state != function.STATE_SUCCESS:
            note = "No habits found. Add one!"
            return function.response(function.STATE_FAILURE, note, data, actions)

        dates = []
        dates.append(date)
        while len(dates) < 7:
            dates.append(self.function.date_previous(dates[-1]))

        dates.reverse()

        complete = {}
        for d in dates:
            complete[d] = self.function.states(d)

        for item in h.data:
            item_id = str(item[3]['id'])

            item_text = u''

            # Check if complete for each date
            for d in dates:
                comp = complete[d]
                c = comp[item_id]['status'] if item_id in comp.keys() else 'N'

                if c == 'N':
                    icon = u'\u2717' # unicode cross
                else:
                    icon = u'\u2713' # unicode tick

                item_text += icon

            item_text += ' %s' % item[0]

            data.append([item_text, None])

        note = 'Summary of habits over last 7 days'

        return function.response(function.STATE_SUCCESS, note, data)
Example #15
0
    def execute(self, data):
        itemid = data[0]
        l = lstobj(self.function, None)
        itemdata = l.get(itemid, None)

        if not itemdata:
            resp = function.response(function.STATE_FAILURE,
                                     'No item to with id "%s"' % (itemid))
            resp.write = 1
            return resp

        items = l.get_versions(itemid)

        if not len(items):
            actions = []
            tags = l.get_tags(itemid)
            if tags:
                for t in tags:
                    actions.append([
                        'View list "%s"' % t['tag'],
                        "list view %s" % t['tag']
                    ])
            return function.response(
                function.STATE_SUCCESS,
                'No previous versions of item "%s"' % (itemid), [], actions)

        data = []
        for item in items:
            item_actions = {}
            #####
            ## Prep tags for each item
            itemtags = l.get_old_tags(item['aid'])
            if itemtags:
                itemtagstr = []
                for t in itemtags:
                    itemtagstr.append(t['tag'])
                    item_actions['[%s]' % t['tag']] = "list view %s" % t['tag']

            if not len(item_actions):
                item_actions = None

            #####
            ## Append item to the list
            data.append([item['item'], None, item_actions])

        return function.response(
            function.STATE_SUCCESS,
            'List previous versions of "%s" with id "%s"' %
            (itemdata['item'], itemdata['id']), data)
Example #16
0
    def execute(self, data):
        if not len(data):
            return function.response(function.STATE_FAILURE,
                                     'No log entry ID specified')

        id = int(data[0])
        l = self.function.remove(id)
        if not l:
            return function.response(function.STATE_FAILURE,
                                     'Log ID %d not found' % id)

        return function.redirect(
            self, ('log', 'view'),
            'Deleted log entry "%s" with timestamp "%s" (ID: %d)' %
            (l.description, l.entrytime, l.id))
Example #17
0
    def execute(self, data):
        start = int(time.time())

        db = self.function.kernel.getDataPrimary()
        db.updateConfig('lastcronstart', start)

        periods = {'minute': 60, 'hourly': 3600, 'daily': 86400}
        data = []

        for period in periods:
            last = int(db.loadConfig('lastcron%s' % period, 0))
            if (last + periods[period]) <= start:
                data.append(['Running %s cron' % period])

                # Update last run time before starting in case
                # it takes longer than 60 seconds and overlaps
                # with the next cron run.
                # Unless of course the long cron run in the
                # 'minute' run, then we're screwed (and you
                # should be beaten for writing that cron job)
                db.updateConfig('lastcron%s' % period, start)
                self.function.kernel.runJobs(period)

        finish = int(time.time())
        db.updateConfig('lastcronfinish', finish)

        longest = int(db.loadConfig('longestcron', 0))
        if longest < (finish - start):
            db.updateConfig('longestcron', finish - start)

        return function.response(function.STATE_SUCCESS, 'Run cron', data)
Example #18
0
    def execute(self, data):
        start = int(time.time())

        db = self.function.kernel.getDataPrimary()
        db.updateConfig('lastcronstart', start)

        periods = {'minute': 60, 'hourly': 3600, 'daily': 86400}
        data = []

        for period in periods:
            last = int(db.loadConfig('lastcron%s' % period, 0))
            if (last + periods[period]) <= start:
                data.append(['Running %s cron' % period])

                # Update last run time before starting in case
                # it takes longer than 60 seconds and overlaps
                # with the next cron run.
                # Unless of course the long cron run in the
                # 'minute' run, then we're screwed (and you
                # should be beaten for writing that cron job)
                db.updateConfig('lastcron%s' % period, start)
                self.function.kernel.runJobs(period)

        finish = int(time.time())
        db.updateConfig('lastcronfinish', finish)

        longest = int(db.loadConfig('longestcron', 0))
        if longest < (finish - start):
            db.updateConfig('longestcron', finish - start)

        return function.response(function.STATE_SUCCESS, 'Run cron', data)
Example #19
0
    def execute(self, data):
        user = self.function.kernel.getConfig('username')
        date = self.function.kernel.inClientTimezone(
            datetime.datetime.now()).strftime('%A %B %d, %Y')
        welcome = 'Hi %s. Today is %s' % (user, date)

        weather = self._get_weather()
        if weather and weather.state == function.STATE_SUCCESS:
            data = []
            for line in weather.data:
                data.append(line[0:1])
        else:
            data = []

        tosort = self.function.kernel.call('list', 'view', ['tosort'])
        if tosort.state == function.STATE_SUCCESS:
            data.append([
                '==== To-Sort (%d) ====' % len(tosort.data), 'list view tosort'
            ])

        today = self.function.kernel.call('list', 'view', ['today'])
        if today.state == function.STATE_SUCCESS:
            data.append(['==== Today ====', 'list view today'])
            data += today.data

        actions = []
        actions.append(["Add to today...", "list add #today %List_item"])
        actions.append(["Add to To-Sort...", "list add #tosort %List_item"])

        return function.response(function.STATE_SUCCESS, welcome, data,
                                 actions)
Example #20
0
    def execute(self, data):
        habitid = data[0]
        date    = data[1]
        status  = data[2]

        current = self.function.state(date, habitid)

        if current == None:
            result = self.function.kernel.call('list', 'add', ['#!habits_%s' % date, '%s|%s' % (habitid, status)])
        else:
            result = self.function.kernel.call('list', 'update', ['#!habits_%s' % date, current['id'], '%s|%s' % (habitid, status)])

        if result.state != function.STATE_SUCCESS:
            note = "Failed to update habit! (%s)" % result.message
            return function.response(function.STATE_FAILURE, note)

        if date == self.function.date_today():
            redirect = ('habit', 'view')
            date = 'today'
        else:
            redirect = ('habit', 'view', [date])

        return function.redirect(
            self,
            redirect,
            notification='Updated habit entry for %s' % date,
            context='list item %s' % habitid
        )
Example #21
0
    def execute(self, data):
        habitid = data[0]
        date = data[1]
        status = data[2]

        current = self.function.state(date, habitid)

        if current == None:
            result = self.function.kernel.call(
                'list', 'add',
                ['#!habits_%s' % date,
                 '%s|%s' % (habitid, status)])
        else:
            result = self.function.kernel.call('list', 'update', [
                '#!habits_%s' % date, current['id'],
                '%s|%s' % (habitid, status)
            ])

        if result.state != function.STATE_SUCCESS:
            note = "Failed to update habit! (%s)" % result.message
            return function.response(function.STATE_FAILURE, note)

        if date == self.function.date_today():
            redirect = ('habit', 'view')
            date = 'today'
        else:
            redirect = ('habit', 'view', [date])

        return function.redirect(self,
                                 redirect,
                                 notification='Updated habit entry for %s' %
                                 date,
                                 context='list item %s' % habitid)
Example #22
0
    def execute(self, data):
        user = self.function.kernel.getConfig('username')
        date = self.function.kernel.inClientTimezone(datetime.datetime.now()).strftime('%A %B %d, %Y')
        welcome = 'Hi %s. Today is %s' % (user, date)

        weather = self._get_weather()
        if weather and weather.state == function.STATE_SUCCESS:
            data = []
            for line in weather.data:
                data.append(line[0:1])
        else:
            data = []

        tosort = self.function.kernel.call('list', 'view', ['tosort'])
        if tosort.state == function.STATE_SUCCESS:
            data.append(['==== To-Sort (%d) ====' % len(tosort.data), 'list view tosort'])

        today = self.function.kernel.call('list', 'view', ['today'])
        if today.state == function.STATE_SUCCESS:
            data.append(['==== Today ====', 'list view today'])
            data += today.data

        actions = []
        actions.append(["Add to today...", "list add #today %List_item"])
        actions.append(["Add to To-Sort...", "list add #tosort %List_item"])

        return function.response(function.STATE_SUCCESS, welcome, data, actions)
Example #23
0
    def execute(self, data):
        lstkey = normalise_tag(data[0])
        itemid = data[1]

        l = lstobj(self.function, lstkey)
        itemdata = l.get(itemid, lstkey)

        data = []
        if not itemdata:
            data.append(['View list "%s"' % lstkey, "list view %s" % lstkey])
            resp = function.response(function.STATE_FAILURE, 'No item to delete in list "%s"' % lstkey)
            resp.data = data
            resp.write = 1
            return resp

        tags = l.get_tags(itemid)
        for t in tags:
            l.remove_tag(itemid, t['tag'])
            data.append(['View list "%s"' % t['tag'], "list view %s" % t['tag']])

        resp_text = 'Deleting "%s" from %s' % (itemdata['item'], tags_as_readable_string([tag['tag'] for tag in tags]))

        return function.redirect(
            self,
            ('list', 'view', [lstkey]),
            notification=resp_text
        )
Example #24
0
    def execute(self, data):

        # TODO validate date
        if len(data) < 1 or data[0] == '':
            date = self.function.date_today()
        else:
            date = data[0]

        today = date == self.function.date_today()

        h = self.function.kernel.call('list', 'view', ['!habits'])

        actions = [
                ("Habit overview", "habit overview"),
                ("Add new habit...", "list add #!habits %Habit_name"),
                ('Previous', 'habit view %s' % self.function.date_previous(date)),
        ]

        data = []
        if h.state != function.STATE_SUCCESS:
            note = "No habits found. Add one!"
            return function.response(function.STATE_FAILURE, note, data, actions)

        complete = self.function.states(date)
        for item in h.data:
            item_id = str(item[3]['id'])
            # Check if complete
            c = complete[item_id]['status'] if item_id in complete.keys() else 'N'

            if c == 'N':
                item_actions = {'Completed!': 'habit update %s %s Y' % (item_id, date)}
                icon = u'\u2717'
            else:
                item_actions = {'Uncomplete': 'habit update %s %s N' % (item_id, date)}
                icon = u'\u2713'

            item_meta       = {'id': item_id, 'context': 'list item %s' % item_id}
            item_text       = u'%s %s' % (icon, item[0])
            data.append([item_text, None, item_actions, item_meta])

        if today:
            note = 'Viewing today\'s habits'
        else:
            note = 'Viewing %s habits' % date

        return function.response(function.STATE_SUCCESS, note, data, actions)
Example #25
0
    def execute(self, data):

        message = 'Default menu items'
        items = [['Home', 'server connect'], ['Server', 'server default'],
                 ['List', 'list default'], ['Logs', 'log view'],
                 ['Log Add', 'log add %Log_entry'], ['Help', 'help view']]

        return function.response(function.STATE_SUCCESS, message, items)
Example #26
0
    def execute(self, data):
        name = data[0]

        loc = location(self.function)
        loc.get_latest(name)

        if not loc.id:
            return function.response(function.STATE_FAILURE,
                                     'No locations reported for "%s"' % name)

        data = []
        data.append([loc.place])
        data.append([
            self.function.kernel.inClientTimezone(
                loc.time).strftime('%y/%m/%d %I:%M%P')
        ])

        return function.response(function.STATE_SUCCESS,
                                 'Last reported location for "%s"' % name,
                                 data)
Example #27
0
    def execute(self, data):
        menudata = self.function.kernel.call('list', 'view', ['#!menu'])

        menu = []
        for i in menudata.data:
            title, _, call = i[0].partition('|')
            menu.append([title.rstrip(), call.lstrip()])

        # Return menu items
        message = 'Menu'
        return function.response(function.STATE_SUCCESS, message, menu, menudata.actions)
Example #28
0
    def execute(self, data):
        atype = data[0]
        auid = data[1]

        results = self.function.account_search(atype, auid)
        data = []
        for c in results:
            data.append([c.name, 'contact view %s' % c.id])

        return function.response(
            function.STATE_SUCCESS,
            'Contacts with "%s" account "%s"' % (atype, auid), data)
Example #29
0
    def execute(self, data):
        timestamp = ' '.join(data[0:2])
        title = ' '.join(data[2:])

        if title.strip() == '':
            return function.response(function.STATE_FAILURE, 'No title supplied')

        # Check timestamp is valid
        try:
            raw = datetime.datetime.strptime(timestamp, '%Y-%m-%d %H:%M:%S')
        except ValueError:
            to_fix = [['reminder add %s %s' % (timestamp, title), 'reminder add %%timestamp{{%s}} %%title{{%s}}' % (timestamp, title)]]
            return function.response(function.STATE_FAILURE, 'Invalid format for timestamp (%s)' % timestamp, to_fix)

        e = self.function.create(timestamp, title)

        return function.redirect(
            self,
            ('reminder', 'list'),
            notification='Added reminder event "%s" with timestamp "%s"' % (e.title, e.get_nice_time())
        )
Example #30
0
    def execute(self, data):
        itemid  = data[0]
        tags    = data[1:]

        tags = normalise_tags(tags)
        tagsstr = tags_as_readable_string(tags)
        added = []

        for tag in tags:
            if tag.strip() == '':
                continue

            l = lstobj(self.function, tag)

            itemdata = l.get(itemid)
            data = []
            data.append(['View list "%s"' % tag, "list view %s" % tag])
            added.append(tag)

            if not itemdata:
                resp = function.response(function.STATE_FAILURE, 'No item to tag "%s"' % tag)
                resp.data = data
                resp.write = 1
                return resp

            l.add_tag(itemid, tag)

        if not added:
            return function.response(function.STATE_FAILURE, 'No tag specified')

        if len(added) > 1:
            message = 'Added tags %s to "%s"' % (tagstr, itemdata['item'])
        else:
            message = 'Added tag "%s" to "%s"' % (added[0], itemdata['item'])
        return function.redirect(
            self,
            ('list', 'view', [added[0]]),
            notification=message,
            context='list item %s' % itemid
        )
Example #31
0
    def execute(self, data):
        itemid = data[0]
        l = lstobj(self.function, None)
        itemdata = l.get(itemid, None)

        if not itemdata:
            resp = function.response(function.STATE_FAILURE, 'No item to with id "%s"' % (itemid))
            resp.write = 1
            return resp

        items = l.get_versions(itemid)

        if not len(items):
            actions = []
            tags = l.get_tags(itemid)
            if tags:
                for t in tags:
                    actions.append(['View list "%s"' % t['tag'], "list view %s" % t['tag']])
            return function.response(function.STATE_SUCCESS, 'No previous versions of item "%s"' % (itemid), [], actions)

        data = []
        for item in items:
            item_actions = {}
            #####
            ## Prep tags for each item
            itemtags = l.get_old_tags(item['aid'])
            if itemtags:
                itemtagstr = []
                for t in itemtags:
                    itemtagstr.append(t['tag'])
                    item_actions['[%s]' % t['tag']] = "list view %s" % t['tag']

            if not len(item_actions):
                item_actions = None

            #####
            ## Append item to the list
            data.append([item['item'], None, item_actions])

        return function.response(function.STATE_SUCCESS, 'List previous versions of "%s" with id "%s"' % (itemdata['item'], itemdata['id']), data)
Example #32
0
    def execute(self, data):
        funcs = self.function.kernel.get('function').keys()
        funcs.sort()

        data = []

        for func in funcs:
            if func == 'help':
                continue

            data.append(['%s help' % func, '%s help' % func])

        return function.response(function.STATE_SUCCESS, 'Global Jarvis help menu', data)
Example #33
0
    def execute(self, data):
        contactid = data[0]
        accountid = data[1]

        c = self.function.get_model_instance(Contact, contactid)
        if not c:
            return function.response(
                function.STATE_FAILURE,
                'Contact with id "%s" cannot be found' % contactid)

        a = self.function.get_model_instance(Account, accountid)
        if not a:
            return function.response(
                function.STATE_FAILURE,
                'Contact with id "%s" cannot be found' % contactid)

        a.delete()

        return function.redirect(
            self, ('contact', 'view', [contactid]),
            notification='Deleted "%s" account from contact "%s"' %
            (a.type, c.name))
Example #34
0
    def execute(self, terms):
        termstr = '", "'.join(terms)
        l = lstobj(self.function, [])

        items = l.search(terms)
        if not len(items):
            return self._no_items_in_list([])

        data = []
        for item in items:
            data.append(self._display_list_item(item))

        return function.response(function.STATE_SUCCESS, 'Results when searching for "%s"' % termstr, data)
Example #35
0
    def execute(self, data):
        tag    = normalise_tag(data[0])
        itemid = data[1]
        item   = ' '.join(data[2:])

        if item.strip() == '':
            return function.response(function.STATE_FAILURE, 'No new item content')

        l = lstobj(self.function, tag)
        itemdata = l.get(itemid, tag)

        if not itemdata or item == itemdata['item']:

            if not itemdata:
                errstr = 'No item to update to "%s" in list "%s"' % (item, tag)
            else:
                errstr = 'No change made to "%s" so not updated' % (itemdata['item'])

            data = [['View list "%s"' % tag, "list view %s" % tag]]
            resp = function.response(function.STATE_FAILURE, errstr)
            resp.data = data
            resp.write = 1
            return resp

        updateditem, newtags = extract_tags(item)
        newtags = normalise_tags(newtags)

        l.update(itemdata, updateditem)

        if len(newtags):
            for newtag in newtags:
                l.add_tag(itemid, newtag)

        return function.redirect(
            self,
            ('list', 'view', [tag]),
            notification='Updated item "%s" to "%s"' % (itemid, item),
            context='list item %s' % itemid
        )
Example #36
0
    def execute(self, data):
        funcs = self.function.kernel.get('function').keys()
        funcs.sort()

        data = []

        for func in funcs:
            if func == 'help':
                continue

            data.append(['%s help' % func, '%s help' % func])

        return function.response(function.STATE_SUCCESS,
                                 'Global Jarvis help menu', data)
Example #37
0
    def execute(self, data):
        description = ' '.join(data)

        if description.strip() == '':
            return function.response(function.STATE_FAILURE, 'No log entry specified')

        l = self.function.add(description)
        item_time = self.function.kernel.inClientTimezone(l.entrytime).strftime('%y/%m/%d %I:%M%P')

        return function.redirect(
            self,
            ('log', 'view'),
            notification='Added log entry "%s" with timestamp "%s"' % (l.description, item_time)
        )
Example #38
0
    def execute(self, data):

        name = ' '.join(data).strip()

        if name == '':
            return function.response(function.STATE_FAILURE,
                                     'No name supplied')

        c = Contact(self.function, {'name': name})
        c.create()

        return function.redirect(self, ('contact', 'list'),
                                 notification='Added contact "%s"' % c.name,
                                 context='contact view %s' % c.id)
Example #39
0
    def execute(self, data):
        contactid = data[0]

        c = self.function.get_model_instance(Contact, contactid)
        if not c:
            return function.response(
                function.STATE_FAILURE,
                'Contact with id "%s" cannot be found' % contactid)

        c.delete()

        return function.redirect(self, ('contact', 'list'),
                                 notification='Deleted contact "%s"' %
                                 (c.name))
Example #40
0
    def execute(self, data):

        command = ' '.join(data)
        newitem, tags = extract_tags(command)

        tags = [normalise_tag(t) for t in tags]

        if not len(tags):
            return function.response(function.STATE_FAILURE,
                                     'No tag specified')

        if newitem.strip() == '':
            return function.response(function.STATE_FAILURE, 'No item to add')

        l = lstobj(self.function, tags[0])
        itemid = l.add_new(newitem)

        for tag in tags[1:]:
            l.add_tag(itemid, tag)

        return function.redirect(
            self, ('list', 'view', tags),
            'Added "%s" with tags "%s"' % (newitem, '", "'.join(tags)))
Example #41
0
    def execute(self, data):
        description = ' '.join(data)

        if description.strip() == '':
            return function.response(function.STATE_FAILURE,
                                     'No log entry specified')

        l = self.function.add(description)
        item_time = self.function.kernel.inClientTimezone(
            l.entrytime).strftime('%y/%m/%d %I:%M%P')

        return function.redirect(
            self, ('log', 'view'), 'Added log entry "%s" with timestamp "%s"' %
            (l.description, item_time))
Example #42
0
    def execute(self, data):
        itemid = data[0]
        tags = data[1:]

        tags = [normalise_tag(t) for t in tags]
        added = []

        for tag in tags:
            if tag.strip() == '':
                continue

            l = lstobj(self.function, tag)

            itemdata = l.get(itemid)
            data = []
            data.append(['View list "%s"' % tag, "list view %s" % tag])
            added.append(tag)

            if not itemdata:
                resp = function.response(function.STATE_FAILURE,
                                         'No item to tag "%s"' % tag)
                resp.data = data
                resp.write = 1
                return resp

            l.add_tag(itemid, tag)

        if not added:
            return function.response(function.STATE_FAILURE,
                                     'No tag specified')

        if len(added) > 1:
            alltags = '", "'.join(added)
            message = 'Added tags "%s" to "%s"' % (alltags, itemdata['item'])
        else:
            message = 'Added tag "%s" to "%s"' % (added[0], itemdata['item'])
        return function.redirect(self, ('list', 'view', [added[0]]), message)
Example #43
0
    def execute(self, data):
        str = 'Current Jarvis server stats:'

        db = self.function.kernel.getDataPrimary()
        url    = self.function.kernel.getConfig('web_baseurl')
        pid    = os.getpid()
        cpuuse = '%s%%' % self._call_ps('pcpu')
        memuse = '%skb' % self._call_ps('rss')
        uptime = self._call_ps('etime')
        pyver  = platform.release()
        dbver  = self.function.kernel.getConfig('version')

        fmt = '%Y-%m-%d %H:%M:%S %Z%z'
        server_timezone = tzlocal.get_localzone()
        now = datetime.datetime.now()
        server_time = server_timezone.localize(now)
        client_time = self.function.kernel.inClientTimezone(now)

        # Cron stuff
        crons  = db.loadConfig('lastcronstart', 0)
        cronf  = db.loadConfig('lastcronfinish', 0)
        cronl  = db.loadConfig('longestcron', 0)
        if crons != 0:
            d = datetime.datetime.fromtimestamp(float(crons))
            crons = self.function.kernel.inClientTimezone(d)

        if cronf != 0:
            d = datetime.datetime.fromtimestamp(float(cronf))
            cronf = self.function.kernel.inClientTimezone(d)

        stats = []
        stats.append('Server URL: %s' % url)
        stats.append('Daemon PID: %d' % pid)
        stats.append('Jarvis CPU usage: %s' % cpuuse)
        stats.append('Jarvis memory usage: %s' % memuse)
        stats.append('Jarvis uptime: %s' % uptime)
        stats.append('Server time: %s' % server_time.strftime(fmt))
        stats.append('Client time: %s' % client_time.strftime(fmt))
        stats.append('Last cron start: %s' % crons.strftime(fmt))
        stats.append('Last cron finish: %s' % cronf.strftime(fmt))
        stats.append('Longest cron run (secs): %s' % cronl)
        stats.append('Python version: %s' % pyver)
        stats.append('Database version: %s' % dbver)

        advdata = []
        for stat in stats:
            advdata.append([stat])

        return function.response(function.STATE_SUCCESS, str, advdata)
Example #44
0
    def execute(self, data):
        lstkey = normalise_tag(data[0])
        itemid = data[1]

        l = lstobj(self.function, lstkey)
        itemdata = l.get(itemid, lstkey)

        data = []
        data.append(['View list "%s"' % lstkey, "list view %s" % lstkey])

        if not itemdata:
            resp = function.response(function.STATE_FAILURE, 'No item to remove in list "%s"' % lstkey)
            resp.data = data
            resp.write = 1
            return resp

        l.remove_tag(itemid, lstkey)

        tags = l.get_tags(itemid)
        for t in tags:
            data.append(['View list "%s"' % t['tag'], "list view %s" % t['tag']])

        resp_text = 'Removing "%s" from "%s"' % (itemdata['item'], lstkey)

        if len(tags):
            resp = function.response(function.STATE_SUCCESS, resp_text, lstkey)
            resp.data = data
            resp.write = 1
        else:
            resp = function.redirect(
                self,
                ('list', 'view', [lstkey]),
                notification=resp_text
            )

        return resp
Example #45
0
    def execute(self, data):
        itemid = data[0]
        timestamp = ' '.join(data[1:3])
        title = ' '.join(data[3:])

        if title.strip() == '':
            return function.response(function.STATE_FAILURE, 'No title supplied')

        # Check timestamp is valid
        try:
            raw = datetime.datetime.strptime(timestamp, '%Y-%m-%d %H:%M:%S')
        except ValueError:
            to_fix = [['reminder update %s %s %s' % (itemid, timestamp, title), 'reminder update %s %%Timestamp{{%s}} %%Title{{%s}}' % (itemid, timestamp, title)]]
            return function.response(function.STATE_FAILURE, 'Invalid format for timestamp (%s)' % timestamp, to_fix)

        e = self.function.get(itemid)
        e.update({'timestamp': timestamp, 'title': title})

        return function.redirect(
            self,
            ('reminder', 'list'),
            notification='Updated reminder event "%s" with timestamp "%s"' % (e.title, e.get_nice_time()),
            context='reminder item %s' % e.id
        )
Example #46
0
    def execute(self, data):
        name        = data[0]
        reporter    = data[1]
        place       = data[2]

        loc = location(self.function)
        loc.name = name
        loc.place = place
        loc.reporter = reporter

        loc.add()

        resp = function.response(function.STATE_SUCCESS, 'Updated "%s" location to "%s"' % (name, place))
        resp.write = 1
        return resp
Example #47
0
    def execute(self, tags):
        tags = normalise_tags(tags)
        tagstr = tags_as_readable_string(tags)
        l = lstobj(self.function, tags)

        items = l.get_all()
        if not len(items):
            return self._no_items_in_list(tags)

        ritem = random.choice(items)

        data = []
        data.append([ritem['item'], None])

        return function.response(function.STATE_SUCCESS, 'Random item tagged with %s' % tagstr, data)
Example #48
0
    def execute(self, data):
        lists = self.function.get_all_lists()
        data = []
        for ls in lists:
            # Ignore lists that begin with a hash, these are system lists
            if ls['listname'].startswith('!'):
                continue

            # Get the length of each list
            l = lstobj(self.function, ls['listname'])

            listdesc = '%s (%d)' % (ls['listname'], l.count())

            data.append([listdesc, 'list view %s' % ls['listname']])

        return function.response(function.STATE_SUCCESS, 'Lists available', data)
Example #49
0
    def execute(self, data):
        events = self.function.list()
        data = []
        for e in events:
            item_title =  '%s - %s' % (e.get_nice_time(), e.title)
            item_actions = {
                'Update': 'reminder update %s %%Timestamp{{%s}} %%Title{{%s}}' % (e.id, e.get_input_time(), e.title)
            }
            item_meta = {
                'id': e.id,
                'context': 'reminder item %s' % e.id
            }
            data.append([item_title, None, item_actions, item_meta])

        actions = [('Add new...', 'reminder add %Timestamp %Title')]

        return function.response(function.STATE_SUCCESS, 'Upcoming reminders', data, actions)
Example #50
0
    def execute(self, tags):
        # tags in this case is a list of all the tags supplied
        # tagstr is the tags imploded around whitespace
        tags = normalise_tags(tags)
        tagstr = tags_as_readable_string(tags)
        l = lstobj(self.function, tags)

        items = l.get_all()

        actions = []
        actions.append(["Add...", "list add %s %%List_item" % tags_as_string(tags)])
        if len(tags) > 1:
            for tag in tags:
                actions.append(["List \"%s\"" % tag, 'list view %s' % tag])

        if not len(items):
            return self._no_items_in_list(tags)

        data = []
        for item in items:
            data.append(self._display_list_item(item, tags))

        return function.response(function.STATE_SUCCESS, 'List %s contents' % tagstr, data, actions)