Exemple #1
0
    def installApp(self, child, app):
        self.installLibrary(child)

        if "PY_MAIN" in child["APP_OPTIONS"] and child.isRoot():
            PyLog.log("application script")
            PyLog.increaseIndent()
            self.installApplication(child)
            PyLog.decreaseIndent()
Exemple #2
0
    def runAction(self, app, action, function):
        PyLog.log("%s(%s)" % (self.name(), app.name()))
        PyLog.debug("%s(%s)[%s]" % (self.name(), app.name(), app._dir),
                    log_level=6)

        PyLog.increaseIndent()

        file_stats = {}
        try:
            ## Check if we're up to date
            file_stats = app.fileStats()
            updated = FD.FileStats.updatedFiles(file_stats)

            if len(updated) == 0:
                PyLog.log("Up to date", log_level=-1)
                return True
            else:
                PyLog.log("OUT of date", count=len(updated), log_level=-1)
                #PyLog.decreaseIndent()

            cmds = []

            ## If no children but we're being built
            ## We must just be a shallow app.
            for child in [app] + app.children:
                t_cmds = function(child, app)
                PyLog.debug("Returned", t_cmds, log_level=6)
                if t_cmds:
                    cmds += t_cmds

            if not cmds:
                cmds = []
            for cmd in cmds:
                if hasattr(cmd, "__call__"):
                    cmd(app)
                elif isinstance(cmd, basestring):
                    if PySH.cmd(cmd, stdout=True, stderr=True) != 0:
                        raise ToolChainException(
                            "Failure while performing action",
                            action=action,
                            app=app,
                            cmd=cmd)
                else:
                    raise ToolChainException(
                        "Invalid %s cmd. Cmds must be string or fun: %s : %s" %
                        (action, app, cmd))
        except PyExcept.BaseException as e:
            raise e
        except Exception as e:
            raise ToolChainException(None, trace=sys.exc_info())

        finally:
            PyLog.decreaseIndent()

        FD.FileStats.saveFileStats(file_stats)

        PyLog.decreaseIndent()
        return True
Exemple #3
0
    def installApp(self, child, app):
        self.config = app
        self.installMisc(app)

        main_steps = [("startup script", self.genShellScript),
                      ("environment script", self.genShellEnvScript),
                      ("instance connect script", self.genShellConnectScript),
                      ("bake cookie", self.genCookie),
                      ("gen dirs", self.genDirs)]

        if app.name() == app["TOOL_OPTIONS"]["ERL_MAIN"] or (
                "EXECUTABLE" in app["APP_OPTIONS"]
                and app["APP_OPTIONS"]["EXECUTABLE"] == True):

            for (label, step) in main_steps:
                PyLog.log(label)
                PyLog.increaseIndent()
                step(app)
                PyLog.decreaseIndent()
Exemple #4
0
	def run(self):
		error = None
		res   = False

		try:
			res = self.action(self.app)
		except PyExcept.BaseException as e:
			PyLog.increaseIndent()
			PyLog.error(e)
			PyLog.decreaseIndent()
		except Exception as e:
			et, ei, tb = sys.exc_info()
			PyLog.error("Exception during %s%s" % (self.action, self.key), exception=str(e))
			PyLog.increaseIndent()
			for line in traceback.format_tb(tb):
				for t_line in line.strip().split("\n"):
					PyLog.error(t_line)
			PyLog.decreaseIndent()

		self.clean_queue.put((self.key, res))
Exemple #5
0
def main():
	cli = PyConfig.CLIConfig()

	PyLog.setLogLevel(0 if "LOG_LEVEL" not in cli else int(cli["LOG_LEVEL"]))
	
	fishmonger.addInternalToolChains(cli.get("INTERNAL_TOOL", []))
	fishmonger.addExternalToolChains(cli.get("EXTERNAL_TOOL", []))
	fishmonger.addCleanToolChains(   cli.get("CLEAN_TOOL",    []))
	fishmonger.addGenerateToolChains(cli.get("GENERATE_TOOL", []))
	fishmonger.addBuildToolChains(   cli.get("BUILD_TOOL",    []))
	fishmonger.addLinkToolChains(    cli.get("LINK_TOOL",     []))
	fishmonger.addInstallToolChains( cli.get("INSTALL_TOOL",  []))
	fishmonger.addDocumentToolChains(cli.get("DOC_TOOL",      []))
	fishmonger.addPackageToolChains( cli.get("PACKAGE_TOOL",  []))

	fish                = FishMonger()

	tools_for_all       = fishmonger.InternalToolChains
	
	actions = {}
	actions["clean"]    = [(fish.clean, tools_for_all | fishmonger.CleanToolChains)]

	actions["build"]    = [
		(fish.generate, tools_for_all | fishmonger.GenerateToolChains),
		(fish.build,    tools_for_all | fishmonger.BuildToolChains),
		(fish.link,     tools_for_all | fishmonger.LinkToolChains)
	]
	actions["compile"]  = actions["build"]

	actions["install"]  = [(fish.install,  tools_for_all | fishmonger.InstallToolChains)]
	actions["doc"]      = [(fish.document, tools_for_all | fishmonger.DocumentToolChains)]
	actions["document"] = actions["doc"]
	
	actions["package"]  = [(fish.packageConfigure, None)] + actions["clean"] + actions["build"] + actions["install"] + [(fish.package, tools_for_all | fishmonger.PackageToolChains)]

	actions["test"]     = [(None, [])]

	x = 0;
	if x not in cli:
		PyLog.error("Usage: fishmonger <clean|build|compile|install|doc|document|package>")
		return 1

	PyLog.log("Configuring")
	PyLog.increaseIndent()
	fish.configure(fishmonger.AllToolChains)
	PyLog.decreaseIndent()

	cli_actions = []
	while x in cli:
		if cli[x] not in actions:
			PyLog.error("Invalid action", cli[x])
			PyLog.error("Usage: fishmonger <clean|build|compile|install|doc|document|package>")
			return 1	
		cli_actions.append(cli[x])
		x += 1

	if "package" in cli_actions:
		cli_actions = ["package"]

	global_args = {
		"max_cores" : int(cli["MAX_CORES"]) if "MAX_CORES" in cli else multiprocessing.cpu_count()
	}

	run_actions = []
	for action in cli_actions:
		tasks = actions[action]
		for (task, tools) in tasks:
			if task not in run_actions:
				run_actions.append(task)
				task((fishmonger.ExternalToolChains, tools), **global_args)
