Beispiel #1
0
    def run(self):

        def cb(count):
            self.queue.put('Processed {}'.format(count))

        process_output = parse(self.infile, self.outfile, nodata=self.nodata, callback=cb)
        self.queue.put(process_output)
Beispiel #2
0
 def test_parse(self):
     lat = "N47°40'46.900\""
     lng = "E007°54'53.000\""
     lat, lng = convert.parse(lat, lng)
     self.assertEquals('N', lat['hemisphere'])
     self.assertEquals('E', lng['hemisphere'])
     self.assertEquals(47, lat['deg'])
     self.assertEquals(7, lng['deg'])
     self.assertEquals(40, lat['min'])
     self.assertEquals(54, lng['min'])
     self.assertEquals(46.9, lat['sec'])
     self.assertEquals(53, lng['sec'])
Beispiel #3
0
    def test_one_yaml_boundary(self):
        post = '\n'.join((
            self.have_yaml,
            '---',
            self.have_markdown,
        ))

        with open(self.post_path, 'w') as f:
            f.write(post)

        front_matter, markdown = parse(self.post_path)
        self.assertEqual(front_matter, self.want_yaml)
        self.assertEqual(markdown, self.want_markdown)
Beispiel #4
0
def deploy_file(post_path, args, confluence):
    """Creates or updates a file in Confluence
    
    Arguments:
        post_path {str} -- The absolute path of the post to deploy to Confluence
        args {argparse.Arguments} -- The parsed command-line arguments
        confluence {confluence.Confluence} -- The Confluence API client
    """

    _, ext = os.path.splitext(post_path)
    if ext not in SUPPORTED_FORMATS:
        log.info('Skipping {} since it\'s not a supported format.'.format(
            post_path))
        return

    try:
        front_matter, markdown = parse(post_path)
    except Exception as e:
        log.error(
            'Unable to process {}. Normally not a problem, but here\'s the error we received: {}'
            .format(post_path, e))
        return

    if 'wiki' not in front_matter or not front_matter['wiki'].get('share'):
        log.info(
            'Post {} not set to be uploaded to Confluence'.format(post_path))
        return

    front_matter['author_keys'] = []
    authors = front_matter.get('authors', [])
    for author in authors:
        confluence_author = confluence.get_author(author)
        if not confluence_author:
            continue
        front_matter['author_keys'].append(confluence_author['userKey'])

    # Normalize the content into whatever format Confluence expects
    html, attachments = convtoconf(markdown, front_matter=front_matter)

    static_path = os.path.join(args.git, 'static')
    for i, attachment in enumerate(attachments):
        attachments[i] = os.path.join(static_path, attachment.lstrip('/'))

    slug_prefix = '_'.join(author.lower() for author in authors)
    post_slug = get_slug(post_path, prefix=slug_prefix)

    ancestor_id = front_matter['wiki'].get('ancestor_id', args.ancestor_id)
    space = front_matter['wiki'].get('space', args.space)

    tags = front_matter.get('tags', [])
    if args.global_label:
        tags.append(args.global_label)

    page = confluence.exists(slug=post_slug,
                             ancestor_id=ancestor_id,
                             space=space)
    if page:
        confluence.update(page['id'],
                          content=html,
                          title=front_matter['title'],
                          tags=tags,
                          slug=post_slug,
                          space=space,
                          ancestor_id=ancestor_id,
                          page=page,
                          attachments=attachments)
    else:
        confluence.create(content=html,
                          title=front_matter['title'],
                          tags=tags,
                          slug=post_slug,
                          space=space,
                          ancestor_id=ancestor_id,
                          attachments=attachments)
Beispiel #5
0
 def test_decimal_minutes(self):
     lat = "N47°40'46.900\""
     lng = "E007°54'53.000\""
     lat, lng = convert.parse(lat, lng)
     self.assertEquals('N 47° 40.782" E 7° 54.883"', convert.decimal_minutes(lat, lng))
Beispiel #6
0
 def test_decimal(self):
     lat = "N47°40'46.900\""
     lng = "E007°54'53.000\""
     lat, lng = convert.parse(lat, lng)
     self.assertEquals('N47.67969 E7.91472', convert.decimal(lat, lng))