Exemple #1
0
def render_step_file(input_fn, output_fn=None, conf=None):
    input_fn_base = os.path.basename(input_fn)
    logger.debug('generating step file for {0}'.format(input_fn_base))
    steps = Steps(input_fn)
    logger.debug('resolved step file input for {0}'.format(input_fn_base))

    r = RstCloth()

    web_output = WebStepsOutput(steps, conf=conf)
    web_output.render()
    r.content(web_output.rst.data, indent=0, wrap=False)
    logger.debug('generated web output for {0}'.format(input_fn_base))

    r.directive('only', 'latex')
    r.newline()
    print_output = PrintStepsOutput(steps, conf=conf)
    print_output.render()
    r.content(print_output.rst.data, indent=3, wrap=False)
    logger.debug('generated print output for {0}'.format(input_fn_base))

    if output_fn is None:
        output_fn = os.path.splitext(input_fn)[0] + '.rst'

    r.write(output_fn)
    logger.debug('wrote step include at {0}'.format(output_fn))
Exemple #2
0
def render_step_file(input_fn, output_fn=None, conf=None):
    input_fn_base = os.path.basename(input_fn)
    logger.debug('generating step file for {0}'.format(input_fn_base))
    steps = Steps(input_fn)
    logger.debug('resolved step file input for {0}'.format(input_fn_base))

    r = RstCloth()

    web_output = WebStepsOutput(steps, conf=conf)
    web_output.render()
    r.content(web_output.rst.data, indent=0, wrap=False)
    logger.debug('generated web output for {0}'.format(input_fn_base))

    r.directive('only', 'latex')
    r.newline()
    print_output = PrintStepsOutput(steps, conf=conf)
    print_output.render()
    r.content(print_output.rst.data, indent=3, wrap=False)
    logger.debug('generated print output for {0}'.format(input_fn_base))

    if output_fn is None:
        output_fn = os.path.splitext(input_fn)[0] + '.rst'

    r.write(output_fn)
    logger.debug('wrote step include at {0}'.format(output_fn))
Exemple #3
0
def generate_hash_file(fn):
    r = RstCloth()

    if os.path.exists(fn):
        with open(fn, 'r') as f:
            existing = f.read()
    else:
        existing = []

    commit = get_commit()

    r.directive('|commit| replace', '``{0}``'.format(commit))

    try:
        if r.data == existing[:-1]:
            logger.info('no new commit(s), not updating {0} ({1})'.format(
                fn, commit[:10]))
            return True
    except TypeError:
        logger.warning('problem generating {0}, continuing'.format(fn))
        with file(fn, 'a'):
            os.utime(fn, times)
    else:
        r.write(fn)
        logger.info('regenerated {0} with new commit hash: {1}'.format(
            fn, commit[:10]))
Exemple #4
0
def render_page(doc, conf): 
    r = RstCloth()
    out_fn = os.path.join(conf.paths.projectroot, conf.paths.source, doc.system_name + '.txt')

    r.title(doc.system_title)
    r.newline()
    r.content(doc.system_description)
    r.newline()

    r.write(out_fn)
Exemple #5
0
def render_step_file(input_fn, output_fn=None):
    steps = Steps(input_fn)
    r = RstCloth()

    web_output = WebStepsOutput(steps)
    web_output.render()
    r.content(web_output.rst.get_block(), indent=0, wrap=False)

    r.directive('only', 'latex')
    r.newline()
    print_output = PrintStepsOutput(steps)
    print_output.render()
    r.content(print_output.rst.get_block(), indent=3, wrap=False)

    if output_fn is None:
        output_fn = os.path.splitext(input_fn)[0] + '.rst'

    r.write(output_fn)
    print('[steps]: rendered step include at ' + output_fn)
Exemple #6
0
def render_step_file(input_fn, output_fn=None):
    steps = Steps(input_fn)
    r = RstCloth()

    web_output = WebStepsOutput(steps)
    web_output.render()
    r.content(web_output.rst.get_block(), indent=0, wrap=False)

    r.directive('only', 'latex')
    r.newline()
    print_output = PrintStepsOutput(steps)
    print_output.render()
    r.content(print_output.rst.get_block(), indent=3, wrap=False)

    if output_fn is None:
        output_fn = os.path.splitext(input_fn)[0] + '.rst'

    r.write(output_fn)
    print('[steps]: rendered step include at ' + output_fn)
