def OnAttach(status): logging.info('API attachment status: ' + skype.Convert.AttachmentStatusToText(status)) if status == Skype4Py.apiAttachAvailable: skype.Attach(); if status == Skype4Py.apiAttachSuccess: logging.info('Connected t skype!')
def check_template_update(token, current_time): global update_map global update_all if token not in update_map or update_map[token] != current_time: update_map[token] = current_time update_all = True info("Template (%s) changed." % token[:8])
def real_generate(filepath): try: info("Parsing '%s'..." % filepath) return pagegen.generate(filepath, not update_all) except Exception as e: error("Failed to generate %s." % filepath) error("%s" % str(e)) debug("Python traceback:\n" + "".join(traceback.format_tb(e.__traceback__)))
def start(): skype.OnMessageHistory = OnMessageHistory skype.OnAttachmentStatus = OnAttach; skype.OnMessageStatus = OnMessageStatus; logging.info('Connecting to Skype') skype.Attach()
def add_command(name, line, author): logging.info("Attempt to add function %s" % name) version = 0 help = "" if "!" in name: raise InvalidFuncNameError, name if find_command(name): # logging.warn("Dynamic command %s already exists!"%name) version = find_command(name)[0]["version"] help = find_command(name)[0]["help"] elif name in command.com_hooks: raise CannotModifyStdFuncsError, name data.query( "INSERT INTO dynamic VALUES (?,?,?,?,?,?)", (version + 1, name, line, datetime.now().strftime("%Y-%m-%d %H:%M:%S"), help, author), ) command.ComHook(name, command_runfunc, name="%sBot" % name, data=line) return version + 1
"--toc", action="store_true", help="whether to include a table of content in the document", default=False) argpr.add_argument("file", help="path to file that will be converted") args = argpr.parse_args() if args.verbose: logging.LOGGING_LEVEL = logging.LoggingLevel.DEBUG else: levels = [ logging.LoggingLevel.INFO, logging.LoggingLevel.WARN, logging.LoggingLevel.ERROR, logging.LoggingLevel.FATAL, logging.LoggingLevel.NONE ] logging.LOGGING_LEVEL = levels[min(args.quiet, len(levels) - 1)] if args.new: folder = os.path.join(BLOG_FOLDER, today().replace(".", "-")) os.makedirs(folder, exist_ok=True) target = os.path.join(folder, "%s.md" % args.file) if os.path.exists(target): warn("'%s' already exists! pagegen will overwrite it." % target) with open(target, "w") as writer: writer.write(meta_to_string(METAINFO_DEFAULTS)) if args.toc: writer.write("\n[TOC]\n") logging.info("New document created in '%s'." % target) else: generate(args.file)
check_template_update(hash(path), hash(int(os.path.getmtime(path)))) for root, dirs, files in os.walk(os.path.abspath(BLOG_FOLDER)): for name in files: if name.endswith(".md") or name.endswith(".markdown"): generate(root, name) generate(os.path.abspath("."), "index.md") generate(os.path.abspath("."), "about.md") generate(os.path.abspath("."), "posts.md") generate(os.path.abspath("."), "links.md") with open(UPDATE_MAP_FILE, "w") as fp: json.dump(update_map, fp, indent=4, sort_keys=True) if update_count: info("Successfully updated %s page(s)." % update_count) info("Writing to JSON database '%s'..." % DATABASE_LOCATION) database.save_json_index(DATABASE_LOCATION) info("Writing to Tipuesearch database '%s'..." % TIPUESEARCH_DATABASE_LOCATION) database.save_tipuesearch_index(TIPUESEARCH_DATABASE_LOCATION) info("Writing to sitemap '%s'..." % SITEMAP_LOCATION) database.save_text_sitemap(SITEMAP_LOCATION) else: warn("Nothing updated.") if logging.ERROR_CNT or logging.WARN_CNT: info("%s error(s), %s warning(s) generated." % (logging.ERROR_CNT, logging.WARN_CNT))
if not update_all: database.load_index(DATABASE_LOCATION) if os.path.exists(UPDATE_MAP_FILE): with open(UPDATE_MAP_FILE) as fp: update_map = json.load(fp) for root, dirs, files in os.walk(TEMPLATES_FOLDER): for file in files: path = os.path.join(root, file) check_template_update(hash(path), hash(int(os.path.getmtime(path)))) for root, dirs, files in os.walk(os.path.abspath(BLOG_FOLDER)): for name in files: if name.endswith(".md") or name.endswith(".markdown"): generate(root, name) with open(UPDATE_MAP_FILE, "w") as fp: json.dump(update_map, fp, indent=4, sort_keys=True) if update_count: info("Successfully updated %s page(s)." % update_count) info("Writing to JSON database '%s'..." % DATABASE_LOCATION) database.save_json_index(DATABASE_LOCATION) info("Writing to Tipuesearch database '%s'..." % TIPUESEARCH_DATABASE_LOCATION) database.save_tipuesearch_index(TIPUESEARCH_DATABASE_LOCATION) info("Writing to sitemap '%s'..." % SITEMAP_LOCATION) database.save_text_sitemap(SITEMAP_LOCATION) else: warn("Nothing updated.") if logging.ERROR_CNT or logging.WARN_CNT: info("%s error(s), %s warning(s) generated." % (logging.ERROR_CNT, logging.WARN_CNT))
def hook_unloaded(module): if module in module_registrations: for tag in module_registrations[module]: del registered_tags[tag] logging.info("Unregistered tag %s from %s" % (tag, module)) del module_registrations[module]
if __name__ == "__main__": argpr = argparse.ArgumentParser(description="Convert specific Markdown file to HTML page") log_group = argpr.add_mutually_exclusive_group() log_group.add_argument("-v", "--verbose", action="count", help="show more messages", default=0) log_group.add_argument("-q", "--quiet", action="count", help="show less messages", default=0) argpr.add_argument("-n", "--new", action="store_true", help="set to create a new document instead of converting") argpr.add_argument("-t", "--toc", action="store_true", help="whether to include a table of content in the document", default=False) argpr.add_argument("file", help="path to file that will be converted") args = argpr.parse_args() if args.verbose: logging.LOGGING_LEVEL = logging.LoggingLevel.DEBUG else: levels = [logging.LoggingLevel.INFO, logging.LoggingLevel.WARN, logging.LoggingLevel.ERROR, logging.LoggingLevel.FATAL, logging.LoggingLevel.NONE] logging.LOGGING_LEVEL = levels[min(args.quiet, len(levels) - 1)] if args.new: folder = os.path.join(BLOG_FOLDER, today().replace(".", "-")) os.makedirs(folder, exist_ok=True) target = os.path.join(folder, "%s.md" % args.file) if os.path.exists(target): warn("'%s' already exists! pagegen will overwrite it." % target) with open(target, "w") as writer: writer.write(meta_to_string(METAINFO_DEFAULTS)) if args.toc: writer.write("\n[TOC]\n") logging.info("New document created in '%s'." % target) else: generate(args.file)