示例#1
0
def glance_id(name):
    # FIXME: We don't handle images with uuid as name
    if utils.is_uuid(name):
        return name
    name = glance_ids(name)
    # In case of multiple images, only do the first one
    if name and len(name) > 0:
        return list(name)[0]
    # Non-existent image
    return None
示例#2
0
 def _validate(self):
     super()._validate()
     if not is_uuid(self.uuid):
         exit_with(f"Error: `{self.uuid}' is an invalid UUID.")
     if not is_unsigned_int(self.major):
         exit_with("Error: major id is out of bounds (0-65535)")
     if not is_unsigned_int(self.minor):
         exit_with("Error: minor id is out of bounds (0-65535)")
     if not is_sudo():
         exit_with("Error: this script requires superuser privileges.  Please re-run with `sudo.'")
示例#3
0
def glance_id(name):
    # FIXME: We don't handle images with uuid as name
    if utils.is_uuid(name):
        return name
    name = glance_ids(name)
    # In case of multiple images, only do the first one
    if name and len(name) > 0:
        return list(name)[0]
    # Non-existent image
    return None
示例#4
0
    def get_invite(self, request):
        """
        If invite_token is specified in the URL, return the corresponding Invite.
        """
        invite_token = request.GET.get('invite_token')
        if not invite_token or not is_uuid(invite_token):
            return None

        event = get_active_event()
        return Invite.objects.filter(user=request.user,
                                     token=invite_token,
                                     cfp__event=event).first()
示例#5
0
async def fetch_player(user, key, lazy=False):
    user_data_raw = await fetch_player_raw(user, key, lazy=lazy)
    user_data = clean.clean_player(user_data_raw)
    if user_data:
        username = user_data['username']
        uuid = user_data['uuid']
        Caches.username_to_uuid_cache[username] = uuid
    else:
        if utils.is_uuid(user):
            username = await mojang.get_username_from_uuid(user)
            uuid = user
        else:
            uuid = await mojang.get_uuid_from_username(user)
            username = user
        user_data = {
            'uuid': uuid,
            'username': username,
            'rank': None,
            'rank_display': None,
            'rank_color_hex': None,
        }

    return user_data
示例#6
0
 def test_utils_is_uuid(self):
     self.assertTrue(utils.is_uuid(uuid.uuid4()))
     self.assertTrue(utils.is_uuid(str(uuid.uuid4())))
     self.assertFalse(utils.is_uuid(None))
     self.assertFalse(utils.is_uuid(True))
     self.assertFalse(utils.is_uuid(False))
     self.assertFalse(utils.is_uuid(''))
     self.assertFalse(utils.is_uuid(u''))
     self.assertFalse(utils.is_uuid([]))
     self.assertFalse(utils.is_uuid({}))
     self.assertFalse(utils.is_uuid(set()))
     self.assertFalse(utils.is_uuid(frozenset()))
示例#7
0
 def test_utils_is_uuid(self):
     self.assertTrue(utils.is_uuid(uuid.uuid4()))
     self.assertTrue(utils.is_uuid(str(uuid.uuid4())))
     self.assertFalse(utils.is_uuid(None))
     self.assertFalse(utils.is_uuid(True))
     self.assertFalse(utils.is_uuid(False))
     self.assertFalse(utils.is_uuid(''))
     self.assertFalse(utils.is_uuid(u''))
     self.assertFalse(utils.is_uuid([]))
     self.assertFalse(utils.is_uuid({}))
     self.assertFalse(utils.is_uuid(set()))
     self.assertFalse(utils.is_uuid(frozenset()))
示例#8
0
def stat():
    _, entries = utils.format_inputs()
    entries = [
        entry for entry in entries if settings.POMODORO_TAG in entry['tags']]
    ret = {
        'status': 'INACTIVE',  # ACTIVE|INTERRUPT|COMPLETE|INACTIVE|BREAK
        'desc': '',            # Description of last tracked task
        'seconds': 0.0,        # Total tracking seconds in Pomodoro Mode
        'interrupt': 0,        # Times of interruptions
        'aborted': 0,          # The count of aborted pomodoroes
        'achieved': 0,         # The count of achieved pomodoroes
        'combo': 0,            # The count of archieved pomodoroes in combo
        'max_combo': 0         #
    }
    if not entries:
        return ret

    seconds, end, now = 0.0, None, datetime.datetime.now()
    for entry in entries + [{}]:
        start = utils.parse_utc(entry['start']) if 'start' in entry else now
        gap = (start - end).total_seconds() if end else 0.0
        if start == end:
            ret['seconds'] += seconds
            if seconds < settings.POMODORO_DURATION:
                ret['status'] = 'ACTIVE'
            else:
                ret['status'] = 'COMPLETE'
                ret['combo'] += 1
                ret['achieved'] += 1
                if ret['max_combo'] < ret['combo']:
                    ret['max_combo'] = ret['combo']
            seconds = 0.0
        elif seconds < settings.POMODORO_DURATION:
            ret['interrupt'] += 1
            if gap < settings.POMODORO_ABORT_GAP:
                ret['status'] = 'INTERRUPT'
            else:
                ret['status'] = 'INACTIVE'
                ret['aborted'] += 1
                ret['combo'] = 0
                ret['seconds'] += seconds
                seconds = 0
        else:
            ret['seconds'] += seconds
            ret['combo'] += 1
            ret['achieved'] += 1
            if ret['max_combo'] < ret['combo']:
                ret['max_combo'] = ret['combo']
            seconds = 0.0
            break2 = end + datetime.timedelta(seconds=(
                settings.POMODORO_SHORT_BREAK
                if ret['combo'] % settings.POMODORO_SET_COUNT
                else settings.POMODORO_LONG_BREAK))
            if (start - break2).total_seconds() >= settings.POMODORO_COMBO_GAP:
                ret['combo'] = 0
                ret['status'] = 'INACTIVE'
            else:
                ret['status'] = break2.strftime('BREAK TO %H:%M')
        end = utils.parse_utc(entry['end']) if 'end' in entry else now
        seconds += (end - start).total_seconds()
    else:
        ret['seconds'] += seconds

    for tag in entries[-1]['tags']:
        if utils.is_uuid(tag):
            ret['desc'] = commands.getoutput('task _get %s.description' % tag)
            break

    return ret