def apply(self, where): name = os.path.join(where, self.name) if self.action_kind == self.ADDED: if self.isdir: os.makedirs(name) else: dirname = os.path.dirname(name) if not os.path.exists(dirname): os.makedirs(dirname) f = file(name, 'w') if self.contents is not None: f.write(self.contents) f.close() elif self.action_kind == self.DELETED: if os.path.exists(name): if self.isdir: rmtree(name) else: os.unlink(name) elif self.action_kind == self.RENAMED: old_name = os.path.join(where, self.old_name) if os.path.exists(old_name): os.rename(old_name, name) elif self.action_kind == self.UPDATED: if self.contents is not None: f = file(name, 'w') f.write(self.contents) else: # update timestamp f = file(name, 'w+') f.close() else: raise TailorBug("Unknown ChangesetEntry.action_kind: %s" % str(self.action_kind))
def _checkoutUpstreamRevision(self, revision): if revision == 'INITIAL': cset = self.changesets[0] self.rev_offset = cset.revision - 1 self._applyChangeset(cset) return cset else: raise TailorBug("Don't know what to do!")
def _applyChangeset(self, changeset): """ Do the actual work of applying the changeset to the working copy. Subclasses should reimplement this method performing the necessary steps to *merge* given `changeset`, returning a list with the conflicts, if any. """ raise TailorBug("%s should override this method!" % self.__class__)
def _getUpstreamChangesets(self, sincerev): """ Query the upstream repository about what happened on the sources since last sync, returning a sequence of Changesets instances. This method must be overridden by subclasses. """ raise TailorBug("%s should override this method!" % self.__class__)
def _commit(self, date, author, patchname, changelog=None, entries=None, tags=[], isinitialcommit=False): """ Commit the changeset. """ raise TailorBug("%s should override this method!" % self.__class__)
def _checkoutUpstreamRevision(self, revision): """ Concretely do the checkout of the upstream revision. """ raise TailorBug("%s should override this method!" % self.__class__)
def _renamePathname(self, oldname, newname): """ Rename a filesystem object to some other name/location. """ raise TailorBug("%s should override this method!" % self.__class__)
def _removePathnames(self, names): """ Remove some filesystem object. """ raise TailorBug("%s should override this method!" % self.__class__)
def _addPathnames(self, names): """ Add some new filesystem objects. """ raise TailorBug("%s should override this method!" % self.__class__)
def _set_date(self, date): if date and date.tzinfo is None: raise TailorBug("Changeset dates must have a timezone!") self.__date = date
def _get_changesets(self): if not self.__changesets: raise TailorBug("Attempted to use empty MockWorkingDir!") return self.__changesets