Exemple #7
0
def generate_hash_file(fn):
    r = RstCloth()

    if os.path.exists(fn):
        with open(fn, 'r') as f:
            existing = f.read()
    else:
        existing = []

    commit = get_commit()

    r.directive('|commit| replace', '``{0}``'.format(commit))

    try:
        if r.get_block('_all')[0] == existing[:-1]:
            logger.info('no new commit(s), not updating {0} ({1})'.format(fn, commit[:10]))
            return True
    except TypeError:
        logger.warning('problem generating {0}, continuing'.format(fn))
        with file(fn, 'a'):
            os.utime(fn, times)
    else:
        r.write(fn)
        logger.info('regenerated {0} with new commit hash: {1}'.format(fn, commit[:10]))
Exemple #8
0
def generate_hash_file(fn):
    r = RstCloth()

    if os.path.exists(fn):
        with open(fn, 'r') as f:
            existing = f.read()
    else:
        existing = []

    commit = get_commit()

    r.directive('|commit| replace', '``{0}``'.format(commit))

    try:
        if r.get_block('_all')[0] == existing[:-1]:
            print('[build]: no new commit(s), not updating {0} ({1})'.format(fn, commit[:10]))
            return True
    except TypeError:
        print('[ERROR] [build]: problem generating {0}, continuing'.format(fn))
        with file(fn, 'a'):
            os.utime(fn, times)
    else:
        r.write(fn)
        print('[build]: regenerated {0} with new commit hash: {1}'.format(fn, commit[:10]))
Exemple #9
0
def generate_image_pages(dir, name, alt, output, conf=None):
    r = RstCloth()
    conf = lazy_conf(conf)

    image = "/".join([dir, name])
    b = name

    for img_output in output:
        img_output["width"] = str(img_output["width"]) + "px"

        r.newline()

        if "tag" in img_output:
            tag = "-" + img_output["tag"] + ".png"
        else:
            tag = ".png"

        options = [("alt", alt), ("align", "center"), ("figwidth", img_output["width"])]

        if "scale" in img_output:
            options.append(("scale", img_output["scale"]))

        if img_output["type"] == "print":
            r.directive("only", "latex", wrap=False, block=b)
            r.newline()
            r.directive(
                name="figure", arg="/images/{0}{1}".format(name, tag), fields=options, indent=3, content=alt, block=b
            )
        else:
            alt_html = publish_parts(alt, writer_name="html")["body"].strip()
            img_tags = [
                '<div class="figure align-center" style="max-width:{5};">',
                '<img src="{0}/{1}/_images/{2}{3}" alt="{4}">',
                "</img>",
                "{6}</div>",
            ]
            img_str = "".join(img_tags)

            r.directive("only", "website and not html", wrap=False, block=b)
            r.newline()
            r.directive(
                name="raw",
                arg="html",
                content=img_str.format(
                    conf.project.url, conf.git.branches.current, name, tag, alt, img_output["width"], alt_html
                ),
                indent=3,
                block=b,
            )

            r.newline(count=2)

            if img_output["width"] > 600:
                options[2] = ("figwidth", 600)

            r.directive("only", "website and html", wrap=False, block=b)
            r.newline()
            r.directive(
                name="figure", arg="/images/{0}{1}".format(name, tag), fields=options, indent=3, content=alt, block=b
            )

        r.newline(block=b)

    r.write(image + ".rst")
    logger.debug("generated include file {0}.rst".format(image))
Exemple #10
0
def generate_image_pages(dir, name, alt, output, conf=None):
    r = RstCloth()
    conf = lazy_conf(conf)

    image = '/'.join([dir, name])
    b = name

    for img_output in output:
        img_output['width'] = str(img_output['width']) + 'px'

        r.newline()

        if 'tag' in img_output:
            tag = '-' + img_output['tag'] + '.png'
        else:
            tag = '.png'

        options = [('alt', alt), ('align', 'center'), ('figwidth', img_output['width'])]

        if 'scale' in img_output:
            options.append(('scale', img_output['scale']))

        if img_output['type'] == 'print':
            r.directive('only', 'latex', wrap=False, block=b)
            r.newline()
            r.directive(name='figure',
                        arg='/images/{0}{1}'.format(name, tag),
                        fields=options,
                        indent=3,
                        content=alt,
                        block=b)
        else:
            alt_html = publish_parts(alt, writer_name='html')['body'].strip()
            img_tags = ['<div class="figure align-center" style="max-width:{5};">',
                        '<img src="{0}/{1}/_images/{2}{3}" alt="{4}">', '</img>',
                        '{6}</div>' ]
            img_str = ''.join(img_tags)

            r.directive('only', 'website and not html', wrap=False, block=b)
            r.newline()
            r.directive(name='raw', arg='html',
                        content=img_str.format(conf.project.url,
                                               conf.git.branches.current, name, tag, alt,
                                               img_output['width'], alt_html),
                        indent=3,
                        block=b)

            r.newline(count=2)

            if img_output['width'] > 600:
                options[2] = ('figwidth', 600)

            r.directive('only', 'website and html', wrap=False, block=b)
            r.newline()
            r.directive(name='figure',
                        arg='/images/{0}{1}'.format(name, tag),
                        fields=options,
                        indent=3,
                        content=alt,
                        block=b)


        r.newline(block=b)

    r.write(image + '.rst')
    print('[image]: generated include file {0}.rst'.format(image))
