Beispiel #1
0
def share_assets(globals_dir, composer, src):
	actions = [
		action(
			"stylesheets",
			lambda soup: soup.find_all("link", {"rel": "stylesheet"}),
			attribute_transform("href", fix_shared_asset_path(globals_dir)),
			composer),
		action(
			"all tags with src attributes",
			lambda soup: soup.find_all(attrs={"src": True}),
			attribute_transform("src", fix_shared_asset_path(globals_dir)), 
			composer),
		# action(
		# 	"scripts",
		# 	lambda soup: soup.find_all("script", src=True),
		# 	attribute_transform("src", fix_shared_asset_path(globals_dir)),
		# 	composer),
		# action(
		# 	"images",
		# 	lambda soup: soup.find_all("img"),
		# 	attribute_transform("src", fix_shared_asset_path(globals_dir)),
		# 	composer),
		# action(
		# 	"iframes",
		# 	lambda soup: soup.find_all("iframe"),
		# 	attribute_transform("src", fix_shared_asset_path(globals_dir)),
		# 	composer),
		# action(
		# 	"videos",
		# 	lambda soup: soup.find_all("video", src=True),
		# 	attribute_transform("src", fix_shared_asset_path(globals_dir)),
		# 	composer),
		action(
			"inline background images",
			lambda soup: soup.find_all(style=True),
			attribute_transform("style", fix_shared_asset_path(globals_dir)),
			composer),
		action(
			"hyperlink_paths",
			lambda soup: soup.find_all("a", href=True),
			attribute_transform("href", fix_shared_asset_path(globals_dir)),
			composer),
		action(
			"hyperlink_protocols",
			lambda soup: soup.find_all("a", href=True),
			attribute_transform("href", fix_hyperlink_protocol),
			veeva_composer("veeva:")),
		action(
			"utf",
			lambda soup: soup.find_all("meta", charset=True),
			add_meta(charset="utf-8"),
			veeva_composer("veeva:"))
	]
	return run_actions(actions, src)
Beispiel #2
0
def share_assets(globals_dir, composer, src):
	actions = [
		action(
			"stylesheets",
			lambda soup: soup.find_all("link", {"rel": "stylesheet"}),
			attribute_transform("href", fix_shared_asset_path(globals_dir)),
			composer),
		action(
			"all tags with src attributes",
			lambda soup: soup.find_all(attrs={"src": True}),
			attribute_transform("src", fix_shared_asset_path(globals_dir)), 
			composer),
		# action(
		# 	"scripts",
		# 	lambda soup: soup.find_all("script", src=True),
		# 	attribute_transform("src", fix_shared_asset_path(globals_dir)),
		# 	composer),
		# action(
		# 	"images",
		# 	lambda soup: soup.find_all("img"),
		# 	attribute_transform("src", fix_shared_asset_path(globals_dir)),
		# 	composer),
		# action(
		# 	"iframes",
		# 	lambda soup: soup.find_all("iframe"),
		# 	attribute_transform("src", fix_shared_asset_path(globals_dir)),
		# 	composer),
		# action(
		# 	"videos",
		# 	lambda soup: soup.find_all("video", src=True),
		# 	attribute_transform("src", fix_shared_asset_path(globals_dir)),
		# 	composer),
		action(
			"inline background images",
			lambda soup: soup.find_all(style=True),
			attribute_transform("style", fix_shared_asset_path(globals_dir)),
			composer),
		action(
			"hyperlink_paths",
			lambda soup: soup.find_all("a", href=True),
			attribute_transform("href", fix_shared_asset_path(globals_dir)),
			composer),
		action(
			"hyperlink_protocols",
			lambda soup: soup.find_all("a", href=True),
			attribute_transform("href", fix_hyperlink_protocol),
			veeva_composer("veeva:")),
		action(
			"utf",
			lambda soup: soup.find_all("meta", charset=True),
			add_meta(charset="utf-8"),
			veeva_composer("veeva:"))
	]
	return run_actions(actions, src)
