Exemple #1
0
 def __init__(self, mainfile, name=None, guess_files=False):
     self.mainfile = mainfile
     self.df = DepsFinder(mainfile, guess_files)
     self.dt = DirTree(self.df.needed_files)
     self.files = []
     if name:
         self.name = name
     else:
         self.name = uuid.uuid1().hex
     self.dir = DirStruct(self.name)
Exemple #2
0
 def __init__(self, mainfile, name=None, guess_files=False):
     self.mainfile = mainfile
     self.df = DepsFinder(mainfile, guess_files)
     self.dt = DirTree(self.df.needed_files)
     self.files = []
     if name:
         self.name = name
     else:
         self.name = uuid.uuid1().hex
     self.dir = DirStruct(self.name)
Exemple #3
0
class Package(object):
    def __init__(self, mainfile, name=None, guess_files=False):
        self.mainfile = mainfile
        self.df = DepsFinder(mainfile, guess_files)
        self.dt = DirTree(self.df.needed_files)
        self.files = []
        if name:
            self.name = name
        else:
            self.name = uuid.uuid1().hex
        self.dir = DirStruct(self.name)

    def build(self):
        for f in self.df.needed_files:
            rp = f[self.dt.get_cplen():]
            target = self.dir.append("SRC_DIR", rp)
            # self.files.append(rp)
            path_dir = os.path.split(target)[0]
            if not os.path.exists(path_dir):
                os.makedirs(path_dir)
            shutil.copy2(f, target)
        target_wd = self.dir.append("SRC_DIR",
                                    os.getcwd()[self.dt.get_cplen():])
        if not os.path.exists(target_wd):
            os.makedirs(target_wd)
        if not os.path.exists(self.dir.CONF_DIR):
            os.makedirs(self.dir.CONF_DIR)
        self.df.write2file_mods(self.dir.MODS_FILE)
        # self.write2file_files()
        self.write_config()

    def write_config(self):
        with open(self.dir.CONF_FILE, "w") as f:
            pwd = os.getcwd()[self.dt.get_cplen():]
            if not pwd:
                pwd = "."
            pwd = " ".join(pwd.split(os.path.sep))
            f.write("PWD=%s\n" % pwd)
            exec_path = os.path.abspath(self.mainfile)[self.dt.get_cplen():]
            exec_path = " ".join(exec_path.split(os.path.sep))
            f.write("EXEC=%s\n" % exec_path)
Exemple #4
0
class Package(object):
    def __init__(self, mainfile, name=None, guess_files=False):
        self.mainfile = mainfile
        self.df = DepsFinder(mainfile, guess_files)
        self.dt = DirTree(self.df.needed_files)
        self.files = []
        if name:
            self.name = name
        else:
            self.name = uuid.uuid1().hex
        self.dir = DirStruct(self.name)

    def build(self):
        for f in self.df.needed_files:
            rp = f[self.dt.get_cplen():]
            target = self.dir.append("SRC_DIR", rp)
            # self.files.append(rp)
            path_dir = os.path.split(target)[0]
            if not os.path.exists(path_dir):
                os.makedirs(path_dir)
            shutil.copy2(f, target)
        target_wd = self.dir.append("SRC_DIR", os.getcwd()[self.dt.get_cplen():])
        if not os.path.exists(target_wd):
            os.makedirs(target_wd)
        if not os.path.exists(self.dir.CONF_DIR):
            os.makedirs(self.dir.CONF_DIR)
        self.df.write2file_mods(self.dir.MODS_FILE)
        # self.write2file_files()
        self.write_config()

    def write_config(self):
        with open(self.dir.CONF_FILE, "w") as f:
            pwd = os.getcwd()[self.dt.get_cplen():]
            if not pwd:
                pwd = "."
            pwd = " ".join(pwd.split(os.path.sep))
            f.write("PWD=%s\n" % pwd)
            exec_path = os.path.abspath(self.mainfile)[self.dt.get_cplen():]
            exec_path = " ".join(exec_path.split(os.path.sep))
            f.write("EXEC=%s\n" % exec_path)
Exemple #5
0
 def __init__(self, path):
     self.dir = DirStruct(path)
     self.read_conf()
