def run(): """Run this action.""" log.debug("run()") old_cwd = os.getcwd() arguments = mdepub.arguments project_path = mdepub.project_path if arguments.fromfile is None: log.fatal("No input file specified.") sys.exit(0) fromf = abspath(arguments.fromfile) with ZipFile(fromf, 'r') as epub: with epub.open("META-INF/source/mdepub_source.zip", 'r') as src_item: src_stream = StringIO(src_item.read()) with ZipFile(src_stream, 'r') as src_zip: with src_zip.open("options.yaml", 'r') as src_opt_item: src_opt = yaml.load(src_opt_item) #print yaml.dump(src_opt) if arguments.to is None: arguments.to = join(old_cwd, clean(src_opt.get('title'))) if arguments.to is None: log.fatal("Can't determine output path name") sys.exit(1) if not exists(arguments.to): os.makedirs(arguments.to) os.chdir(arguments.to) src_zip.extractall() src_stream.close() os.chdir(old_cwd)
def run(): """Run this action.""" log.debug("run()") print "Book title?" title = raw_input("> ") print "Author(s)?" author = raw_input("> ") print "Path to new book project files?\n[default: current directory]" path = raw_input("> ") or "." today = re.sub("^0", "", date.today().strftime("%d %b %Y")) uuid = mdepub.new_id() filename = mdepub.options.get("filename") or clean(title) log.debug("Creating project in \"%s\".", path) if not exists(path): os.makedirs(path) os.chdir(path) if exists("options.yaml"): log.fatal("An mdepub project file already exists in this path.") sys.exit(1) css_content = template.get_file_content("book.css") with open("{}.css".format(filename), 'w') as f: f.write(css_content) txt = template.get_file_content("book.md") with open("{}.md".format(filename), 'w') as f: f.write( txt.format(Title=title, Author=author) ) txt = template.get_file_content("options.yaml") with open("options.yaml", 'w') as f: f.write( txt.format(Title=title, Author=author, Date=today, uuid=uuid) )
def run(): """Run this action.""" log.debug("run()") old_cwd = os.getcwd() arguments = mdepub.arguments project_path = mdepub.project_path if arguments.fromfile is None: log.fatal("No input file specified.") sys.exit(0) fromf = abspath(arguments.fromfile) with ZipFile(fromf, 'r') as epub: with epub.open("META-INF/source/mdepub_source.zip", 'r') as src_item: src_stream = StringIO(src_item.read()) with ZipFile(src_stream, 'r') as src_zip: with src_zip.open("options.yaml", 'r') as src_opt_item: src_opt = yaml.load(src_opt_item) #print yaml.dump(src_opt) if arguments.to is None: arguments.to = join(old_cwd, clean(src_opt.get('title'))) if arguments.to is None: log.fatal("Can't determine output path name") sys.exit(1) if not exists(arguments.to): os.makedirs(arguments.to) os.chdir(arguments.to) src_zip.extractall() src_stream.close() os.chdir(old_cwd)
def init(): """Initialize mdepub package and populate options variable.""" global options global project_path global arguments global log global options_loaded logging.basicConfig(level=logging.WARN) log = logging.getLogger('mdepub') project_path = os.getcwd() log.debug("Working path: %s", project_path) options_file = os.path.join(project_path, "options.yaml") options_loaded = False if os.path.exists(options_file): options_loaded = True log.debug("Loading options.yaml") options = yaml.load(open("options.yaml")) if VERSION.split(".") < (options.get("require mdepub version") or "").split("."): log.fatal("This project requires at least version %s of mdepub.", options["require mdepub version"]) sys.exit(1) #print yaml.dump(options) #print options.keys() if not options.get('filename'): options['filename'] = filename.clean(options['title']) log.debug("Filename: %s", options['filename']) else: options = yaml.load("dummy: 0") log.debug("options.yaml not found.") arguments = ArgumentParser().parse_args() if arguments.filename: options['filename'] = arguments.filename
def run(): """Run this action.""" log.debug("run()") print "Book title?" title = raw_input("> ") print "Author(s)?" author = raw_input("> ") print "Path to new book project files?\n[default: current directory]" path = raw_input("> ") or "." today = re.sub("^0", "", date.today().strftime("%d %b %Y")) uuid = mdepub.new_id() filename = mdepub.options.get("filename") or clean(title) log.debug("Creating project in \"%s\".", path) if not exists(path): os.makedirs(path) os.chdir(path) if exists("options.yaml"): log.fatal("An mdepub project file already exists in this path.") sys.exit(1) css_content = template.get_file_content("book.css") with open("{}.css".format(filename), 'w') as f: f.write(css_content) txt = template.get_file_content("book.md") with open("{}.md".format(filename), 'w') as f: f.write(txt.format(Title=title, Author=author)) txt = template.get_file_content("options.yaml") with open("options.yaml", 'w') as f: f.write(txt.format(Title=title, Author=author, Date=today, uuid=uuid))
def init(): """Initialize mdepub package and populate options variable.""" global options global project_path global arguments global log global options_loaded logging.basicConfig(level=logging.WARN) log = logging.getLogger('mdepub') project_path = os.getcwd() log.debug("Working path: %s", project_path) options_file = os.path.join(project_path, "options.yaml") options_loaded = False if os.path.exists(options_file): options_loaded = True log.debug("Loading options.yaml") options = yaml.load(open("options.yaml")) if VERSION.split(".") < (options.get("require mdepub version") or "").split("."): log.fatal("This project requires at least version %s of mdepub.", options["require mdepub version"]) sys.exit(1) #print yaml.dump(options) #print options.keys() if not options.get('filename'): options['filename'] = filename.clean(options['title']) log.debug("Filename: %s", options['filename']) else: options = yaml.load("dummy: 0") log.debug("options.yaml not found.") arguments = ArgumentParser().parse_args() if arguments.filename: options['filename'] = arguments.filename