Ejemplo n.º 1
0
def clean(role, build_path):
    if os.path.exists(build_path):
        fckit.remove(build_path)
    if role.is_legacy():
        print "skipping handcrafted main task file"
        generated = (role.readme_path, )
    else:
        generated = (role.readme_path, role.tasks_path)
    for root, dirnames, filenames in os.walk("."):
        for filename in filenames:
            path = os.path.normpath(os.path.join(root, filename))
            if fnmatch.fnmatch(filename, ".*.hmap") or path in generated:
                fckit.remove(path)
Ejemplo n.º 2
0
def clean(role, build_path):
	if os.path.exists(build_path):
		fckit.remove(build_path)
	if role.is_legacy():
		print "skipping handcrafted main task file"
		generated = (role.readme_path,)
	else:
		generated = (role.readme_path, role.tasks_path)
	for root, dirnames, filenames in os.walk("."):
		for filename in filenames:
			path = os.path.normpath(os.path.join(root, filename))
			if fnmatch.fnmatch(filename, ".*.hmap") or path in generated:
				fckit.remove(path)
Ejemplo n.º 3
0
	def _handle_target(self, name, default = "stack", **kwargs):
		"generic target handler: call the custom handler if it exists, or fallback on default"
		fckit.trace(">>", "[", name, "]")
		handler = self.manifest.get("on_%s" % name, default)
		if handler is Exception:
			raise Error(self.manifest["name"], name, "unsupported target")
		elif handler is None:
			pass
		elif handler == "stack": # stack target and let the on_flush handler deal with it
			self.targets.append(name, **kwargs)
		elif callable(handler):
			for res in (handler)(
				filename = self.filename,
				targets = self.targets,
				**kwargs):
				if isinstance(res, (list, tuple)):
					if res[0] == "@try":
						try:
							self._check_call(res[1:])
						except:
							fckit.trace("command failure ignored")
					elif res[0] == "@tag":
						self._check_call(self.vcs.tag(*res[1:]))
					elif res[0] == "@push":
						self._check_call(self.vcs.push())
					elif res[0] == "@flush":
						assert name != "flush", "infinite recursion detected"
						self.flush()
					elif res[0] == "@trace":
						fckit.trace(*res[1:])
					elif res[0] == "@purge":
						self._check_call(self.vcs.purge())
					elif res[0] == "@commit":
						self._check_call(self.vcs.commit(*res[1:]))
					elif res[0] == "@remove":
						fckit.remove(*res[1:])
					else:
						self._check_call(res)
				else: # res is an error object
					raise Error(self.manifest["name"], name, res)
		else:
			raise AssertionError("invalid target handler")
		fckit.trace("<<", "[", name, "]")
Ejemplo n.º 4
0
def check_syntax(role, helpers):
	"generate a playbook using the role and syntax-check it"
	tmpdir = fckit.mkdir()
	cwd = os.getcwd()
	#print "!! role path=", cwd
	#print "!! playbook path=", tmpdir
	fckit.chdir(tmpdir)
	try:
		# write playbook:
		playbook = [{
			"hosts": "127.0.0.1",
			"connection": "local",
			"roles": [role.name],
		}]
		helpers["marshall"](
			obj = playbook,
			path = os.path.join(tmpdir, "playbook.yml"))
		# write inventory:
		inventory = "localhost ansible_connection=local"
		helpers["marshall"](
			obj = inventory,
			path = os.path.join(tmpdir, "inventory.cfg"),
			extname = ".txt")
		# write configuration:
		config = {
			"defaults": {
				"roles_path": os.path.dirname(cwd),
				"hostfile": "inventory.cfg",
			}
		}
		helpers["marshall"](
			obj = config,
			path = os.path.join(tmpdir, "ansible.cfg"))
		# perform the check:
		fckit.check_call("ansible-playbook", "playbook.yml", "--syntax-check")
		return True
	except:
		return False
	finally:
		fckit.chdir(cwd)
		fckit.remove(tmpdir)
Ejemplo n.º 5
0
def check_syntax(role, helpers):
    "generate a playbook using the role and syntax-check it"
    tmpdir = fckit.mkdir()
    cwd = os.getcwd()
    #print "!! role path=", cwd
    #print "!! playbook path=", tmpdir
    fckit.chdir(tmpdir)
    try:
        # write playbook:
        playbook = [{
            "hosts": "127.0.0.1",
            "connection": "local",
            "roles": [role.name],
        }]
        helpers["marshall"](obj=playbook,
                            path=os.path.join(tmpdir, "playbook.yml"))
        # write inventory:
        inventory = "localhost ansible_connection=local"
        helpers["marshall"](obj=inventory,
                            path=os.path.join(tmpdir, "inventory.cfg"),
                            extname=".txt")
        # write configuration:
        config = {
            "defaults": {
                "roles_path": os.path.dirname(cwd),
                "hostfile": "inventory.cfg",
            }
        }
        helpers["marshall"](obj=config,
                            path=os.path.join(tmpdir, "ansible.cfg"))
        # perform the check:
        fckit.check_call("ansible-playbook", "playbook.yml", "--syntax-check")
        return True
    except:
        return False
    finally:
        fckit.chdir(cwd)
        fckit.remove(tmpdir)
Ejemplo n.º 6
0
	def tearDown(self):
		fckit.remove(self.tmpdir)
Ejemplo n.º 7
0
 def tearDown(self):
     fckit.chdir(self.cwd)
     fckit.remove(self.tmpdir)
Ejemplo n.º 8
0
def clean(role):
	path = os.path.dirname(role.package_path)
	if os.path.exists(path):
		fckit.remove(path)
Ejemplo n.º 9
0
	def tearDown(self):
		fckit.remove(self.dirname)
Ejemplo n.º 10
0
	def tearDown(self):
		fckit.chdir(self.cwd)
		fckit.remove(self.tmpdir)