Exemplo n.º 1
0
    def load(self,):
        self.html = Cache.load(Board=self.board, Thread=self.thread)

        if self.html:
            self.html = self.html.decode("utf8")
Exemplo n.º 2
0
  def load(self,):
    self.cache = Cache.load("thread", self.board, self.thread)

    if not self.cache:
      self.cache = Cache.create("thread", self.board, self.thread)
Exemplo n.º 3
0
def main():
	commands = {}
	config = None
	ignore_list = []
	settings = AttributeStore()
	tools = {}
	asset_folders = []
	
	p = argparse.ArgumentParser()
	p.add_argument(
		"-c",
		"--config", 
		dest="config_path", 
		metavar="CONFIG_FILE_PATH",
		help="Configuration file path to use when converting assets",
		required=True
	)

	p.add_argument(
		"-p",
		"--platform",
		dest="platform"
	)
	p.add_argument(
		"-y",
		"--clear-cache",
		dest="clear_cache",
		action="store_true"
	)
	p.add_argument(
		"-s",
		"--source_root",
		dest="source_root"
	)

	args = p.parse_args()
	config_cache = KeyValueCache()

	# load config
	config_data = load_config(args.config_path, config_cache)
	
	# the source_root can be specified on the command line;
	# this properly inserts it into the paths dict
	if "paths" in config_data:
		if "source_root" not in config_data["paths"]:
			if not args.source_root:
				raise Exception(
						"source_root is missing. This should be defined"
						" in a config file, or on the command line."
					)				
			else:
				# this path SHOULD be an absolute path
				config_data["paths"]["source_root"] = args.source_root

	config = AttributeStore(config_data)

	if not args.platform:
		args.platform = get_platform()
		logging.info("Target Platform is \"%s\"" % args.platform)


	# load tools
	tools_path = os.path.abspath(
		os.path.join(
		WorkingDirectory.current_directory(),
		os.path.dirname(__file__),
		"tools.conf"
		)
	)

	# get cache path
	cache = Cache(args.config_path, remove=args.clear_cache)
	cache.load()

	# conform all paths
	if getattr(config, "paths", None):
		base_path = os.path.dirname(os.path.abspath(args.config_path))

		# setup environment variables, path, etc.
		config.paths = setup_environment(base_path, config.paths, args.platform)
		
		setattr(settings, "paths", AttributeStore(config.paths))


	# parse all tools
	Tool.load_tools(
		tools,
		tools_path,
		config.tools
	)

	logging.info("Loaded %i tools." % len(tools.items()))

	# parse asset folders
	for asset_glob in config.assets:
		data = dict(
			{u"glob" : asset_glob}.items() +
			config.assets[asset_glob].items()
		)
		asset_folder = AssetFolderMask(**data)
		asset_folder.make_folders_absolute(
			settings.paths.source_root, 
			settings.paths.destination_root
		)
		asset_folders.append(asset_folder)
	logging.info("Loaded %i asset folders." % len(asset_folders))

	# check if we need to enter monitoring mode
	monitor_mode = hasattr(config, "monitor")
	if monitor_mode:
		monitor = config.monitor
		if not "url" in monitor:
			raise Exception("Monitor block requires a \"url\" parameter")

		# run monitoring
		monitor_assets(
			cache,
			settings,
			asset_folders,
			tools,
			args.platform,
			monitor["url"]
		)
	else:
		# just run through all assets
		iterate_assets(
			cache,
			settings,
			asset_folders,
			tools, 
			args.platform
		)

	# write cache to file
	cache.save()