Beispiel #1
0
async def puplist(ctx):
    message = ctx.message
    pups = db.get_pups()
    if len(pups) == 0:
        embed = discord.Embed(colour=discord.Colour.red())
        embed.title="No Pups"
        embed.description="There no pups. Add pups with `{0}addpup`".format(COMMAND_PREFIX)
        await message.author.send(embed=embed)
        return
    title="Pup List"
    description=("Here are all the pups!")
    entries = []
    for pup in pups:
        entries.append(paginator.Entry(str(pup['id']),pup['url']))

    # Do paginator for favorites > 10
    if len(entries) > 10:
        pages = paginator.Paginator.format_pages(entries=entries,title=title,description=description)
        p = paginator.Paginator(client,message=message,page_list=pages,as_dm=True)
        await p.paginate(start_page=1)
    else:
        embed = discord.Embed(colour=discord.Colour.teal())
        embed.title = title
        embed.description = description
        for e in entries:
            embed.add_field(name=e.name,value=e.value,inline=False)
    await message.author.send(embed=embed)
Beispiel #2
0
def wp_get_recent_changes_from_cache(config_agent, tpl_render, req_path, limit,
                                     offset):
    view_settings = get_view_settings(config_agent)
    static_files = static_file.get_global_static_files(**view_settings)

    folder_pages_full_path = config_agent.get_full_path("paths", "pages_path")
    local_full_path = mdutils.req_path_to_local_full_path(
        req_path, folder_pages_full_path)
    static_file_prefix = static_file.get_static_file_prefix_by_local_full_path(
        config_agent=config_agent,
        local_full_path=local_full_path,
        req_path=req_path)

    buf = cache.get_recent_changes_from_cache(config_agent)
    all_lines = buf.split()
    total_lines = len(all_lines)

    title = "Recent Changes (%d/%d)" % (offset, total_lines / limit)

    start = offset * limit
    end = start + limit
    lines = all_lines[start:end]

    buf = mdutils.sequence_to_unorder_list(
        folder_pages_full_path=folder_pages_full_path,
        seq=lines,
        **view_settings)
    content = mdutils.md2html(config_agent=config_agent,
                              req_path=req_path,
                              text=buf,
                              static_file_prefix=static_file_prefix,
                              **view_settings)

    pg = paginator.Paginator()
    pg.total = total_lines
    pg.current_offset = offset
    pg.limit = limit
    pg.url = "/~recent"

    return tpl_render.canvas(config=config_agent.config,
                             static_files=static_files,
                             button_path=title,
                             req_path=req_path,
                             title=title,
                             content=content,
                             paginator=pg,
                             **view_settings)
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument("instance_id", help="Instance ID to compare samples for.")
    parser.add_argument("--verbose", help="increase output verbosity", action="store_true")
    args = parser.parse_args()

    instance_id = args.instance_id

    verbose = False
    if args.verbose:
        print("INFO: Verbosity turned on.")
        verbose = True

    print("INFO: This will compare 2 weeks worth of samples for specified instance.")

    # get a token
    creds = credentials.Credentials()
    token = creds.get_token()

    # get config
    conf = config.Config()

    pag = paginator.Paginator(endpoint = conf.ceilometer_endpoint, token = token)
    mon = mongor.Mongor()

    time_end = datetime.utcnow()
    time_begin = time_end - timedelta(days=14)

    samples_api = pag.get_samples_for_instance(instance_id, time_begin, time_end)
    samples_db = mon.get_samples_for_instance(instance_id, time_begin, time_end)

    compare_samples(samples_api, samples_db, verbose)
    event_samples = extract_events_from_samples(samples_db)

    if verbose:
        print("INFO: All the event-based samples:")
        for event in event_samples:
            pprint.pprint(event)
            print("----------------")
    print( "INFO: There are {} event-based samples.".format(len(event_samples)) )
Beispiel #4
0
    def parse_meta_data(self):
        """Parses the meta data from posts
        """
        self.posts = []
        self.tags = {}
        for post in os.listdir(self.config.posts_dir):
            # ignore hidden files
            if post.startswith('.'):
                continue

            post = os.path.join(self.config.posts_dir, post)
            post_meta = template.get_meta_data(post)
            post_meta['date'] = datetime.datetime.strptime(
                post_meta['date'], self.date_format)
            post_url = os.path.join(
                '/', post_meta['date'].strftime(self.config.post_url),
                os.path.splitext(post_meta['filename'].split(
                    self.config.posts_dir)[1][1:])[0])
            post_meta['url'] = post_url
            self.posts.append(post_meta)

            # create tag cloud
            for tag in post_meta.get('tags', []):
                if tag in self.tags:
                    self.tags[tag].append(post_meta)
                else:
                    self.tags[tag] = [post_meta]

        # sort posts based on date.
        self.posts.sort(key=lambda x: x['date'], reverse=True)
        # sort tags based on date
        for tagname in self.tags:
            self.tags[tagname].sort(key=lambda x: x['date'], reverse=True)

        # include next and previous urls for posts. includes post tags
        for post_num, post in enumerate(self.posts):
            post_tags = []
            for tagname in post.get('tags', []):
                tag_url = os.path.join('/', 'tag',
                                       urllib.quote_plus(tagname.lower()))
                post_tags.append({
                    'name': tagname,
                    'url': tag_url,
                    'posts': self.tags[tagname]
                })
            post['tags'] = post_tags
            post['id'] = post['url']
            previous = post_num + 1
            next = post_num - 1
            if previous < len(self.posts):
                post['previous'] = self.posts[previous]
            else:
                post['previous'] = None
            if next >= 0:
                post['next'] = self.posts[next]
            else:
                post['next'] = None

        # tags for env
        tags_info = []
        for tagname, post in self.tags.iteritems():
            tag_url = os.path.join('/', 'tag',
                                   urllib.quote_plus(tagname.lower()))
            tags_info.append({
                'name': tagname,
                'url': tag_url,
                'posts': self.tags[tagname]
            })

        # create paginator
        self.paginator = paginator.Paginator(self.posts, self.config.paginate)
        # create site information
        site = {}
        site['time'] = datetime.datetime.now()
        # extract site information from settings.yaml
        site.update(getattr(self.config, 'site', {}))
        # update the template global with posts info
        template.env.globals.update({
            'posts': self.posts,
            'site': site,
            'tags': tags_info
        })
Beispiel #5
0
async def pagination(ctx, entries: list, embed=True):
    p = paginator.Paginator(ctx, entries=entries, embed=embed)
    return await p.paginate()