Exemple #6
0
class Agent(object):
    def __init__(self, path):
        self.dir = DirStruct(path)
        self.read_conf()

    def read_mods(self):
        self.mods = []
        with open(self.dir.MODS_FILE, "r") as f:
            for line in f:
                line = line.strip()
                if line and not line.startswith("#"):
                    items = line.split()
                    if len(items) == 1:
                        require_str = items[0]
                    else:
                        require_str = "==".join(items)
                    working_set = pkg_resources.WorkingSet()
                    require = pkg_resources.Requirement.parse(require_str)
                    try:
                        if not working_set.find(require):
                            self.mods.append(require_str)
                    except Exception:
                        self.mods.append(require_str)
        working_dir = os.path.sep.join(self.conf["PWD"].split())
        self.working_dir = self.dir.append("SRC_DIR", working_dir)
        mainfile = os.path.sep.join(self.conf["EXEC"].split())
        self.mainfile = self.dir.append("SRC_DIR", mainfile)

    def read_conf(self):
        self.conf = {}
        with open(self.dir.CONF_FILE, "r") as f:
            for line in f:
                line = line.strip()
                if line and not line.startswith("#"):
                    attr, value = line.split("=")
                    self.conf[attr.strip()] = value.strip()

    def setup_env(self, quiet=False):
        if quiet:
            outproc = lambda x: None
        else:
            outproc = self.print_output
        env_dir = self.dir.ENV_DIR
        if not os.path.exists(env_dir):
            sh.virtualenv("--system-site-packages", env_dir,
                          _out=outproc).wait()
        activate_this = self.dir.append("ENV_DIR", 'bin/activate_this.py')
        execfile(activate_this, dict(__file__=activate_this))
        self.read_mods()
        if self.mods:
            sh.pip.install(self.mods, _out=outproc).wait()

    def print_output(self, line):
        sys.stdout.write(line)

    def run(self, clean):
        sh.cd(self.working_dir)
        try:
            sh.python(self.mainfile,
                      _out=self.print_output,
                      _err=self.print_output).wait()
        except Exception:
            pass
        if clean:
            self.clean()

    def clean(self):
        sh.rm("-rf", self.dir.TOP)
Exemple #7
0
 def __init__(self, path):
     self.dir = DirStruct(path)
     self.read_conf()
Exemple #8
0
class Agent(object):
    def __init__(self, path):
        self.dir = DirStruct(path)
        self.read_conf()

    def read_mods(self):
        self.mods = []
        with open(self.dir.MODS_FILE, "r") as f:
            for line in f:
                line = line.strip()
                if line and not line.startswith("#"):
                    items = line.split()
                    if len(items) == 1:
                        require_str = items[0]
                    else:
                        require_str = "==".join(items)
                    working_set = pkg_resources.WorkingSet()
                    require = pkg_resources.Requirement.parse(require_str)
                    try:
                        if not working_set.find(require):
                            self.mods.append(require_str)
                    except Exception:
                        self.mods.append(require_str)
        working_dir = os.path.sep.join(self.conf["PWD"].split())
        self.working_dir = self.dir.append("SRC_DIR", working_dir)
        mainfile = os.path.sep.join(self.conf["EXEC"].split())
        self.mainfile = self.dir.append("SRC_DIR", mainfile)

    def read_conf(self):
        self.conf = {}
        with open(self.dir.CONF_FILE, "r") as f:
            for line in f:
                line = line.strip()
                if line and not line.startswith("#"):
                    attr, value = line.split("=")
                    self.conf[attr.strip()] = value.strip()


    def setup_env(self, quiet=False):
        if quiet:
            outproc = lambda x:None
        else:
            outproc = self.print_output
        env_dir = self.dir.ENV_DIR
        if not os.path.exists(env_dir):
            sh.virtualenv("--system-site-packages", env_dir, _out=outproc).wait()
        activate_this = self.dir.append("ENV_DIR",'bin/activate_this.py')
        execfile(activate_this, dict(__file__=activate_this))
        self.read_mods()
        if self.mods:
            sh.pip.install(self.mods, _out=outproc).wait()

    def print_output(self, line):
        sys.stdout.write(line)

    def run(self, clean):
        sh.cd(self.working_dir)
        try:
            sh.python(self.mainfile, _out=self.print_output, _err=self.print_output).wait()
        except Exception:
            pass
        if clean:
            self.clean()

    def clean(self):
        sh.rm("-rf", self.dir.TOP)