Пример #1
0
    def cleanup(self):
        """Remove downloaded files.

        Note: it is perfectly ok if subclasses decide to
              cache the downloaded data for some time.

        """
        if self._remote_files is None:
            return
        for filename in os.listdir(self.old_path):
            os.unlink(os.path.join(self.old_path, filename))
        os.rmdir(self.old_path)
        try:
            os.rmdir(wc_diff_mkdir(self.wc_path, ''))
        except OSError as e:
            if e.errno != errno.ENOTEMPTY:
                raise
Пример #2
0
    def cleanup(self):
        """Remove downloaded files.

        Note: it is perfectly ok if subclasses decide to
              cache the downloaded data for some time.

        """
        if self._remote_files is None:
            return
        for filename in os.listdir(self.old_path):
            os.unlink(os.path.join(self.old_path, filename))
        os.rmdir(self.old_path)
        try:
            os.rmdir(wc_diff_mkdir(self.wc_path, ''))
        except OSError as e:
            if e.errno != errno.ENOTEMPTY:
                raise
Пример #3
0
    def diff(self, diff, *filenames, **kwargs):
        """Initialize diff object.

        filenames are the working copy filenames which should
        be considered. If no filenames are specified all working
        copy files will be used.
        A ValueError is raised if a filename is not tracked.

        Keyword arguments:
        revision -- diff against the remote revision revision (default: '')

        """
        def consider_filenames(info, filenames):
            if set(filenames) == set(self.files()):
                return
            # only consider filenames
            remove = []
            for filename in info:
                if filename not in filenames:
                    remove.append(filename)
            for filename in remove:
                info.remove(filename)

        untracked = [f for f in filenames if self.status(f) == '?']
        if untracked:
            msg = ("diff not possible untracked files: %s" %
                   ', '.join(untracked))
            raise ValueError(msg)
        revision = kwargs.get('revision', '')
        if not filenames:
            filenames = self.files()
        diff.wc_path = self.path
        diff.revision_data = self._files.revision_data()
        if revision:
            spkg = SourcePackage(self.project, self.name)
            directory = spkg.list(rev=revision, apiurl=self.apiurl)
            info = self._calculate_updateinfo(remote_files=directory)
            consider_filenames(info, filenames)
            # swap added and deleted
            tmp = info.added
            info.added = info.deleted
            info.deleted = tmp
            # treat files with state 'A' as added
            local_added = [f for f in info.unchanged if self.status(f) == 'A']
            for filename in local_added:
                info.unchanged.remove(filename)
                info.added.append(filename)
            # check for missing files
            missing = [f for f in info if self.status(f) == '!']
            # treat files with state 'D' as deleted
            deleted = [f for f in info if self.status(f) == 'D']
            for filename in missing + deleted:
                info.remove(filename)
            info.conflicted.extend(missing)
            info.deleted.extend(deleted)
            diff._remote_files = directory
            srcmd5 = directory.get('srcmd5')
            diff.old_path = wc_diff_mkdir(self.path, srcmd5)
            diff.revision_data = {'rev': revision, 'srcmd5': srcmd5}
        else:
            info = self._calculate_commitinfo(*filenames)
            consider_filenames(info, filenames)
            skipped = [f for f in info.unchanged if self.status(f) == 'S']
            for filename in skipped:
                info.remove(filename)
            info.skipped = skipped
            diff.old_path = wc_pkg_data_filename(self.path, '')
        listnames = ('added', 'deleted', 'modified', 'unchanged', 'skipped')
        for listname in listnames:
            for filename in getattr(info, listname):
                diff.append(filename, listname)
        for filename in info.conflicted:
            if self.status(filename) == '!':
                diff.append(filename, 'missing')
            else:
                diff.append(filename, 'modified')
Пример #4
0
    def diff(self, diff, *filenames, **kwargs):
        """Initialize diff object.

        filenames are the working copy filenames which should
        be considered. If no filenames are specified all working
        copy files will be used.
        A ValueError is raised if a filename is not tracked.

        Keyword arguments:
        revision -- diff against the remote revision revision (default: '')

        """
        def consider_filenames(info, filenames):
            if set(filenames) == set(self.files()):
                return
            # only consider filenames
            remove = []
            for filename in info:
                if filename not in filenames:
                    remove.append(filename)
            for filename in remove:
                info.remove(filename)

        untracked = [f for f in filenames if self.status(f) == '?']
        if untracked:
            msg = ("diff not possible untracked files: %s"
                   % ', '.join(untracked))
            raise ValueError(msg)
        revision = kwargs.get('revision', '')
        if not filenames:
            filenames = self.files()
        diff.wc_path = self.path
        diff.revision_data = self._files.revision_data()
        if revision:
            spkg = SourcePackage(self.project, self.name)
            directory = spkg.list(rev=revision, apiurl=self.apiurl)
            info = self._calculate_updateinfo(remote_files=directory)
            consider_filenames(info, filenames)
            # swap added and deleted
            tmp = info.added
            info.added = info.deleted
            info.deleted = tmp
            # treat files with state 'A' as added
            local_added = [f for f in info.unchanged if self.status(f) == 'A']
            for filename in local_added:
                info.unchanged.remove(filename)
                info.added.append(filename)
            # check for missing files
            missing = [f for f in info if self.status(f) == '!']
            # treat files with state 'D' as deleted
            deleted = [f for f in info if self.status(f) == 'D']
            for filename in missing + deleted:
                info.remove(filename)
            info.conflicted.extend(missing)
            info.deleted.extend(deleted)
            diff._remote_files = directory
            srcmd5 = directory.get('srcmd5')
            diff.old_path = wc_diff_mkdir(self.path, srcmd5)
            diff.revision_data = {'rev': revision, 'srcmd5': srcmd5}
        else:
            info = self._calculate_commitinfo(*filenames)
            consider_filenames(info, filenames)
            skipped = [f for f in info.unchanged if self.status(f) == 'S']
            for filename in skipped:
                info.remove(filename)
            info.skipped = skipped
            diff.old_path = wc_pkg_data_filename(self.path, '')
        listnames = ('added', 'deleted', 'modified', 'unchanged', 'skipped')
        for listname in listnames:
            for filename in getattr(info, listname):
                diff.append(filename, listname)
        for filename in info.conflicted:
            if self.status(filename) == '!':
                diff.append(filename, 'missing')
            else:
                diff.append(filename, 'modified')