def _run(module,
         logger,
         task,
         completed_tasks,
         from_command_line=False,
         args=None,
         kwargs=None):
    """
    @type module: module
    @type logging: Logger
    @type task: Task
    @type completed_tasts: set Task
    @rtype: set Task
    @return: Updated set of completed tasks after satisfying all dependencies.
    """
    # Satsify dependencies recursively. Maintain set of completed tasks so each
    # task is only performed once.
    input_artifacts = {}
    for dependency in task.dependencies:
        _run(module, logger, dependency, completed_tasks)
        input_artifacts[dependency.name] = artifact_file(
            dependency.name, completed_tasks[dependency.name])

    # Perform current task, if need to.
    if from_command_line or task.name not in completed_tasks:

        if task.ignored:

            logger.info("Ignoring task \"%s\"" % task.name)
            cs = 'IGNORE'
        else:

            logger.info(yellow("Starting task \"%s\"" % task.name))
            try:
                # Run task.
                cs = checksum(module, input_artifacts, task.func,
                              task.watched_sources, args, kwargs)
                if cuisine.dir_exists(artifact_file(task.name, cs)):
                    logger.info("Nothing changed")
                else:
                    cuisine.dir_remove(artifact_dir(task.name))
                    cuisine.dir_ensure(artifact_dir(task.name))
                    cuisine.dir_remove(tmp_file(task.name))
                    cuisine.dir_ensure(tmp_file(task.name))
                    State.input_artifacts = input_artifacts
                    State.output_artifact = task.name
                    logger.info("Going to write an artifact with checksum " +
                                cs)
                    task(*(args or []), **(kwargs or {}))
                    cuisine.run("mv " + tmp_file(task.name) + " " +
                                artifact_file(task.name, cs))
            except:
                logger.critical("Error in task \"%s\"" % task.name)
                logger.critical("Aborting build")
                raise

            logger.info("Completed task " + task.name + " artifact path: " +
                        artifact_file(task.name, cs))

        completed_tasks[task.name] = cs
示例#2
0
文件: all.py 项目: magahet/cuisine
 def testAttribs(self):
     tmpdir = tempfile.mkdtemp()
     try:
         dir1_path = os.path.join(tmpdir, 'dir1')
         cuisine.dir_ensure(dir1_path)
         file1_path = os.path.join(dir1_path, 'file1')
         cuisine.file_write(file1_path, 'test', mode='666')
         cuisine.dir_attribs(tmpdir, mode=755, recursive=True)
         attribs = cuisine.file_attribs_get(dir1_path)
         self.assertEqual(attribs.get('mode'), '755')
     finally:
         cuisine.dir_remove(tmpdir, recursive=True)
def _run(module, logger, task, completed_tasks, from_command_line = False, args = None, kwargs = None):
    """
    @type module: module
    @type logging: Logger
    @type task: Task
    @type completed_tasts: set Task
    @rtype: set Task
    @return: Updated set of completed tasks after satisfying all dependencies.
    """
    # Satsify dependencies recursively. Maintain set of completed tasks so each
    # task is only performed once.
    input_artifacts={}
    for dependency in task.dependencies:
        _run(module,logger,dependency, completed_tasks)
        input_artifacts[dependency.name] = artifact_file(dependency.name, completed_tasks[dependency.name])


    # Perform current task, if need to.
    if from_command_line or task.name not in completed_tasks:

        if task.ignored:
        
            logger.info("Ignoring task \"%s\"" % task.name)
            cs = 'IGNORE'
        else:

            logger.info(yellow("Starting task \"%s\"" % task.name))
            try:
                # Run task.
                cs = checksum(module, input_artifacts, task.func, task.watched_sources, args, kwargs)
                if cuisine.dir_exists(artifact_file(task.name, cs)):
                    logger.info("Nothing changed")
                else:
                    cuisine.dir_remove(artifact_dir(task.name))
                    cuisine.dir_ensure(artifact_dir(task.name))
                    cuisine.dir_remove(tmp_file(task.name))
                    cuisine.dir_ensure(tmp_file(task.name))
                    State.input_artifacts = input_artifacts
                    State.output_artifact = task.name
                    logger.info("Going to write an artifact with checksum " + cs)
                    task(*(args or []), **(kwargs or {}))
                    cuisine.run("mv " + tmp_file(task.name) + " " + artifact_file(task.name, cs))
            except:
                logger.critical("Error in task \"%s\"" % task.name)
                logger.critical("Aborting build")
                raise
            
            logger.info("Completed task " + task.name + " artifact path: " + artifact_file(task.name, cs))
        
        completed_tasks[task.name] = cs
示例#4
0
 def uninstall_gunicorn(self):
     with mode_sudo():
         with settings(warn_only=True):
             dir_remove('/var/log/gunicorn', recursive = True)
             if (self.virtualenv_dir and 
                 file_exists(self.virtualenv_dir + '/bin/activate')
                 ):
                 dir_remove(self.virtualenv_dir, recursive = True)
             if self.util.get_package_manager() == 'apt':
                 dir_remove('/etc/init/gunicorn.conf') 
