def md(self, week=0): with closing(StringIO()) as s: writer = mdg.Writer(s) writer.write_heading(f'Week {week}: Day {self.number}', 3) writer.writeline(f'Rest: {self.rest}s') writer.writeline() writer.writeline(f'Total: ~{self.estimate()}min') writer.writeline() table = mdg.Table() table.add_column('Pushups') for grp in self.set_groups: _min, _max = grp.rule if _min == 0: table.add_column('<{}'.format(_max)) elif _max >= 0xffffffff: table.add_column('>{}'.format(_min)) else: table.add_column('{}-{}'.format(*grp.rule)) rows = list(zip(*(grp.sets for grp in self.set_groups))) for k, row in enumerate(rows, 1): if k < len(rows): table.append(f'Set {k}', *row) else: table.append(f'Set {k}', *(f'{n}+' for n in row)) writer.write(table) writer.writeline('---') return s.getvalue()
def generate(self): with open('{}/report.md'.format(self.report_folder), 'w') as f: writer = mg.Writer(f) for p in self.pillars.keys(): writer.write_heading(p) unordered = mg.List() print(self.pillars['security']) for k in self.pillars[p]: unordered.append('.'.join(k)) writer.write(unordered) i = 1 for res in self.data: self.create_icon(str(i)) writer.write_heading('![{}](./images/{}.png) {}'.format( res, i, res)) table = mg.Table() table.add_column('') table.add_column('') for key in self.data[res]: if '.' in key: keys = key.split('.') root_keys = map(lambda x: '**{}**'.format(x), keys[:-1]) sub_key = '*{}*'.format(keys[-1]) display_key = '{}.{}'.format('.'.join(root_keys), sub_key) else: display_key = '**{}**'.format(key) val = self.data[res][key] if val.strip().startswith('{'): continue table.append(display_key, val) writer.write(table) for key in self.data[res]: val = self.data[res][key] if not val.strip().startswith('{'): continue writer.write_heading(key, 2) code = mg.Code() code.append(val) writer.write(code) i = i + 1
def main(): """Create README.""" if os.path.isfile('README.md'): readme = overwrite() else: readme = 'README.md' with open(readme, 'w') as f: w = mg.Writer(f) w.write_heading(user_data['project_name'], 1) w.write_hrule() # Description and Key Features w.write_heading('Description', 3) if badge: w.writeline(badge) w.writeline() w.writeline('Version: ' + mg.emphasis(setup_dict['version'])) w.writeline() w.writeline(setup_dict['description']) key_features = mg.List() key_features.append('Feature #1') key_features.append('Feature #2') key_features.append('Feature #3') w.write(key_features) # AUTHORS w.write_heading('Authors', 3) w.write_hrule() authors = mg.List() for i in range(len(setup_dict['author'])): authors.append(mg.link(user_data['url'], setup_dict['author'][i])) w.write(authors) if len(dependencies) > 0: # DEPENDENCIES w.write_heading('Dependencies', 3) w.write_hrule() deps = mg.List() for dep in dependencies: deps.append(dep) if args.django and "django" not in dependencies: deps.append("Django") elif args.pyramid and "pyramid" not in dependencies: deps.append("Pyramid") elif args.flask and "flask" not in dependencies: deps.append("Flask") w.write(deps) if args.verbose: # DOCS w.write_heading('Documentation', 3) w.write_hrule() w.writeline( 'Additional documentation can be found at: YOUR DOC SITE HERE') w.write_heading('Getting Started', 3) w.write_hrule() # GETTING STARTED: Installation requirements w.write_heading(mg.emphasis('Prerequisites'), 5) prereqs = mg.List() prereqs.append( mg.link('https://www.python.org/downloads/', 'python (3.6+)')) prereqs.append(mg.link('https://pip.pypa.io/en/stable/', 'pip')) prereqs.append(mg.link('https://git-scm.com/', 'git')) w.write(prereqs) # GETTING STARTED: Cloning/VE Instructions w.write_heading(mg.emphasis('Installation'), 5) w.writeline( 'First, clone the project repo from Github. Then, change directories into the cloned repository. To accomplish this, execute these commands:' ) w.writeline() w.writeline('`$ git clone {}.git`'.format(user_data['url'])) w.writeline() w.writeline('`$ cd {}`'.format(user_data['project_name'])) w.writeline() w.writeline( 'Now now that you have cloned your repo and changed directories into the project, create a virtual environment named "ENV", and install the project requirements into your VE.' ) w.writeline() w.writeline('`$ python3 -m venv ENV`') w.writeline() w.writeline('`$ source ENV/bin/activate`') w.writeline() w.writeline('`$ pip install -r requirements.txt`') if os.path.isfile('requirements.txt'): with open('requirements.txt', 'r') as f: reqs = [] for line in f: line = line.strip() reqs.append(line) reqs = [i.split('==')[0] for i in reqs] if args.django and "psycopg2" in reqs: # Additional Django setup requirements using PostgreSQL w.writeline() w.writeline( 'Open PostgreSQL using the `psql` command from your Terminal.' ) w.writeline( 'Create a PostgreSQL Database, called YOUR DBNAME HERE, using following command:' ) w.writeline() w.writeline('`USER=# CREATE DATABASE ~YOUR DB NAME HERE~;`') w.writeline() w.writeline( 'Now that your database exists, you can migrate this project\'s data into it. Outside of the PostgreSQL commandline, on the same level as your `manage.py` file, run:' ) w.writeline('`$ ./manage.py migrate`') w.writeline() elif args.django and "mymssql" in reqs: # Additional Django setup requirements using MySQL w.writeline() w.writeline( 'Open MySQL using the `psql` command from your Terminal, with your personal user data.' ) w.writeline( 'Create a PostgreSQL Database, called YOUR DBNAME HERE, using following command:' ) w.writeline() w.writeline('`USER=# CREATE DATABASE ~YOUR DB NAME HERE~;`') w.writeline() w.writeline( 'Now that your database exists, you can migrate this project\'s data into it. Outside of the MySQL commandline, on the same level as your `manage.py` file, run:' ) w.writeline('`$ ./manage.py migrate`') w.writeline() elif args.django and "cx_Oracle" in reqs: # Additional Django setup requirements using Oracle w.writeline() w.writeline( 'Open Oracle using the `sqlplus` command from your Terminal.' ) w.writeline( 'Create an Oracle Database, called YOUR DBNAME HERE, using following command:' ) w.writeline() w.writeline('`USER=# CREATE DATABASE ~YOUR DB NAME HERE~;`') w.writeline() w.writeline( 'Now that your database exists, you can migrate this project\'s data into it. Outside of the Oracle commandline, on the same level as your `manage.py` file, run:' ) w.writeline('`$ ./manage.py migrate`') w.writeline() if args.django: # GETTING STARTED: Serving the App (Django) w.write_heading(mg.emphasis('Serving Locally'), 5) w.writeline(serving_options['django']['instructions']) w.writeline(serving_options['django']['serve_command']) w.writeline(serving_options['django']['hosting']) elif args.pyramid: # GETTING STARTED: Serving the App (Pyramid) w.write_heading(mg.emphasis('Serving Locally'), 5) w.writeline(serving_options['pyramid']['instructions']) w.writeline(serving_options['pyramid']['serve_command']) w.writeline(serving_options['pyramid']['hosting']) elif args.flask: # GETTING STARTED: Serving the App (Flask) w.write_heading(mg.emphasis('Serving Locally'), 5) w.writeline(serving_options['flask']['instructions']) w.writeline(serving_options['flask']['serve_command']) w.writeline(serving_options['flask']['hosting']) # TESTS: Running & Files w.write_heading('Test Suite', 3) w.write_hrule() if len(test_dict.keys()) > 0: w.write_heading(mg.emphasis('Running Tests'), 5) if args.django: w.writeline( 'This is a Django application, and therefore to run tests, run the following command at the same level as `./manage.py`.' ) w.writeline() w.writeline('`./manage.py test`') else: w.writeline( 'This application uses {} as a testing suite. To run tests, run:' .format(mg.link(test_options[testing_mod][0], testing_mod))) w.writeline() w.writeline('`{}`'.format(test_options[testing_mod][1])) w.writeline() w.writeline('To view test coverage, run:') w.writeline() w.writeline('`{}`'.format(test_options[testing_mod][2])) w.write_heading(mg.emphasis('Test Files'), 5) w.writeline('The testing files for this project are:') w.writeline() test_table = mg.Table() test_table.add_column('File Name', mg.Alignment.CENTER) test_table.add_column('Description', mg.Alignment.CENTER) for key, val in test_dict.items(): test_table.append('`{}`'.format(key), val) w.write(test_table) else: w.writeline('This repository contains no tests.') # URLS - table if args.django or args.pyramid or args.flask: w.write_heading('URLs', 3) w.write_hrule() w.writeline( 'The URLS for this project can be found in the following modules:' ) w.writeline() urls_table = mg.Table() urls_table.add_column('URL module', mg.Alignment.CENTER) urls_table.add_column('Description', mg.Alignment.CENTER) for key, val in url_dict.items(): urls_table.append(key, val) w.write(urls_table) # APPLICATIONS (Django) -v if args.django and args.verbose: w.write_heading('Django Apps', 3) w.write_hrule() models_list = mg.List() for model in settings_dict['INSTALLED_APPS']: if "django.contrib" not in model and "storages" not in model: models_list.append(model) w.write(models_list) # APPLICATIONS (Pyramid) if args.pyramid: w.write_heading('Pyramid Development Files', 3) w.write_hrule() w.writeline( 'Development files specific to the Pyramid web framework can be found in the following files:' ) pyr_table = mg.List() for key, val in pyramid_info.items(): pyr_table.append(key) w.write(pyr_table) # TOOLS w.write_heading('Development Tools', 3) w.write_hrule() tools_list = mg.List() tools_list.append('{} - programming language'.format( mg.emphasis('python'))) if os.path.isfile('requirements.txt'): with open('requirements.txt', 'r') as f: reqs = [] for line in f: line = line.strip() reqs.append(line) reqs = [i.split('==')[0] for i in reqs] for package in reqs: if package.lower() in frameworks: tools_list.append('{} - web framework'.format( mg.emphasis(package.lower()))) elif package.lower() in dbms: tools_list.append('{} - DB management system'.format( mg.emphasis(package.lower()))) w.write(tools_list) if args.verbose: # CONTRIBUTIONS w.write_heading('Contributions', 3) w.write_hrule() w.writeline( 'If you wish to contribute to this project, please contact {}.' .format(setup_dict['author_email'])) # LICENSE w.write_heading('License', 3) w.write_hrule() w.writeline(license) # ACKNOWLEDGEMENTS w.write_heading('Acknowledgements', 3) w.write_hrule() shoutouts = mg.List() shoutouts.append('Coffee') w.write(shoutouts) w.writeline( mg.emphasis('This README was generated using ' + mg.link( 'https://github.com/chelseadole/write-me', 'writeme.'))) print(""" README generated. User TODOs: * Add application highlights to bullet-point "Features" section * Add correct contributor Github URL links to "Authors" section * Populate "Acknowledgements" section Please review your new README, and complete any sections that require additional user input. """)
def main(): """Create README.""" if os.path.isfile('README.md'): readme = overwrite() else: readme = 'README.md' with open(readme, 'w') as f: w = mg.Writer(f) w.write_heading(user_data['project_name'], 1) w.write_hrule() # Description and Key Features if badge: w.writeline(badge) w.writeline() w.writeline('Version: ' + mg.emphasis(setup_dict['version'])) w.writeline() w.writeline(setup_dict['description']) key_features = mg.List() key_features.append('Feature #1') key_features.append('Feature #2') key_features.append('Feature #3') w.write(key_features) # AUTHORS w.write_heading('Authors', 3) w.write_hrule() authors = mg.List() for i in range(len(setup_dict['author'])): authors.append( mg.link(user_data['project_user_profile_url'], setup_dict['author'][i])) w.write(authors) # DEPENDENCIES w.write_heading('Dependencies', 3) w.write_hrule() deps = mg.List() for dep in dependencies: deps.append(dep) w.write(deps) if args.verbose: # DOCS w.write_heading('Documentation', 3) w.write_hrule() w.writeline('Additional documentation can be found at: {}'.format( 'http://write-me.readthedocs.io/en/stable/')) w.write_heading('Getting Started', 3) w.write_hrule() w.write_heading('Getting Started', 3) # GETTING STARTED: Installation requirements w.write_heading(mg.emphasis('Prerequisites'), 5) prereqs = mg.List() prereqs.append( mg.link('https://www.python.org/downloads/', 'python (3.6+)')) prereqs.append(mg.link('https://pip.pypa.io/en/stable/', 'pip')) prereqs.append(mg.link('https://git-scm.com/', 'git')) w.write(prereqs) # GETTING STARTED: Cloning/VE Instructions w.write_heading(mg.emphasis('Installation'), 5) w.writeline( 'First, clone the project repo from Github. Then, change directories into the cloned repository. To accomplish this, execute these commands:' ) w.writeline() w.writeline('`$ git clone {}.git`'.format(user_data['url'])) w.writeline() w.writeline('`$ cd {}`'.format(user_data['project_name'])) w.writeline() w.writeline( 'Now now that you have cloned your repo and changed directories into the project, create a virtual environment named "ENV", and install the project requirements into your VE.' ) w.writeline() w.writeline('`$ python3 -m venv ENV`') w.writeline() w.writeline('`$ source ENV/bin/activate`') w.writeline() w.writeline('`$ pip install -r requirements.txt`') if args.django: # GETTING STARTED: Serving the App (Django) w.write_heading(mg.emphasis('Serving Locally'), 5) w.writeline(serving_options['django']['instructions']) w.writeline(serving_options['django']['serve_command']) w.writeline(serving_options['django']['hosting']) elif args.pyramid: # GETTING STARTED: Serving the App (Pyramid) w.write_heading(mg.emphasis('Serving Locally'), 5) w.writeline(serving_options['pyramid']['instructions']) w.writeline(serving_options['pyramid']['serve_command']) w.writeline(serving_options['pyramid']['hosting']) elif args.flask: # GETTING STARTED: Serving the App (Flask) w.write_heading(mg.emphasis('Serving Locally'), 5) w.writeline(serving_options['flask']['instructions']) w.writeline(serving_options['flask']['serve_command']) w.writeline(serving_options['flask']['hosting']) # TESTS: Running & Files w.write_heading('Test Suite', 3) w.write_hrule() if len(test_dict.keys()) > 0: w.write_heading(mg.emphasis('Running Tests'), 5) w.writeline( 'This application uses {} as a testing suite. To run tests, run:' .format(mg.link(test_options[testing_mod][0], testing_mod))) w.writeline() w.writeline('`{}`'.format(test_options[testing_mod][1])) w.writeline() w.writeline('To view test coverage, run:') w.writeline() w.writeline('`{}`'.format(test_options[testing_mod][2])) w.write_heading(mg.emphasis('Test Files'), 5) w.writeline('The testing files for this project are:') w.writeline() test_table = mg.Table() test_table.add_column('File Name', mg.Alignment.CENTER) test_table.add_column('Description', mg.Alignment.CENTER) for key, val in test_dict.items(): test_table.append('`{}`'.format(key), val) w.write(test_table) # URLS - table if args.django or args.pyramid or args.flask: w.write_heading('URLs', 3) w.write_hrule() w.writeline( 'The URLS for this project can be found in the following modules:' ) w.writeline() urls_table = mg.Table() urls_table.add_column('URL module', mg.Alignment.CENTER) urls_table.add_column('Description', mg.Alignment.CENTER) for key, val in url_dict.items(): urls_table.append(key, val) w.write(urls_table) else: w.writeline('This repository contains no tests.') # APPLICATIONS (Django) -v if args.django and args.verbose: w.write_heading('Django Apps', 3) w.write_hrule() models_list = mg.List() for model in settings_dict['INSTALLED_APPS']: if "django.contrib" not in model: models_list.append(model) w.write(models_list) # TOOLS w.write_heading('Development Tools', 3) w.write_hrule() tools_list = mg.List() tools_list.append('{} - programming language'.format( mg.emphasis('python'))) if os.path.isfile('requirements.txt'): with open('requirements.txt', 'r') as f: reqs = [] for line in f: line = line.strip() reqs.append(line) reqs = [i.split('==')[0] for i in reqs] for package in reqs: if package.lower() in frameworks: tools_list.append('{} - web framework'.format( mg.emphasis(package.lower()))) elif package.lower() in dbms: tools_list.append('{} - DB management system'.format( mg.emphasis(package.lower()))) elif package.lower() in languages: tools_list.append('{} - programming language'.format( mg.emphasis(package.lower()))) w.write(tools_list) if args.verbose: # CONTRIBUTIONS w.write_heading('Contributions', 3) w.write_hrule() w.writeline( 'If you wish to contribute to this project, please contact {}.' .format(setup_dict['author_email'])) # LICENSE w.write_heading('License', 3) w.write_hrule() w.writeline(license) # ACKNOWLEDGEMENTS w.write_heading('Acknowledgements', 3) w.write_hrule() shoutouts = mg.List() shoutouts.append('Coffee') w.write(shoutouts) w.writeline( mg.emphasis('This README was generated using ' + mg.link( 'https://github.com/chelseadole/write-me', 'writeme.'))) return """
checklist.append('checklist2', True) writer.write(checklist) link = mg.link('link text', 'https://reddit.com') writer.writeline(link) image = mg.Image('https://example.com/link/to/image.png', 'my alt text') writer.writeline(image) code = mg.Code('Python') code.append("s = 'Python syntax highlighting'") code.append("print(s)") writer.write(code) table = mg.Table() table.add_column('col1') table.add_column('col2', mg.Alignment.CENTER) table.add_column('col3', 2) for i in range(3): table.append(*['e{}f{}'.format(i, j) for j in range(3)]) table.append() table.append(mg.strong('e5f1'), image) writer.write(table) blockquote = mg.BlockQuote() blockquote.append('A great man once said...') blockquote.append('- Wayne Gretzky') writer.write(blockquote) blockquote2 = mg.BlockQuote(level=2)