Beispiel #3
0
def mv_refs(old_slide_name, new_slide_name, src):
	actions = [
		action(
			"old rel to old rel",
			lambda soup: soup.find_all("a", href=True),
			attribute_transform("href", mv_rel(old_slide_name, new_slide_name)),
			veeva_composer("veeva:")),
		action(
			"old veeva to new veeva",
			lambda soup: soup.find_all("a", href=True),
			attribute_transform("href", mv_veev(old_slide_name, new_slide_name)),
			veeva_composer("veeva:"))
	]

	return run_actions(actions, src)
Beispiel #4
0
def mv_refs(old_slide_name, new_slide_name, src):
	actions = [
		action(
			"old rel to old rel",
			lambda soup: soup.find_all("a", href=True),
			attribute_transform("href", mv_rel(old_slide_name, new_slide_name)),
			veeva_composer("veeva:")),
		action(
			"old veeva to new veeva",
			lambda soup: soup.find_all("a", href=True),
			attribute_transform("href", mv_veev(old_slide_name, new_slide_name)),
			veeva_composer("veeva:"))
	]

	return run_actions(actions, src)
Beispiel #5
0
def integrate_all(composer, src):
	actions = [
		action(
			"stylesheets",
			lambda soup: soup.find_all("link", {"rel": "stylesheet"}),
			attribute_transform("href", fix_relative_path),
			composer),
		# action(
		# 	"scripts",
		# 	lambda soup: soup.find_all("script", src=True),
		# 	attribute_transform("src", fix_relative_path),
		# 	composer),
		# action(
		# 	"images",
		# 	lambda soup: soup.find_all("img"),
		# 	attribute_transform("src", fix_relative_path),
		# 	composer),
		# action(
		# 	"iframes",
		# 	lambda soup: soup.find_all("iframe"),
		# 	attribute_transform("src", fix_relative_path),
		# 	composer),
		action(
			"all tags with src attributes", # stylesheets, scripts, images, iframes, ...
			lambda soup: soup.find_all(attrs={"src": True}),
			attribute_transform("src", fix_relative_path),
			composer),
		action(
			"hyperlink_paths",
			lambda soup: soup.find_all("a", href=True),
			attribute_transform("href", fix_relative_path),
			composer),
		action(
			"hyperlink_protocols",
			lambda soup: soup.find_all("a", href=True),
			attribute_transform("href", fix_hyperlink_protocol),
			veeva_composer("veeva:")),
		action(
			"utf",
			lambda soup: soup.find_all("meta", charset=True),
			add_meta(charset="utf-8"),
			veeva_composer("veeva:"))
	]

	return run_actions(actions, src)
Beispiel #6
0
def integrate_all(composer, src):
	actions = [
		action(
			"stylesheets",
			lambda soup: soup.find_all("link", rel="stylesheet"),
			attribute_transform("href", fix_relative_path),
			composer),
		# action(
		# 	"scripts",
		# 	lambda soup: soup.find_all("script", src=True),
		# 	attribute_transform("src", fix_relative_path),
		# 	composer),
		# action(
		# 	"images",
		# 	lambda soup: soup.find_all("img"),
		# 	attribute_transform("src", fix_relative_path),
		# 	composer),
		# action(
		# 	"iframes",
		# 	lambda soup: soup.find_all("iframe"),
		# 	attribute_transform("src", fix_relative_path),
		# 	composer),
		action(
			"all tags with src attributes", # stylesheets, scripts, images, iframes, ...
			lambda soup: soup.find_all(attrs={"src": True}),
			attribute_transform("src", fix_relative_path),
			composer),
		action(
			"hyperlink_paths",
			lambda soup: soup.find_all("a", href=True),
			attribute_transform("href", fix_relative_path),
			composer),
		action(
			"hyperlink_protocols",
			lambda soup: soup.find_all("a", href=True),
			attribute_transform("href", fix_hyperlink_protocol),
			veeva_composer("veeva:")),
		action(
			"utf",
			lambda soup: soup.find_all("meta", charset=True),
			add_meta(charset="utf-8"),
			veeva_composer("veeva:"))
	]

	return run_actions(actions, src)
