コード例 #1
0
 def test_can_be_used_to_create_directories(self):
     d = self.tmppath('some', 'dir')
     self.assertFalse(os.path.exists(d))
     with ignoring(errno.EEXIST):
         os.makedirs(d)
     self.assertTrue(os.path.exists(d))
     with ignoring(errno.EEXIST):
         os.makedirs(d)
コード例 #2
0
    def gc(self, max_versions):
        '''
        Remove all deployed versions except the most recent max_versions, and
        any live verisons.
        '''
        with self.lock:
            old_versions = set(self.deployed_versions[:-max_versions])
            if self.live_version:
                old_versions.discard(self.live_version)

                # We bootstrap environments that have their own Jenkins, from
                # the production repository. So there is likely to be 1 (and
                # only 1) version higher than the local builds, but older.
                mtime = lambda version: os.stat(
                    os.path.join(self.appdir, 'versions', version)).st_mtime
                last_version = self.deployed_versions[-1]
                if (self.live_version != last_version and
                        mtime(self.live_version) > mtime(last_version)):
                    old_versions.add(last_version)

            for version in old_versions:
                shutil.rmtree(os.path.join(self.appdir, 'versions', version))

            used_virtualenvs = set()
            for version in self.deployed_versions:
                ve = os.path.join(self.appdir, 'versions', version,
                                  'virtualenv')
                with ignoring(errno.ENOENT):
                    used_virtualenvs.add(os.path.basename(os.readlink(ve)))

            ve_dir = os.path.join(self.appdir, 'virtualenvs')
            if os.path.isdir(ve_dir):
                for ve in os.listdir(ve_dir):
                    if ve not in used_virtualenvs:
                        shutil.rmtree(os.path.join(ve_dir, ve))
コード例 #3
0
    def prepare_logfiles(self):
        path = self.config.get(self.app, {}).get('path', {})
        logs = [path.get('log'), path.get('celery_log')]

        for logfile in logs:
            if not logfile:
                continue
            with ignoring(errno.EEXIST):
                os.mkdir(os.path.dirname(logfile))
            touch(logfile, self.log_user, self.log_group, 0640)
コード例 #4
0
ファイル: repository.py プロジェクト: yola/yodeploy
    def delete(self, path, metadata=False):
        """Delete a file.

        If metadata is True, this file has metadata that should be removed too.
        """
        fn = os.path.join(self.root, path)
        try:
            os.unlink(fn)
        except OSError as e:
            if e.errno == errno.ENOENT:
                raise KeyError(e)
            raise
        if metadata:
            with ignoring(errno.ENOENT):
                os.unlink(fn + '.meta')
コード例 #5
0
ファイル: repository.py プロジェクト: yola/yodeploy
    def list(self, path=None, files=False, dirs=True):
        """List the contents of path.

        Files will be listed when files is True.
        Directories will be listed when dirs is True.
        """
        if path:
            directory = os.path.join(self.root, path)
        else:
            directory = self.root
        predicates = []
        if files:
            predicates.append(os.path.isfile)
        if dirs:
            predicates.append(os.path.isdir)

        with ignoring(errno.ENOENT):
            for filename in os.listdir(directory):
                pathname = os.path.join(directory, filename)
                if any(predicate(pathname) for predicate in predicates):
                    yield filename
コード例 #6
0
ファイル: helpers.py プロジェクト: yola/yodeploy
def rm(path):
    with ignoring(errno.ENOENT):
        os.remove(path)
コード例 #7
0
ファイル: helpers.py プロジェクト: yola/yodeploy
def rmdir(path):
    with ignoring(errno.ENOENT):
        shutil.rmtree(path)