Exemple #6
0
	def package(self, tools, **kwargs):
		PyLog.log("Packaging")
		PyLog.increaseIndent()
		self.configureAction(tools, "package")
		self.runAction(**kwargs)
		PyLog.decreaseIndent()
Exemple #7
0
	def link(self, tools, **kwargs):
		PyLog.log("Linking")
		PyLog.increaseIndent()
		self.configureAction(tools, "link")
		self.runAction(**kwargs)
		PyLog.decreaseIndent()
Exemple #8
0
	def generate(self, tools, **kwargs):
		PyLog.log("Generating")
		PyLog.increaseIndent()
		self.configureAction(tools, "generate")
		self.runAction(**kwargs)
		PyLog.decreaseIndent()
Exemple #9
0
	def clean(self, tools, **kwargs):
		PyLog.log("Cleaning")
		PyLog.increaseIndent()
		self.configureAction(tools, "clean")
		self.runAction(**kwargs)
		PyLog.decreaseIndent()
Exemple #10
0
	def document(self, tools, **kwargs):
		PyLog.log("Documenting")
		PyLog.increaseIndent()
		self.configureAction(tools, "document")
		self.runAction(**kwargs)
		PyLog.decreaseIndent()
Exemple #11
0
	def install(self, tools, **kwargs):
		PyLog.log("Installing")
		PyLog.increaseIndent()
		self.configureAction(tools, "install")
		self.runAction(**kwargs)
		PyLog.decreaseIndent()
Exemple #12
0
	def build(self, tools, **kwargs):
		PyLog.log("Building")
		PyLog.increaseIndent()
		self.configureAction(tools, "build")
		self.runAction(**kwargs)
		PyLog.decreaseIndent()
Exemple #13
0
def getRequiredApps(app, install_dir="."):
    PyLog.increaseIndent()

    global AppRequirements

    seen_apps = {}
    apps = []

    PyLog.debug("Find", app)

    ## If we already exist just return
    if app in AppRequirements:
        PyLog.debug("Already exist!")
        PyLog.decreaseIndent()
        return AppRequirements[app]

    app_file = None
    for search_dir in [install_dir] + [
            "/usr/lib/erlang", "/usr/lib64/erlang", "/usr/local/lib/erlang"
    ]:
        PyLog.debug("Searching for .app file",
                    app=app,
                    search_dir=search_dir,
                    log_level=5)
        app_file = PyFind.find("*/" + app + ".app", search_dir)
        PyLog.debug("Found .app file", app_file=app_file, log_level=5)
        if app_file:
            break

    if not app_file:
        PyLog.debug("Doesnt exist!")
        PyLog.decreaseIndent()
        return apps

    doc = PyErl.parse_file(app_file)
    tuples = doc.getElementsByTagName("tuple")
    tuple = None

    ## Find Application tuple
    for ttuple in tuples:
        if ttuple[0].to_string() == "applications":
            tuple = ttuple
            break

    ## If no apps are specified we can just start
    if tuple == None:
        PyLog.debug("No apps required")
        PyLog.decreaseIndent()
        return [app]

    all_dapps = []
    ## For each required app
    for dapp in tuple[1]:
        ## Get that apps required apps
        all_dapps += getRequiredApps(dapp.to_string(), install_dir)

    for t_app in all_dapps:
        if t_app in seen_apps:
            continue
        seen_apps[t_app] = 1
        apps.append(t_app)

    apps.append(app)
    AppRequirements[app] = apps

    PyLog.debug("APP USE", app=app, apps=apps)

    PyLog.debug("Complete")
    PyLog.decreaseIndent()
    return apps