Exemple #11
0
class OptionRendered(object):
    def __init__(self, option):
        if not isinstance(option, Option):
            raise TypeError
        else:
            self.option = option

        self.rst = RstCloth()

    def resolve_option_name(self):
        if self.option.directive == 'option':
            if self.option.name.startswith('<'):
                prefix = ''
            else:
                prefix = '--'

            if hasattr(self.option, 'aliases'):
                if hasattr(self.option, 'arguments'):
                    return '{0}{1} {2}, {3}'.format(
                        prefix, self.option.name, self.option.arguments,
                        '{0}, '.format(self.option.arguments).join(
                            self.option.aliases))
                else:
                    return '{0}{1}, {2}'.format(prefix, self.option.name,
                                                ', '.join(self.option.aliases))

            else:
                if hasattr(self.option, 'arguments'):
                    return '{0}{1} {2}'.format(prefix, self.option.name,
                                               self.option.arguments)
                else:
                    return '{0}{1}'.format(prefix, self.option.name)
        else:
            return self.option.name

    def resolve_output_path(self, path):
        name_parts = self.option.name.split(',')

        if len(name_parts) > 1:
            clensed_name = name_parts[0]
        else:
            clensed_name = self.option.name

        fn = '-'.join([
            self.option.directive, self.option.program, clensed_name
        ]) + '.rst'
        return os.path.join(path, fn)

    def render(self, path):
        self.option.replace()

        self.rst.directive(self.option.directive, self.resolve_option_name())
        self.rst.newline()

        if self.option.type is not None:
            self.rst.content('*Type*: {0}'.format(self.option.type), indent=3)
            self.rst.newline()

        if self.option.default is not None:
            self.rst.content('*Default*: {0}'.format(self.option.default),
                             indent=3)
            self.rst.newline()

        if self.option.pre is not None:
            self.rst.content(self.option.pre.split('\n'), indent=3, wrap=False)
            self.rst.newline()

        if self.option.description is not None:
            self.rst.content(self.option.description.split('\n'),
                             indent=3,
                             wrap=False)
            self.rst.newline()

        if self.option.post is not None:
            self.rst.content(self.option.post.split('\n'),
                             indent=3,
                             wrap=False)
            self.rst.newline()

        output_file = self.resolve_output_path(path)

        self.rst.write(output_file)

        logger.debug('wrote option to file {0}'.format(output_file))
Exemple #12
0
class OptionRendered(object):
    def __init__(self, option):
        if not isinstance(option, Option):
            raise TypeError
        else:
            self.option = option

        self.rst = RstCloth()

    def resolve_option_name(self):
        if self.option.directive == "option":
            if self.option.name.startswith("<"):
                prefix = ""
            else:
                prefix = "--"

            if hasattr(self.option, "aliases"):
                if hasattr(self.option, "arguments"):
                    return "{0}{1} {2}, {3}".format(
                        prefix,
                        self.option.name,
                        self.option.arguments,
                        "{0}, ".format(self.option.arguments).join(self.option.aliases),
                    )
                else:
                    return "{0}{1}, {2}".format(prefix, self.option.name, ", ".join(self.option.aliases))

            else:
                if hasattr(self.option, "arguments"):
                    return "{0}{1} {2}".format(prefix, self.option.name, self.option.arguments)
                else:
                    return "{0}{1}".format(prefix, self.option.name)
        else:
            return self.option.name

    def resolve_output_path(self, path):
        name_parts = self.option.name.split(",")

        if len(name_parts) > 1:
            clensed_name = name_parts[0]
        else:
            clensed_name = self.option.name

        fn = "-".join([self.option.directive, self.option.program, clensed_name]) + ".rst"
        return os.path.join(path, fn)

    def render(self, path):
        self.option.replace()

        self.rst.directive(self.option.directive, self.resolve_option_name())
        self.rst.newline()

        if self.option.default is not None:
            self.content("*Default*: {0}".format(self.option.default))
            self.rst.newline()

        if self.option.type is not None:
            self.content("*Type*: {0}".format(self.option.type))
            self.rst.newline()

        if self.option.pre is not None:
            self.rst.content(self.option.pre.split("\n"), indent=3, wrap=False)
            self.rst.newline()

        if self.option.description is not None:
            self.rst.content(self.option.description.split("\n"), indent=3, wrap=False)
            self.rst.newline()

        if self.option.post is not None:
            self.rst.content(self.option.post.split("\n"), indent=3, wrap=False)
            self.rst.newline()

        output_file = self.resolve_output_path(path)
        self.rst.write(output_file)