示例#5
0
 if not os.path.isdir("/root/.unison"):
     os.mkdir("/root/.unison")
 sed_cmd3 = 'sed "s/SLAVESERVER/'+slaveip+'/g" '+installation_path+'/conf/default.prf > /root/.unison/default.prf'
 subprocess.call(sed_cmd3, shell=True)
 rsync_cmd1 = 'rsync -av '+installation_path+'/conf/lsyncd_master.conf /etc/lsyncd.conf'
 subprocess.call(rsync_cmd1, shell=True)
 sed_cmd4 = 'sed -e "s/MASTERSERVER/'+masteripalone+'/g" -e "s/MASTERSSHPORT/'+masterport+'/g" '+installation_path+'/conf/lsyncd_slave.conf > /tmp/nDeploy_lsyncd.conf'
 subprocess.call(sed_cmd4, shell=True)
 cuisine.rsync("/tmp/nDeploy_lsyncd.conf", "/etc/lsyncd.conf")
 os.remove("/tmp/nDeploy_lsyncd.conf")
 cuisine.run('sed -i "s/^UMASK/#UMASK/" /etc/login.defs')
 if not os.path.isdir("/etc/nginx/"+slaveserver):
     os.mkdir("/etc/nginx/"+slaveserver)
 cuisine.dir_ensure("/etc/nginx/"+slaveserver)
 if not cuisine.file_is_link("/etc/nginx/sites-enabled"):
     cuisine.dir_remove("/etc/nginx/sites-enabled")
     cuisine.file_link("/etc/nginx/"+slaveserver, "/etc/nginx/sites-enabled", symbolic=True)
 subprocess.call('systemctl enable  csync2.socket', shell=True)
 subprocess.call('systemctl start csync2.socket', shell=True)
 cuisine.run('systemctl enable  csync2.socket')
 cuisine.run('systemctl start csync2.socket')
 # Do a Manual csync2 sync
 subprocess.call("/usr/sbin/csync2 -xv", shell=True)
 subprocess.call('grep "/usr/sbin/csync2" /etc/crontab || echo "* * * * * root /usr/sbin/csync2 -x" >> /etc/crontab', shell=True)
 subprocess.call('systemctl restart crond.service', shell=True)
 subprocess.call('systemctl enable  lsyncd.service', shell=True)
 subprocess.call('systemctl start lsyncd.service', shell=True)
 cuisine.run('systemctl enable  lsyncd.service')
 cuisine.run('systemctl start lsyncd.service')
 cuisine.run('systemctl enable nginx.service')
 cuisine.run('systemctl start nginx.service')
示例#6
0
 def remove_project(self):
     with settings(warn_only=True):
         if dir_exists('%s/.%s' % (self.repo_dir, self.vcs)):
             with mode_sudo():
                 dir_remove(self.repo_dir, recursive=True,)
示例#7
0
 def remove_symlink(self):
     (basedir, symlink_location) = self.www_dir.rsplit('/', 1)
     with settings(warn_only=True):
         if file_is_link(self.www_dir):
             with mode_sudo():
                 dir_remove(self.www_dir, recursive = True)
 if not os.path.isdir("/root/.unison"):
     os.mkdir("/root/.unison")
 sed_cmd3 = 'sed "s/SLAVESERVER/' + slaveip + '/g" ' + installation_path + '/conf/default.prf > /root/.unison/default.prf'
 subprocess.call(sed_cmd3, shell=True)
 rsync_cmd1 = 'rsync -av ' + installation_path + '/conf/lsyncd_master.conf /etc/lsyncd.conf'
 subprocess.call(rsync_cmd1, shell=True)
 sed_cmd4 = 'sed -e "s/MASTERSERVER/' + masteripalone + '/g" -e "s/MASTERSSHPORT/' + masterport + '/g" ' + installation_path + '/conf/lsyncd_slave.conf > /tmp/nDeploy_lsyncd.conf'
 subprocess.call(sed_cmd4, shell=True)
 cuisine.rsync("/tmp/nDeploy_lsyncd.conf", "/etc/lsyncd.conf")
 os.remove("/tmp/nDeploy_lsyncd.conf")
 cuisine.run('sed -i "s/^UMASK/#UMASK/" /etc/login.defs')
 if not os.path.isdir("/etc/nginx/" + slaveserver):
     os.mkdir("/etc/nginx/" + slaveserver)
 cuisine.dir_ensure("/etc/nginx/" + slaveserver)
 if not cuisine.file_is_link("/etc/nginx/sites-enabled"):
     cuisine.dir_remove("/etc/nginx/sites-enabled")
     cuisine.file_link("/etc/nginx/" + slaveserver,
                       "/etc/nginx/sites-enabled",
                       symbolic=True)
 subprocess.call('systemctl enable  csync2.socket', shell=True)
 subprocess.call('systemctl start csync2.socket', shell=True)
 cuisine.run('systemctl enable  csync2.socket')
 cuisine.run('systemctl start csync2.socket')
 # Do a Manual csync2 sync
 subprocess.call("/usr/sbin/csync2 -xv", shell=True)
 subprocess.call(
     'grep "/usr/sbin/csync2" /etc/crontab || echo "* * * * * root /usr/sbin/csync2 -x" >> /etc/crontab',
     shell=True)
 subprocess.call('systemctl restart crond.service', shell=True)
 subprocess.call('systemctl enable  lsyncd.service', shell=True)
 subprocess.call('systemctl start lsyncd.service', shell=True)