Beispiel #7
0
def runScript():
	## TODO: make work with --root flag
	def does_file_exist(fname):
		exists = os.path.exists(fname)
		if not exists: print("%s does not exist!" % fname)
		return exists

	def all_exists(folders):
		return reduce(lambda acc, arg: acc and does_file_exist(arg), folders, True)


	parser = argparse.ArgumentParser(formatter_class=argparse.RawDescriptionHelpFormatter,
		description = banner(subtitle="Re-Linker"))

	parser.add_argument("--root", nargs=1, help="Project root folder", required=False)
	parser.add_argument("--verbose", action="store_true", required=False, help="Chatty Cathy")

	group = parser.add_mutually_exclusive_group()
	group.add_argument("--mv", nargs=3, metavar=("old_name", "new_name", "source"), help="recursively rename references to an old slide name with a new slide name")
	group.add_argument("--veev2rel", nargs="+", metavar="source", help="recursively replace veeva links with relative links")
	group.add_argument("--rel2veev", nargs="+", metavar="source", help="recursively replace relative links with veeva link")
	group.add_argument("--integrate-all", nargs="+", metavar="source", help="recursively resolve relative links and replace hrefs with veeva")
	group.add_argument("--share-assets", nargs="+", metavar="source", help="recursively replace links to global assets with veeva ../shared/ prefix")

	if len(sys.argv) == 1:
		parser.print_help()
		return 2

	args = parser.parse_args()
	verbose = args.verbose

	composer = veeva_composer("veeva:")

	if args.mv is not None:
		old, new, folder = args.mv
		if not all_exists([folder]): 
			return 128
		else:
			return parse_folder(folder, actions=[mv_refs(composer, old, new)], verbose=verbose)

	if args.veev2rel is not None:
		folders = args.veev2rel
		if not all_exists(folders):
			return 128
		else:
			for folder in folders:
				parse_folder(folder, actions=[veev2rel(composer)], verbose=verbose)
			return

	if args.rel2veev is not None:
		folders = args.rel2veev
		if not all_exists(folders):
			return 128
		else:
			for folder in folders:
				parse_folder(folder, actions=[rel2veev(composer)], verbose=verbose)
			return

	if args.integrate_all is not None:
		folders = args.integrate_all
		if not all_exists(folders):
			return 128
		else:
			for folder in folders:
				parse_folder(folder, actions=[integrate_all(composer)], verbose=verbose)
			return

	if args.share_assets is not None:
		if args.root:
			veeva_root = args.root[0]
		else:
			veeva_root = os.getcwd()

		config_file = os.path.join(veeva_root, CONFIG_FILENAME)

		if not os.path.exists(config_file):
			print("Relink.py: could not load config file", file=sys.stderr)
			return 128
		else:
			with open(config_file) as f:
				config = json.load(f)

		global_assets = config['MAIN']['globals_dir']

		folders = args.share_assets
		if not all_exists(folders):
			return 128
		else:
			for folder in folders:
				parse_folder(folder, actions=[share_assets(global_assets,composer)], verbose=verbose)
Beispiel #8
0
def runScript():
	## TODO: make work with --root flag
	def does_file_exist(fname):
		exists = os.path.exists(fname)
		if not exists: print("%s does not exist!" % fname)
		return exists

	def all_exists(folders):
		return reduce(lambda acc, arg: acc and does_file_exist(arg), folders, True)


	parser = argparse.ArgumentParser(formatter_class=argparse.RawDescriptionHelpFormatter,
		description = banner(subtitle="Re-Linker"))

	parser.add_argument("--root", nargs=1, help="Project root folder", required=False)
	parser.add_argument("--verbose", action="store_true", required=False, help="Chatty Cathy")

	group = parser.add_mutually_exclusive_group()
	group.add_argument("--mv", nargs=3, metavar=("old_name", "new_name", "source"), help="recursively rename references to an old slide name with a new slide name")
	group.add_argument("--veev2rel", nargs="+", metavar="source", help="recursively replace veeva links with relative links")
	group.add_argument("--rel2veev", nargs="+", metavar="source", help="recursively replace relative links with veeva link")
	group.add_argument("--integrate-all", nargs="+", metavar="source", help="recursively resolve relative links and replace hrefs with veeva")

	if len(sys.argv) == 1:
		parser.print_help()
		return 2

	args = parser.parse_args()
	verbose = args.verbose

	composer = veeva_composer("veeva:")

	if args.mv is not None:
		old, new, folder = args.mv
		if not all_exists([folder]): 
			return 128
		else:
			return parse_folder(folder, actions=[mv_refs(composer, old, new)], verbose=verbose)

	if args.veev2rel is not None:
		folders = args.veev2rel
		if not all_exists(folders):
			return 128
		else:
			for folder in folders:
				parse_folder(folder, actions=[veev2rel(composer)], verbose=verbose)
			return

	if args.rel2veev is not None:
		folders = args.rel2veev
		if not all_exists(folders):
			return 128
		else:
			for folder in folders:
				parse_folder(folder, actions=[rel2veev(composer)], verbose=verbose)
			return

	if args.integrate_all is not None:
		folders = args.integrate_all
		if not all_exists(folders):
			return 128
		else:
			for folder in folders:
				parse_folder(folder, actions=[integrate_all(composer)], verbose=verbose)
			return
