Example #1
0
def state(cookies, path):
	"""Returns the state of an app, which includes:

	{
		'platform_version': platform version in config.json.
		'problems': a list of problems which should be displayed in the app status box.
		'should_rebuild': whether the app needs to be rebuilt due to config or platform changes.
		'did_migrate': whether the app was updated in some way to make it compatible with the platform version in config.json.
	}

	:param path: Path to the app we want the state of.
	"""
	file_problem = _missing_file_problems(path)
	if file_problem:
		return dict(
			problem=file_problem,
			should_rebuild=False
		)

	app_config = build_config.load_app(path)
	app_platform = app_config.get('platform_version')
	if app_platform is None:
		return dict(
			problem={
				'type': 'platform_version_missing'
			},
			should_rebuild=False
		)

	try:
		response_dict = forge_tool.singleton.remote.server_says_should_rebuild(path, cookies=cookies)
	except RequestError as e:
		return dict(
			platform_version=app_platform,
			problem=_classify_request_error(e),
			should_rebuild=False
		)

	if not response_dict['should_rebuild']:
		did_migrate = lib.make_dynamic_call(
			[os.path.join(path, '.template'), os.path.join(path, '.template', '.lib')],
			'generate_dynamic.customer_goals.migrate_app_to_current',
			{'path': path},
			fail_if_missing=False
		)
		if did_migrate:
			async.current_call().emit('migration')

	return dict(
		platform_version=app_platform,
		should_rebuild=response_dict['should_rebuild'],
	)
Example #2
0
def platform_targets(path):
	"""Returns the targets supported by the current platform"""
	try:
		targets = lib.make_dynamic_call(
			[os.path.join(path, '.template'), os.path.join(path, '.template', '.lib')],
			'generate_dynamic.build.enabled_platforms',
			{ 'build_type_dir': path },
			fail_if_missing = True
		)
	except:
		targets = [	'safari', 'osx', 'firefox', 'reload', 'web', 'chrome', 'ios',
					'android', 'wp', 'ie', 'ios-native', 'android-native' ]	

	return targets
def create_plugin_template(cookies, uuid, name, path, core_version):
	'''Create a template for a plugin and return a local plugin object (similar to list_local) to be immediately used'''
	path = os.path.abspath(path)
	if not os.path.exists(path):
		os.makedirs(path)

	if os.listdir(path):
		raise Exception("Plugin can only be created in an empty directory.")

	_update_plugin_dynamic(cookies, path, core_version)

	# Run create template from plugin_dynamic
	result = make_dynamic_call(os.path.join(path, ".trigger", "plugin_dynamic"), 'plugin.create_template', {"uuid": uuid, "name": name, "path": path})

	_add_plugin_location(path)

	return result
def create_module_template(cookies, name, path, namespace, core_version):
    """Create a template for a module and return a local module object (similar to list_local) to be immediately used"""
    path = os.path.abspath(path)
    if not os.path.exists(path):
        os.makedirs(path)

    if os.listdir(path):
        raise Exception("module can only be created in an empty directory.")

    _update_module_dynamic(cookies, path, core_version)

    # Run create template from module_dynamic
    result = make_dynamic_call(
        os.path.join(path, ".trigger", "module_dynamic"),
        "module.create_template",
        {"name": name, "path": path, "namespace": namespace},
    )

    _add_module_location(path)

    return result
            with open(module_manifest_path) as module_manifest_file:
                try:
                    module_manifest_dict = json.load(module_manifest_file)
                except ValueError:
                    raise ValueError("Couldn't parse JSON file: %s" % module_manifest_path)
        except IOError:
            return module_model

    if "platform_version" in module_manifest_dict:
        try:
            _update_module_dynamic_if_needed(cookies, path, module_manifest_dict["platform_version"])

            module_model.update(
                make_dynamic_call(
                    os.path.join(path, ".trigger", "module_dynamic"),
                    "module.load",
                    {"path": path, "manifest": module_manifest_dict},
                )
            )
        except Exception:
            module_model["problems"] = [
                {
                    "raw_message": """<p class='bigger'>Failed to download platform code</p>
				<p>You probably have a bad platform_version in your module manifest, make sure the file '%s' contains a valid platform_version property.</p>"""
                    % module_manifest_path
                }
            ]
    else:
        # No platform version means we can't use dynamic code to load the module
        # XXX: I don't think this error will ever be seen, local modules with no name are effectively ignored by the toolkit
        module_model["problems"] = [
def make_call(python_path, method_name, params):
	return make_dynamic_call(python_path, method_name, params)
	plugin_model = {}
	plugin_manifest_path = os.path.join(path, "plugin", "manifest.json")

	with async.current_call().io_lock:
		with open(plugin_manifest_path) as plugin_manifest_file:
			try:
				plugin_manifest_dict = json.load(plugin_manifest_file)
			except ValueError:
				raise ValueError("Couldn't parse JSON file: %s" % plugin_manifest_path)

	if "platform_version" in plugin_manifest_dict:
		_update_plugin_dynamic_if_needed(cookies, path, plugin_manifest_dict['platform_version'])

		plugin_model.update(make_dynamic_call(
			os.path.join(path, ".trigger", "plugin_dynamic"),
			'plugin.load',
			{"path": path, "manifest": plugin_manifest_dict}
		))
	elif "uuid" in plugin_manifest_dict:
		# No platform version means we can't use dynamic code to load the plugin
		plugin_model['problems'] = [{
			"raw_message": """<p class='bigger'>No platform version in manifest</p>
			<p>A platform version is required in the plugin manifest, make sure the file '%s' contains a platform_version property.</p>""" % plugin_manifest_path
		}]
	else:
		# No way to identify plugin
		raise Exception("No plugin uuid found in manifest: %s" % plugin_manifest_path)

	return plugin_model

@expose