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))
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]))
def __init__(self, option): if not isinstance(option, Option): raise TypeError else: self.option = option self.rst = RstCloth()
def build_contents(self): self.contents = RstCloth() self.contents.directive('class', 'hidden') self.contents.newline() self.contents.directive('toctree', fields=[('titlesonly', '')], indent=3) self.contents.newline()
def __init__(self, steps): if not isinstance(steps, Steps): raise TypeError else: self.steps = steps self.current_step = 1 self.rst = RstCloth() self.hook()
def __init__(self, imported_table, widths=None, indent=0): self.table = imported_table self.indent = indent if widths is not None: self.widths = [str(i) for i in widths] else: self.widths = None self.r = RstCloth() self._render_table() self.output = self.r.data
def generate_release_untar(builder, release): r = RstCloth() r.directive('code-block', 'sh', block='header') r.newline(block='header') r.content('tar -zxvf mongodb-{0}-{1}.tgz'.format(builder, release), 3, wrap=False, block='cmd') return r
def generate_release_copy(builder, release): r = RstCloth() r.directive('code-block', 'sh', block='header') r.newline(block='header') r.content('mkdir -p mongodb', 3, wrap=False, block='cmd') r.content('cp -R -n mongodb-{0}-{1}/ mongodb'.format(builder, release), 3, wrap=False, block='cmd') return r
def generate_params(params, fn, conf): r = RstCloth() basename = os.path.basename(fn) params.sort(key=lambda p: p['position']) # Begin by generating the table for web output r.directive('only', '(html or singlehtml or dirhtml)', block='htm') r.newline(block='htm') # { filename: { $name: <param> } } ext_params = {} processed_params = [] for param in params: if 'file' in param: pos = param['position'] if param['file'] not in ext_params: fn, ext = populate_external_param(param['file'], basename, conf.paths.projectroot, conf.paths.source) ext_params[fn] = ext param = ext_params[conf.paths.source + param['file']][param['name']] param['position'] = pos processed_params.append(param) r.content(generate_param_table(processed_params), indent=3, block='html') r.newline(block='htm') # Then generate old-style param fields for non-web output r.directive('only', '(texinfo or latex or epub)', block='tex') r.newline(block='tex') for param in processed_params: key, val = generate_param_fields(param) r.field(name=key, value=val, indent=3, wrap=False, block='tex') r.newline(block='tex') return r
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)
def generate_param_table(params): table_data = ParamTable() table_data.set_column_widths(params[0]) table_data.add_header( render_header_row(params[0], table_data.num_rows, table_data.type_column)) for param in params: row = [RstCloth().pre(param['name'])] if table_data.type_column is True: row.append(process_type_cell(param['type'], 'table')) row.append( process_description(param['description'], param['field']['optional'])) table_data.add_row(row) table = TableBuilder(ListTable(table_data, widths=table_data.widths)) return table.output
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]))
def generate_output(builder, platform, version, release): """ This is the legacy version of the function used by the makefile and CLI infrastructure""" r = RstCloth() r.directive('code-block', 'sh', block='header') r.newline(block='header') if release == 'core': r.content( 'curl -O http://downloads.mongodb.org/{0}/mongodb-{1}-{2}.tgz'. format(platform, builder, version), 3, wrap=False, block='cmd') else: r.content( 'curl -O http://downloads.10gen.com/linux/mongodb-{0}-subscription-{1}-{2}.tgz' .format(builder, release, version), 3, wrap=False, block='cmd') r.content('tar -zxvf mongodb-{0}-subscription-{1}-{2}.tgz'.format( builder, release, version), 3, wrap=False, block='cmd') r.content('cp -R -n mongodb-{0}-subscription-{1}-{2}/ mongodb'.format( builder, release, version), 3, wrap=False, block='cmd') r.newline(block='footer') return r
def generate_release_output(builder, platform, architecture, release): """ This is the contemporary version of the function used by the generate.py script""" r = RstCloth() r.directive('code-block', 'sh', block='header') r.newline(block='header') if architecture == 'core': r.content( 'curl -O http://downloads.mongodb.org/{0}/mongodb-{1}-{2}.tgz'. format(platform, builder, release), 3, wrap=False, block='cmd') else: r.content( 'curl -O http://downloads.10gen.com/linux/mongodb-{0}-subscription-{1}-{2}.tgz' .format(builder, architecture, release), 3, wrap=False, block='cmd') r.content('tar -zxvf mongodb-{0}-subscription-{1}-{2}.tgz'.format( builder, architecture, release), 3, wrap=False, block='cmd') r.content('cp -R -n mongodb-{0}-subscription-{1}-{2}/ mongodb'.format( builder, architecture, release), 3, wrap=False, block='cmd') r.newline(block='footer') return r
def build_page(data, conf): fn = os.path.join(conf.paths.projectroot, conf.paths.includes, 'metadata.yaml') if not os.path.exists(fn): return None else: iconf = BuildConfiguration(fn) r = RstCloth() r.title(iconf.title) r.newline() r.directive('default-domain', iconf.domain) r.newline() if 'introduction' in iconf: r.content(iconf.introduction) r.newline() r.directive(name='contents', arg='Included Files', fields=[ ('backlinks', 'none'), ('class', 'long-toc'), ('depth', 1), ('local', ''), ]) r.newline() data = data.items() data.sort() for _, record in data: page_name = r.pre(record['name']) r.heading(text=page_name, char='-', indent=0) r.newline() r.heading('Meta', char='~', indent=0) r.newline() if record['num_clients'] == 0: r.content('{0} is not included in any files.'.format(page_name)) r.newline() add_content(r, record) elif record['num_clients'] == 1: if record['yaml_only']: r.content( '{0} is only included in yaml files.'.format(page_name)) r.newline() else: link = r.role('doc', record['clients'][0]) r.content('{0} is only included in {1}.'.format( page_name, link)) r.newline() add_meta(r, page_name, record) add_content(r, record) else: r.content('{0} is included in **{1}** files.'.format( page_name, record['num_clients']), wrap=False) r.newline() add_meta(r, page_name, record) if record['yaml_only'] is False: clients = [ p for p in record['clients'] if not p.startswith('/includes') ] if len(clients) == 1: client_link = r.role('doc', clients[0]) inc_str = '{0} is the only file that includes {1} that is not also an include.' r.content(inc_str.format(client_link, page_name)) r.newline() else: r.heading('Client Pages', char='~', indent=0) r.newline() for pg in clients: client_link = r.role('doc', pg) r.li(client_link, wrap=False) r.newline() add_include_example(r, page_name, record['path']) add_content(r, record) return r
def build_dfn(self): self.dfn = RstCloth() self.dfn.directive('class', 'toc') self.dfn.newline()
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))