Beispiel #9
0
def runScript():
	## TODO: make work with --root flag
	def does_file_exist(fname):
		exists = os.path.exists(fname)
		if not exists: print("%s does not exist!" % fname)
		return exists

	def all_exists(folders):
		return reduce(lambda acc, arg: acc and does_file_exist(arg), folders, True)


	parser = argparse.ArgumentParser(formatter_class=argparse.RawDescriptionHelpFormatter,
		description = banner(subtitle="Re-Linker"))

	parser.add_argument("--root", nargs=1, help="Project root folder", required=False)
	parser.add_argument("--verbose", action="store_true", required=False, help="Chatty Cathy")

	group = parser.add_mutually_exclusive_group()
	group.add_argument("--mv", nargs=3, metavar=("old_name", "new_name", "source"), help="recursively rename references to an old slide name with a new slide name")
	group.add_argument("--veev2rel", nargs="+", metavar="source", help="recursively replace veeva links with relative links")
	group.add_argument("--rel2veev", nargs="+", metavar="source", help="recursively replace relative links with veeva link")
	group.add_argument("--integrate-all", nargs="+", metavar="source", help="recursively resolve relative links and replace hrefs with veeva")
	group.add_argument("--share-assets", nargs="+", metavar="source", help="recursively replace links to global assets with veeva ../shared/ prefix")

	if len(sys.argv) == 1:
		parser.print_help()
		return 2

	args = parser.parse_args()
	verbose = args.verbose

	composer = veeva_composer("veeva:")

	if args.mv is not None:
		old, new, folder = args.mv
		if not all_exists([folder]): 
			return 128
		else:
			return parse_folder(folder, actions=[mv_refs(composer, old, new)], verbose=verbose)

	if args.veev2rel is not None:
		folders = args.veev2rel
		if not all_exists(folders):
			return 128
		else:
			for folder in folders:
				parse_folder(folder, actions=[veev2rel(composer)], verbose=verbose)
			return

	if args.rel2veev is not None:
		folders = args.rel2veev
		if not all_exists(folders):
			return 128
		else:
			for folder in folders:
				parse_folder(folder, actions=[rel2veev(composer)], verbose=verbose)
			return

	if args.integrate_all is not None:
		folders = args.integrate_all
		if not all_exists(folders):
			return 128
		else:
			for folder in folders:
				parse_folder(folder, actions=[integrate_all(composer)], verbose=verbose)
			return

	if args.share_assets is not None:
		if args.root:
			veeva_root = args.root[0]
		else:
			veeva_root = os.getcwd()

		config_file = os.path.join(veeva_root, CONFIG_FILENAME)

		if not os.path.exists(config_file):
			print("Relink.py: could not load config file", file=sys.stderr)
			return 128
		else:
			with open(config_file) as f:
				config = json.load(f)

		global_assets = config['MAIN']['globals_dir']

		folders = args.share_assets
		if not all_exists(folders):
			return 128
		else:
			for folder in folders:
				parse_folder(folder, actions=[share_assets(global_assets,composer)], verbose=verbose)