예제 #1
0
파일: services.py 프로젝트: hcasse/maat
def embed():
	"""Embed the required modules in the current project."""
	
	# select the libraries
	tm = None
	ms = []
	for m in sys.modules.values():
		try:
			if m != None:
				if m.__name__ == "maat":
					tm = m
					ms.append(m)
				elif m.__name__.startswith("maat."):
					ms.append(m) 
		except AttributeError:
			pass

	# get maat directory
	mpath = common.Path(env.top.path) / "maat"

	# copy the modules
	for m in ms:
		p = m.__file__
		if p.endswith(".pyc"):
			p = p[:-1]
		lowlevel.copy(common.Path(p), mpath)
예제 #2
0
def copy(frm, to, filter = common.Filter()):
	"""Perform a copy of a file or a recursive copy of a directory."""
	makedir(to)
	try:
		if not frm.is_dir():
			shutil.copyfile(str(frm), str(to / frm.get_file()))
		else:
			parent = frm.parent()
			for dir, dirs, files in os.walk(str(frm)):
					
				# create directory
				org_dpath = common.Path(dir)
				tgt_dpath = to / common.Path(dir).relative_to(parent)
				if not tgt_dpath.exists():
					os.mkdir(str(tgt_dpath))
					
				# copy files
				for file in files:
					org_fpath = org_dpath / file
					tgt_fpath = to / common.Path(dir).relative_to(parent) / file
					if filter.accept(org_fpath):
						shutil.copyfile(str(org_fpath), str(tgt_fpath))
					
				# copy directories
				for d in dirs:
					org_path = org_dpath / d
					if not filter.accept(org_path):
						dirs.remove(d)
	except (IOError, OSError) as e:
			env.error(str(e))
예제 #3
0
def gen(dir, rext, dep):
    """Generate recipes to build res. A generation string is found between
	file src and res. Each intermediate file has for name the kernel of res
	(generated files will be put in the res directory). Returns the list of
	files to build (last file having rext as extension)."""
    dir = common.Path(dir)
    dep = common.Path(dep)

    # prepare the kernel
    b = dep.get_base()
    dext = dep.get_ext()
    n = b.get_file()
    kern = dir / n

    # initialize lookup process
    if not ext_db.has_key(dext):
        common.script_error("don't know how to build '%s' from '%s'" %
                            (rext, dep))
        #raise Common.MaatError("DEBUG:")
    ext = ext_db[dext]
    prev = dep

    # end when dep is found
    ress = []
    while ext.ext != rext:
        gen = ext.gens[rext]
        next = kern + gen.res.ext
        gen.gen(next, prev)
        ress.append(next)
        prev = next
        ext = gen.res

    # return result
    return ress
예제 #4
0
 def write(self, out):
     a = action.make_actions(
         self.fun([File(common.Path("*" + self.res.ext))],
                  [File(common.Path("*" + self.dep.ext))]))
     cmds = []
     a.commands(cmds)
     for c in cmds:
         out.write("\t%s\n" % c)
예제 #5
0
def set_env(e):
    global curenv
    global curdir
    env.cur = e
    curenv = e
    curdir = common.Path(e.path)
    e.path.set_cur()
예제 #6
0
def phony(goal, deps, *actions):
    """Build a goal with the following dependencies that does not
	match a real file."""
    path = common.Path(env.cur.path) / goal
    file = get_file(str(path))
    if file.recipe:
        common.script_error("a goal named '%s' already exist!" % goal)
    else:
        file.set_phony()
        return ActionRecipe(goal, deps, *actions).ress[0]
예제 #7
0
 def test(self, ctx):
     self.perform(ctx)
     if self.dir != None:
         old_dir = os.getcwd()
         try:
             os.chdir(self.dir)
         except OSError as e:
             raise common.MaatError("cannot change to '%s': %s" %
                                    (self.dir, e))
     if self.out:
         out = common.Path(self.out)
         maat.mkdir(str(out.parent()))
         out_stream = open(str(out), "w")
     else:
         out_stream = NULL
     if self.err:
         err = common.Path(self.err)
         maat.mkdir(str(err.parent()))
         err_stream = open(str(err), "w")
     else:
         err_stream = NULL
     if self.inp:
         in_stream = open(str(self.input), "r")
     else:
         in_stream = NULL
     cmd = action.make_line(self.args)
     if maat.verbose:
         ctx.print_info("running %s" % cmd)
     rc = subprocess.call(cmd,
                          stdin=in_stream,
                          stdout=out_stream,
                          stderr=err_stream,
                          shell=True)
     if self.check(rc):
         self.success(ctx)
     else:
         self.failure(ctx, "return code = %d, command = %s" % (rc, cmd))
     if self.dir != None:
         os.chdir(old_dir)