Exemple #13
0
def generate_image_pages(dir, name, alt, output, conf=None):
    r = RstCloth()
    conf = lazy_conf(conf)

    image = '/'.join([dir, name])
    b = name

    for img_output in output:
        img_output['width'] = str(img_output['width']) + 'px'

        r.newline()

        if 'tag' in img_output:
            tag = '-' + img_output['tag'] + '.png'
        else:
            tag = '.png'

        options = [('alt', alt), ('align', 'center'), ('figwidth', img_output['width'])]

        if 'scale' in img_output:
            options.append(('scale', img_output['scale']))

        if img_output['type'] == 'print':
            r.directive('only', 'latex', wrap=False, block=b)
            r.newline()
            r.directive(name='figure',
                        arg='/images/{0}{1}'.format(name, tag),
                        fields=options,
                        indent=3,
                        content=alt,
                        block=b)
        else:
            alt_html = publish_parts(alt, writer_name='html')['body'].strip()
            img_tags = ['<div class="figure align-center" style="max-width:{5};">',
                        '<img src="{0}/{1}/_images/{2}{3}" alt="{4}">', '</img>',
                        '{6}</div>' ]
            img_str = ''.join(img_tags)

            r.directive('only', 'website and not html', wrap=False, block=b)
            r.newline()
            r.directive(name='raw', arg='html',
                        content=img_str.format(conf.project.url,
                                               conf.git.branches.current, name, tag, alt,
                                               img_output['width'], alt_html),
                        indent=3,
                        block=b)

            r.newline(count=2)

            if img_output['width'] > 600:
                options[2] = ('figwidth', 600)

            r.directive('only', 'website and html', wrap=False, block=b)
            r.newline()
            r.directive(name='figure',
                        arg='/images/{0}{1}'.format(name, tag),
                        fields=options,
                        indent=3,
                        content=alt,
                        block=b)


        r.newline(block=b)

    r.write(image + '.rst')
    logger.debug('generated include file {0}.rst'.format(image))
Exemple #14
0
class OptionRendered(object):
    def __init__(self, option):
        if not isinstance(option, Option):
            raise TypeError
        else:
            self.option = option

        self.rst = RstCloth()

    def resolve_option_name(self):
        if self.option.directive == 'option':
            if self.option.name.startswith('<'):
                prefix = ''
            else:
                prefix = '--'

            if hasattr(self.option, 'aliases'):
                if hasattr(self.option, 'arguments'):
                    return '{0}{1} {2}, {3}'.format(prefix, self.option.name,
                                                    self.option.arguments,
                                                    '{0}, '.format(self.option.arguments).join(self.option.aliases))
                else:
                    return '{0}{1}, {2}'.format(prefix, self.option.name,
                                                ', '.join(self.option.aliases))

            else:
                if hasattr(self.option, 'arguments'):
                    return '{0}{1} {2}'.format(prefix, self.option.name,
                                               self.option.arguments)
                else:
                    return '{0}{1}'.format(prefix, self.option.name)
        else:
            return self.option.name

    def resolve_output_path(self, path):
        name_parts = self.option.name.split(',')

        if len(name_parts) > 1:
            clensed_name = name_parts[0]
        else:
            clensed_name = self.option.name

        fn = '-'.join([ self.option.directive, self.option.program, clensed_name ]) + '.rst'
        return os.path.join(path, fn)

    def render(self, path):
        self.option.replace()

        self.rst.directive(self.option.directive, self.resolve_option_name())
        self.rst.newline()

        if self.option.type is not None:
            self.rst.content('*Type*: {0}'.format(self.option.type), indent=3)
            self.rst.newline()

        if self.option.default is not None:
            self.rst.content('*Default*: {0}'.format(self.option.default), indent=3)
            self.rst.newline()

        if self.option.pre is not None:
            self.rst.content(self.option.pre.split('\n'), indent=3, wrap=False)
            self.rst.newline()

        if self.option.description is not None:
            self.rst.content(self.option.description.split('\n'), indent=3, wrap=False)
            self.rst.newline()

        if self.option.post is not None:
            self.rst.content(self.option.post.split('\n'), indent=3, wrap=False)
            self.rst.newline()

        output_file = self.resolve_output_path(path)

        self.rst.write(output_file)

        logger.debug('wrote option to file {0}'.format(output_file))