def update_readme(self): """ Adds a brief copyright and licensing statement to the readme file. For longer licenses the reader is referred to the appropriate COPYING/LICENSE/etc file, while for shorter licenses (BSD, MIT, etc) the full license is appended to the README. """ # Check if there is already a readme file dirlist = os.listdir(self.cwd) readme_file = [x for x in dirlist if x is "README" or "readme." in x.lower()] if len(readme_file) == 0: readme_filename = "README" else: readme_filename = readme_file[0] # Append notice to the README with open(readme_filename, "a") as readme: resource_location = "data/readme-statements/" + self.license # Again, pkg_resource API requires paths joined by '/'. # Don't use os.path.join readme_statement = pkg_resources.resource_stream("garnish", resource_location) text_to_add = readme_statement.read() text_to_add = fill_template(text_to_add, self.args, self.longname, self.license_filename, self.url) text_to_add = wrap_paragraphs(text_to_add, 80) readme.writelines("\n\n" + text_to_add) status_msg = "Copyright statement added to " + readme_filename print status_msg logging.info(status_msg)
def update_readme(self): """ Adds a brief copyright and licensing statement to the readme file. For longer licenses the reader is referred to the appropriate COPYING/LICENSE/etc file, while for shorter licenses (BSD, MIT, etc) the full license is appended to the README. """ # Check if there is already a readme file dirlist = os.listdir(self.cwd) readme_file = [ x for x in dirlist if x is 'README' or 'readme.' in x.lower() ] if len(readme_file) == 0: readme_filename = 'README' else: readme_filename = readme_file[0] # Append notice to the README with open(readme_filename, 'a') as readme: resource_location = 'data/readme-statements/' + self.license # Again, pkg_resource API requires paths joined by '/'. # Don't use os.path.join readme_statement = pkg_resources.resource_stream( 'garnish', resource_location) text_to_add = readme_statement.read() text_to_add = fill_template(text_to_add, self.args, self.longname, self.license_filename, self.url) text_to_add = wrap_paragraphs(text_to_add, 80) readme.writelines('\n\n' + text_to_add) status_msg = 'Copyright statement added to ' + readme_filename print status_msg logging.info(status_msg)
def listing(comment: Comment, message_to: str) -> None: try: LISTING_TEMPLATE = fill_template( template=read_file("./template/LISTING.md"), replaced={ "author": comment.author.name, "floods": "\n".join([f"- {key}" for key in list(floods.keys())]), "mark": config["mark"], "command-base": config["commands"]["base"], "source-code": config["source-code"], "add-flood": f"https://www.reddit.com/message/compose?to=u/{message_to}&{urlencode(config['send-message']['add-flood'], quote_via=quote)}", "make-suggestion": f"https://www.reddit.com/message/compose?to=u/{message_to}&{urlencode(config['send-message']['make-suggestion'], quote_via=quote)}", "report-error": f"https://www.reddit.com/message/compose?to=u/{message_to}&{urlencode(config['send-message']['report-error'], quote_via=quote)}", }, ) if ( f"{config['mark']}{config['commands']['list']}" in comment.body and not comment.saved ): logger.info( f"{comment.body} from u/{comment.author} in r/{comment.subreddit}" ) logger.info(f"Replied to https://reddit.com{comment.permalink}") if PY_ENV == "production": comment.reply(LISTING_TEMPLATE) comment.save() elif PY_ENV == "development": logger.info(LISTING_TEMPLATE) except Exception: comment.unsave() logger.exception( f"Error occurred while replied to https://reddit.com{comment.permalink}" )
def flood(comment: Comment, message_to: str) -> None: try: FLOOD_TEMPLATE = fill_template( template=read_file("./template/FLOOD.md"), replaced={ "author": comment.author.name, "mark": config["mark"], "command-list": config["commands"]["list"], "source-code": config["source-code"], "add-flood": f"https://www.reddit.com/message/compose?to=u/{message_to}&{urlencode(config['send-message']['add-flood'], quote_via=quote)}", "make-suggestion": f"https://www.reddit.com/message/compose?to=u/{message_to}&{urlencode(config['send-message']['make-suggestion'], quote_via=quote)}", "report-error": f"https://www.reddit.com/message/compose?to=u/{message_to}&{urlencode(config['send-message']['report-error'], quote_via=quote)}", "flood": "{flood}", }, ) for key, value in floods.items(): if ( key.lower().strip() in comment.body and f"{config['mark']}{config['commands']['base']}" in comment.body and not comment.saved ): FLOOD_TEMPLATE = fill_template( template=FLOOD_TEMPLATE, replaced={"flood": value.strip()} ) logger.info( f"{comment.body} from u/{comment.author} in r/{comment.subreddit}" ) logger.info(f"Replied to https://reddit.com{comment.permalink}") # DEBUG: if PY_ENV == "production": comment.reply(FLOOD_TEMPLATE) elif PY_ENV == "development": logger.info(FLOOD_TEMPLATE) except Exception: comment.unsave() logger.exception( f"Error occurred while replied to https://reddit.com{comment.permalink}" )
def build_header_message(filetype): """ Given license information in the args and a file extension string in filetype variable, return a string containing the appropriate in-file licensing header string. """ if filetype in self.comment_chars.keys(): comment_char = self.comment_chars[filetype] else: print 'Could not add header to {0}. Unknown filetype.'.format(filename) return start_msg = comment_char + self.start_msg end_msg = comment_char + self.end_msg temp = self.template notice = [fill_template(x, self.args, self.longname, self.license_filename, self.url) for x in temp] notice = [comment_char + ' ' + x for x in notice] notice = ''.join(notice) complete_header = start_msg + notice + end_msg return complete_header
def create_description_tex_file(problem): utils.fill_template(utils.Templates.TeX.problem(), problem.tex_file) utils.warning([ 'Não se esqueça de preencher a descrição do problema:', ' ' + problem.tex_file ])