def create_parser(): parser = argparse.ArgumentParser(formatter_class=argparse.RawDescriptionHelpFormatter, description=banner()) parser.add_argument("--bake", action="store_true", help="Compile templates and SASS (yum!)") parser.add_argument("--clean", action="store_true", help="Clean up the mess (mom would be proud!)") parser.add_argument("--controls", action="store_true", help="Generate slide control files (gonna have something already baked)") parser.add_argument("--dev", action="store_true", help="Use the quick-bake test kitchen environment (no screenshots, no packaging). This is a shortcut to using --nuke --bake --watch --veev2rel") parser.add_argument("--go", action="store_true", help="Use a quick-bake recipe -> nuke, bake, screenshots, package, clean") parser.add_argument("--init", action="store_true", help="Initialize a new VELVEEVA project") parser.add_argument("--inline", action="store_true", help="Inline globals") parser.add_argument("--integrate", action="store_true", help="Integrate relative assets and hyperlinks (useful for packaging from static development") parser.add_argument("--nuke", action="store_true", help="Nuke old builds and temp files") parser.add_argument("--scaffold", action="store_true", help="Set up build and temp folders") parser.add_argument("--package", action="store_true", help="Wrap it up [Selected when no options are given]") parser.add_argument("--publish", action="store_true", help="Ship it off to market") parser.add_argument("--relink", action="store_true", help="Make some href saussage (replace relative links with global and convert to veeva: protocol)") parser.add_argument("--rel2veev", action="store_true", help="Convert relative links to veeva: protocol") parser.add_argument("--sass", action="store_true", help="Compile Sass") parser.add_argument("--screenshots", action="store_true", help="Include Screenshots") parser.add_argument("--ssonly", action="store_true", help="As-is screenshots (no dependencies)") parser.add_argument("--templates", action="store_true", help="Compile Templates") parser.add_argument("--veev2rel", action="store_true", help="Convert veeva: hrefs to relative links") parser.add_argument("--verbose", action="store_true", help="Chatty Cathy") parser.add_argument("--notparallel", action="store_true", help="Only run things one after another") parser.add_argument("--watch", action="store_true", help="Watch for changes and re-build on change") parser.add_argument("--packageonly", action="store_true", help="Zip as-is") return parser
def main(): sys.stdout = codecs.getwriter('utf-8')(sys.stdout.detach()) if len(sys.argv) < 2: print(banner(subtitle='An easier way to manage, maintain,\n and build Veeva iRep presentations')) usage() return 1 else: return dispatch(sys.argv[1], sys.argv[2:])
def exec_util(args): if not args: print(banner()) util_help() return 1 util = args[0] util_args = args[1:] utils = parseUtils() if util is None: print(banner()) util_help() return 1 elif util in utils: script = os.path.join(UTILS_DIR,util+".py") return exec_cmd(script, util_args) else: print(util + ' is not a recognized Velveeva util command') return 1
def run_build(build_plan, env): STEPS = len(build_plan) if env['PREFLIGHT_HOOK'] is not None: for out in execute([ENV['PREFLIGHT_HOOK']]): print(out) print(banner()) print("👉 %s 👈\n" % paint.bold.yellow(ENV['PROJECT_NAME'])) try: with concurrent.futures.ProcessPoolExecutor() as executor: # with ProgressBar(max_value=STEPS, # widgets=[Bar(marker="🍕"),Percentage()], # redirect_stdout=True) as progress, concurrent.futures.ProcessPoolExecutor() as executor: # env['progress'] = progress i = 0 for step in build_plan: if len(step) == 0: i = i + 1 elif len(step) == 1: func = step[0][0] func.announce() func(env, i) i = i + 1 else: futures = [] for func in step: action = func[0] action.announce() futures.append(executor.submit(action, env, i)) synchronize_and_wait = [f.result() for f in futures] i = i + 1 # progress.update(STEPS) # finish up if env['POSTFLIGHT_HOOK'] is not None: for out in execute([ENV['POSTFLIGHT_HOOK']]): print(out) except Exception as e: print(paint.bold.red("\n💩 there was an error:")) print(e) sys.exit(1) print(paint.bold.green("\n🍕 Yum!"))
def doScript(): VERBOSE = False parser = argparse.ArgumentParser(formatter_class=argparse.RawDescriptionHelpFormatter, description=banner()) parser.add_argument("--bake", action="store_true", help="Compile templates and SASS (yum!)") parser.add_argument("--clean", action="store_true", help="Clean up the mess (mom would be proud!) [Selected when no options are given]") parser.add_argument("--controls", action="store_true", help="Generate slide control files (gonna have something already baked)") parser.add_argument("--controlsonly", action="store_true", help="Only generate control files") parser.add_argument("--dev", action="store_true", help="Use the quick-bake test kitchen environment (no screenshots, no packaging). This is a shortcut to using go --clean --watch --veev2rel") parser.add_argument("--init", action="store_true", help="Initialize a new VELVEEVA project") parser.add_argument("--nuke", action="store_true", help="Nuke old builds and temp files") parser.add_argument("--nobake", action="store_true", help="Don't bake it...") parser.add_argument("--package", action="store_true", help="Wrap it up [Selected when no options are given]") parser.add_argument("--packageonly", action="store_true", help="Just wrap it up (you gotta already have something baked)") parser.add_argument("--publish", action="store_true", help="Ship it off to market") parser.add_argument("--publishonly", action="store_true", help="(Only) ship it off to market (you gotta already have something baked, and control files generated)") parser.add_argument("--relink", action="store_true", help="Make some href saussage (replace relative links with global and convert to veeva: protocol)") parser.add_argument("--screenshots", action="store_true", help="Include Screenshots [Selected when no options are given]") parser.add_argument("--veev2rel", action="store_true", help="Convert veeva: hrefs to relative links") parser.add_argument("--verbose", action="store_true", help="Chatty Cathy") parser.add_argument("--watch", action="store_true", help="Watch for changes and re-bake on change") if len(sys.argv) == 1: parser.print_help() sys.exit(0) args = parser.parse_args() config = parse_config() SOURCE_DIR = config['MAIN']['source_dir'] DEST_DIR = config['MAIN']['output_dir'] GLOBALS_DIR = config['MAIN']['globals_dir'] PARTIALS_DIR = config['MAIN']['partials_dir'] TEMPLATES_DIR = config['MAIN']['templates_dir'] ZIPS_DIR = config['MAIN']['zips_dir'] ### CTL File Info ### CTLS_DIR = config['MAIN']['ctls_dir'] VEEVA_USERNAME = config['VEEVA']['username'] VEEVA_PASSWORD = config['VEEVA']['password'] VEEVA_SERVER = config['VEEVA']['server'] VEEVA_EMAIL = config['VEEVA'].get('email', None) ROOT_DIR = os.getcwd() CONFIG_FILE_NAME = "VELVEEVA-config.json" PROJECT_NAME = config['MAIN']['name'] VELVEEVA_DIR = os.path.dirname(os.path.abspath(inspect.stack()[0][1])) #💩🍕 print(banner()) print("👉 %s 👈\n" % paint.bold.yellow(PROJECT_NAME)) try: with ProgressBar(max_value=11, widgets=[Bar(marker="🍕"),Percentage()], redirect_stdout=True) as progress: #0. nuke print("🔥 %s" % paint.gray("Nuking old builds...")) progress.update(1) nuke(ROOT_DIR, config) #1. scaffold needed folders 🗄 print("🗄 %s" % paint.gray("Creating directories...")) progress.update(2) scaffold(ROOT_DIR, config) #2. inline local (non-html) files, and create build folders 💉 print("💉 %s " % paint.gray("Inlining partials and globals...")) progress.update(3) copy_locals(ROOT_DIR, SOURCE_DIR, DEST_DIR) #3. inline partials and globals progress.update(4) cmd = os.path.join(VELVEEVA_DIR, "lib", "inject.py") for out in execute(["python3", cmd, ROOT_DIR, GLOBALS_DIR, DEST_DIR]): print(out) #4. render sass 💅 print("💅 %s " % paint.gray("Compiling SASS...")) progress.update(5) cmd = os.path.join(VELVEEVA_DIR, "lib", "compile_sass.py") for out in execute(["python3", cmd, os.path.join(ROOT_DIR,DEST_DIR)]): print(out) #5. render templates 📝 print("📝 %s " % paint.gray("Rendering templates...")) progress.update(6) cmd = os.path.join(VELVEEVA_DIR, "lib", "render_templates.py") for out in execute(["python3", cmd, os.path.join(ROOT_DIR, SOURCE_DIR), os.path.join(ROOT_DIR,DEST_DIR), os.path.join(ROOT_DIR, TEMPLATES_DIR), os.path.join(ROOT_DIR, PARTIALS_DIR)]): print(out) #6. take screenshots 📸 print("📸 %s " % paint.gray("Taking screenshots...")) progress.update(7) cmd = os.path.join(VELVEEVA_DIR, "lib", "screenshot.py") src = os.path.abspath(os.path.join(ROOT_DIR,DEST_DIR)) cfg = os.path.abspath(os.path.join(ROOT_DIR,CONFIG_FILE_NAME)) for out in execute(["python3", cmd, src, cfg]): print(out) #7. package slides 📬 progress.update(8) print("📬 %s " % paint.gray("Packaging slides...")) cmd = os.path.join(VELVEEVA_DIR, "lib", "package_slides.py") for out in execute(["python3", cmd, os.path.join(ROOT_DIR,DEST_DIR), os.path.join(ROOT_DIR,DEST_DIR,ZIPS_DIR)]): print(out) #8. generate control files ⚒ print("⚒ %s " % paint.gray("Generating .ctl files...")) progress.update(9) cmd = os.path.join(VELVEEVA_DIR, "lib", "genctls.py") flags = ["python3" , cmd , "--root", ROOT_DIR , "--src", os.path.abspath(os.path.join(ROOT_DIR,DEST_DIR,ZIPS_DIR)) , "--out", os.path.abspath(os.path.join(ROOT_DIR,DEST_DIR,CTLS_DIR)) , "--u", VEEVA_USERNAME , "--pwd", VEEVA_PASSWORD] if VEEVA_EMAIL is not None: flags = flags + ["--email", VEEVA_EMAIL] for out in execute(flags): print(out) #9. ftp 🚀 print("🚀 %s " % paint.gray("Publishing to Veeva FTP server...")) progress.update(10) cmd = os.path.join(VELVEEVA_DIR, "lib", "publish.py") for out in execute(["python3", cmd , "--zip", os.path.abspath(os.path.join(ROOT_DIR,DEST_DIR,ZIPS_DIR)) , "--ctl", os.path.abspath(os.path.join(ROOT_DIR,DEST_DIR,CTLS_DIR)) , "--host", VEEVA_SERVER , "--u", VEEVA_USERNAME , "--pwd", VEEVA_PASSWORD]): print(out) #done! progress.update(11) # relinking # don't use subprocess -> import directly # concurrent build # not as shitty exception handling # file watcher architecture # all utils should use python argparse and --src SRC (e.g.) flags not strictly positional arguments # make flags required (so fails if not present) # unified banner printer except Exception as e: print(paint.bold.red("\n💩 there was an error:")) print(e) sys.exit(1) print(paint.bold.green("\n🍕 Yum!"))
def doScript(): VERBOSE = False parser = argparse.ArgumentParser( formatter_class=argparse.RawDescriptionHelpFormatter, description=banner()) parser.add_argument("--bake", action="store_true", help="Compile templates and SASS (yum!)") parser.add_argument( "--clean", action="store_true", help= "Clean up the mess (mom would be proud!) [Selected when no options are given]" ) parser.add_argument( "--controls", action="store_true", help="Generate slide control files (gonna have something already baked)" ) parser.add_argument("--controlsonly", action="store_true", help="Only generate control files") parser.add_argument( "--dev", action="store_true", help= "Use the quick-bake test kitchen environment (no screenshots, no packaging). This is a shortcut to using go --clean --watch --veev2rel" ) parser.add_argument("--init", action="store_true", help="Initialize a new VELVEEVA project") parser.add_argument("--nuke", action="store_true", help="Nuke old builds and temp files") parser.add_argument("--nobake", action="store_true", help="Don't bake it...") parser.add_argument("--package", action="store_true", help="Wrap it up [Selected when no options are given]") parser.add_argument( "--packageonly", action="store_true", help="Just wrap it up (you gotta already have something baked)") parser.add_argument("--publish", action="store_true", help="Ship it off to market") parser.add_argument( "--publishonly", action="store_true", help= "(Only) ship it off to market (you gotta already have something baked, and control files generated)" ) parser.add_argument( "--relink", action="store_true", help= "Make some href saussage (replace relative links with global and convert to veeva: protocol)" ) parser.add_argument( "--screenshots", action="store_true", help="Include Screenshots [Selected when no options are given]") parser.add_argument("--veev2rel", action="store_true", help="Convert veeva: hrefs to relative links") parser.add_argument("--verbose", action="store_true", help="Chatty Cathy") parser.add_argument("--watch", action="store_true", help="Watch for changes and re-bake on change") if len(sys.argv) == 1: parser.print_help() sys.exit(0) args = parser.parse_args() config = parse_config() SOURCE_DIR = config['MAIN']['source_dir'] DEST_DIR = config['MAIN']['output_dir'] GLOBALS_DIR = config['MAIN']['globals_dir'] PARTIALS_DIR = config['MAIN']['partials_dir'] TEMPLATES_DIR = config['MAIN']['templates_dir'] ZIPS_DIR = config['MAIN']['zips_dir'] ### CTL File Info ### CTLS_DIR = config['MAIN']['ctls_dir'] VEEVA_USERNAME = config['VEEVA']['username'] VEEVA_PASSWORD = config['VEEVA']['password'] VEEVA_SERVER = config['VEEVA']['server'] VEEVA_EMAIL = config['VEEVA'].get('email', None) ROOT_DIR = os.getcwd() CONFIG_FILE_NAME = "VELVEEVA-config.json" PROJECT_NAME = config['MAIN']['name'] VELVEEVA_DIR = os.path.dirname(os.path.abspath(inspect.stack()[0][1])) #💩🍕 print(banner()) print("👉 %s 👈\n" % paint.bold.yellow(PROJECT_NAME)) try: with ProgressBar(max_value=11, widgets=[Bar(marker="🍕"), Percentage()], redirect_stdout=True) as progress: #0. nuke print("🔥 %s" % paint.gray("Nuking old builds...")) progress.update(1) nuke(ROOT_DIR, config) #1. scaffold needed folders 🗄 print("🗄 %s" % paint.gray("Creating directories...")) progress.update(2) scaffold(ROOT_DIR, config) #2. inline local (non-html) files, and create build folders 💉 print("💉 %s " % paint.gray("Inlining partials and globals...")) progress.update(3) copy_locals(ROOT_DIR, SOURCE_DIR, DEST_DIR) #3. inline partials and globals progress.update(4) cmd = os.path.join(VELVEEVA_DIR, "lib", "inject.py") for out in execute( ["python3", cmd, ROOT_DIR, GLOBALS_DIR, DEST_DIR]): print(out) #4. render sass 💅 print("💅 %s " % paint.gray("Compiling SASS...")) progress.update(5) cmd = os.path.join(VELVEEVA_DIR, "lib", "compile_sass.py") for out in execute( ["python3", cmd, os.path.join(ROOT_DIR, DEST_DIR)]): print(out) #5. render templates 📝 print("📝 %s " % paint.gray("Rendering templates...")) progress.update(6) cmd = os.path.join(VELVEEVA_DIR, "lib", "render_templates.py") for out in execute([ "python3", cmd, os.path.join(ROOT_DIR, SOURCE_DIR), os.path.join(ROOT_DIR, DEST_DIR), os.path.join(ROOT_DIR, TEMPLATES_DIR), os.path.join(ROOT_DIR, PARTIALS_DIR) ]): print(out) #6. take screenshots 📸 print("📸 %s " % paint.gray("Taking screenshots...")) progress.update(7) cmd = os.path.join(VELVEEVA_DIR, "lib", "screenshot.py") src = os.path.abspath(os.path.join(ROOT_DIR, DEST_DIR)) cfg = os.path.abspath(os.path.join(ROOT_DIR, CONFIG_FILE_NAME)) for out in execute(["python3", cmd, src, cfg]): print(out) #7. package slides 📬 progress.update(8) print("📬 %s " % paint.gray("Packaging slides...")) cmd = os.path.join(VELVEEVA_DIR, "lib", "package_slides.py") for out in execute([ "python3", cmd, os.path.join(ROOT_DIR, DEST_DIR), os.path.join(ROOT_DIR, DEST_DIR, ZIPS_DIR) ]): print(out) #8. generate control files ⚒ print("⚒ %s " % paint.gray("Generating .ctl files...")) progress.update(9) cmd = os.path.join(VELVEEVA_DIR, "lib", "genctls.py") flags = [ "python3", cmd, "--root", ROOT_DIR, "--src", os.path.abspath(os.path.join(ROOT_DIR, DEST_DIR, ZIPS_DIR)), "--out", os.path.abspath(os.path.join(ROOT_DIR, DEST_DIR, CTLS_DIR)), "--u", VEEVA_USERNAME, "--pwd", VEEVA_PASSWORD ] if VEEVA_EMAIL is not None: flags = flags + ["--email", VEEVA_EMAIL] for out in execute(flags): print(out) #9. ftp 🚀 print("🚀 %s " % paint.gray("Publishing to Veeva FTP server...")) progress.update(10) cmd = os.path.join(VELVEEVA_DIR, "lib", "publish.py") for out in execute([ "python3", cmd, "--zip", os.path.abspath(os.path.join(ROOT_DIR, DEST_DIR, ZIPS_DIR)), "--ctl", os.path.abspath(os.path.join(ROOT_DIR, DEST_DIR, CTLS_DIR)), "--host", VEEVA_SERVER, "--u", VEEVA_USERNAME, "--pwd", VEEVA_PASSWORD ]): print(out) #done! progress.update(11) # relinking # don't use subprocess -> import directly # concurrent build # not as shitty exception handling # file watcher architecture # all utils should use python argparse and --src SRC (e.g.) flags not strictly positional arguments # make flags required (so fails if not present) # unified banner printer except Exception as e: print(paint.bold.red("\n💩 there was an error:")) print(e) sys.exit(1) print(paint.bold.green("\n🍕 Yum!"))
def help(args): print(banner()) usage()
def create_parser(): parser = argparse.ArgumentParser( formatter_class=argparse.RawDescriptionHelpFormatter, description=banner()) parser.add_argument("--bake", action="store_true", help="Compile templates and SASS (yum!)") parser.add_argument("--clean", action="store_true", help="Clean up the mess (mom would be proud!)") parser.add_argument( "--controls", action="store_true", help="Generate slide control files (gonna have something already baked)" ) parser.add_argument("--controlsonly", action="store_true", help="Generate slide control files (no other steps)") parser.add_argument( "--dev", action="store_true", help= "Use the quick-bake test kitchen environment (no screenshots, no packaging). This is a shortcut to using --nuke --bake --watch --veev2rel" ) parser.add_argument( "--go", action="store_true", help= "Use a quick-bake recipe -> nuke, bake, screenshots, package, clean") parser.add_argument("--init", action="store_true", help="Initialize a new VELVEEVA project") parser.add_argument("--inline", action="store_true", help="Inline globals") parser.add_argument( "--integrate", action="store_true", help= "Integrate relative assets and hyperlinks (useful for packaging from static development" ) parser.add_argument("--nuke", action="store_true", help="Nuke old builds and temp files") parser.add_argument("--scaffold", action="store_true", help="Set up build and temp folders") parser.add_argument("--package", action="store_true", help="Wrap it up [Selected when no options are given]") parser.add_argument("--publish", action="store_true", help="Ship it off to market") parser.add_argument( "--relink", action="store_true", help= "Make some href saussage (replace relative links with global and convert to veeva: protocol)" ) parser.add_argument("--rel2veev", action="store_true", help="Convert relative links to veeva: protocol") parser.add_argument("--sass", action="store_true", help="Compile Sass") parser.add_argument("--screenshots", action="store_true", help="Include Screenshots") parser.add_argument("--ssonly", action="store_true", help="As-is screenshots (no dependencies)") parser.add_argument("--templates", action="store_true", help="Compile Templates") parser.add_argument("--veev2rel", action="store_true", help="Convert veeva: hrefs to relative links") parser.add_argument("--verbose", action="store_true", help="Chatty Cathy") parser.add_argument("--notparallel", action="store_true", help="Only run things one after another") parser.add_argument("--watch", action="store_true", help="Watch for changes and re-build on change") parser.add_argument("--packageonly", action="store_true", help="Zip as-is") parser.add_argument("--share-assets", action="store_true", help="Use Veeva's shared asset feature for globals") parser.add_argument("--globals", action="store_true", help="Inline globals") parser.add_argument("--locals", action="store_true", help="Inline locals") parser.add_argument("--render-slides", action="store_true", help="Render/Copy slides into dest") parser.add_argument( "--publishonly", action="store_true", help="FTP upload slide and control files (no other steps)") return parser