예제 #8
0
def get_goal(path):
    """Get the goal matching the given path in the DB. Apply
	localization rules relative to a particular make.py if the path
	is not absolute. If the goal cannot be found, raise a MaatError."""

    # apply localisation rule
    if not os.path.isabs(str(path)):
        fpath = env.cur.path / path
    else:
        fpath = common.Path(path)
    fpath = fpath.norm()

    # find the file
    if str(fpath) in file_db:
        return file_db[str(fpath)]
    else:
        raise common.MaatError("goal %s does not exist" % path)
예제 #9
0
def get_file(path):
    """Get the file matching the given path in the DB. Apply
	localization rules relative to a particular make.py if the path
	is not absolute."""

    # apply localisation rule
    if not os.path.isabs(str(path)):
        path = env.cur.path / path
    else:
        path = common.Path(path)
    path = path.norm()

    # find the file
    if str(path) in file_db:
        return file_db[str(path)]
    else:
        return File(path)
예제 #10
0
    def actual(self):
        """Get the actual path of the file. For target file, this path
		is relative to BPATH variable."""
        if not self.actual_path:
            if not self.is_target:
                self.actual_path = self.path
            else:
                bpath = self["BPATH"]
                if not bpath:
                    self.actual_path = self.path
                else:
                    bpath = env.top.path / bpath
                    bpath = common.Path(bpath)
                    if self.path.prefixed_by(env.top.path):
                        self.actual_path = bpath / self.path.relative_to(
                            env.top.path)
                    else:
                        self.actual_path = bpath / self.path
        return self.actual_path
예제 #11
0
def path(p):
    """Convert simple string to Maat path."""
    if p == None or isinstance(p, common.Path):
        return p
    else:
        return common.Path(str(p))
예제 #12
0
def suffix(p):
    """Get extension of a path or a list of paths."""
    if isinstance(p, list):
        return [common.Path(x).get_ext() for x in p]
    else:
        return common.Path(p).get_ext()
예제 #13
0
def isdir(path):
    """Test if the given path is a directory."""
    return common.Path(path).is_dir()
예제 #14
0
def join(a1, a2):
    """Join two parts of a file path."""
    return common.Path(a1) / a2
예제 #15
0
def curdir():
    """Get the current working directory."""
    return common.Path(os.getcwd())
예제 #16
0
#	This program is distributed in the hope that it will be useful,
#	but WITHOUT ANY WARRANTY; without even the implied warranty of
#	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#	GNU General Public License for more details.
#
#	You should have received a copy of the GNU General Public License
#	along with this program.  If not, see <http://www.gnu.org/licenses/>.
"""Implementation of environment in Maat."""
import glob
import os
import os.path
import sys

import maat.common as common

topdir = common.Path(os.getcwd())  # top directory


def curdir():
    """Get the current working directory."""
    return common.Path(os.getcwd())


# environments
class Env:
    """Base class of environments."""
    path = ""
    name = ""

    def __init__(self, name, path=topdir):
        self.name = name
예제 #17
0
파일: build.py 프로젝트: hcasse/maat
 def push_env(self):
     """Install the environment to build the target."""
     if self.target.recipe:
         maat.push_env(self.target.recipe.env)
         common.Path(self.target.recipe.cwd).set_cur()
예제 #18
0
 def __init__(self, name, blocking=False, deps=[]):
     recipe.File.__init__(self, common.Path("config/%s" % name))
     self.name = name
     self.blocking = blocking
     self.deps = []
     self.result = None
예제 #19
0
 def __init__(self, paths, target):
     self.paths = [common.Path(arg) for arg in args]
     self.target = common.Path(target)
예제 #20
0
 def __init__(self, src, tgt):
     self.src = common.Path(src)
     self.tgt = common.Path(tgt)
예제 #21
0
 def __init__(self, path, content):
     self.path = common.Path(path)
     self.content = str(content)