+
+class Patch(StgitObject):
+ """Basic patch implementation
+ """
+ def __init__(self, name, series_dir, refs_dir):
+ self.__series_dir = series_dir
+ self.__name = name
+ self._set_dir(os.path.join(self.__series_dir, self.__name))
+ self.__refs_dir = refs_dir
+ self.__top_ref_file = os.path.join(self.__refs_dir, self.__name)
+ self.__log_ref_file = os.path.join(self.__refs_dir,
+ self.__name + '.log')
+
+ def create(self):
+ os.mkdir(self._dir())
+ self.create_empty_field('bottom')
+ self.create_empty_field('top')
+
+ def delete(self):
+ for f in os.listdir(self._dir()):
+ os.remove(os.path.join(self._dir(), f))
+ os.rmdir(self._dir())
+ os.remove(self.__top_ref_file)
+ if os.path.exists(self.__log_ref_file):
+ os.remove(self.__log_ref_file)
+
+ def get_name(self):
+ return self.__name
+
+ def rename(self, newname):
+ olddir = self._dir()
+ old_top_ref_file = self.__top_ref_file
+ old_log_ref_file = self.__log_ref_file
+ self.__name = newname
+ self._set_dir(os.path.join(self.__series_dir, self.__name))
+ self.__top_ref_file = os.path.join(self.__refs_dir, self.__name)
+ self.__log_ref_file = os.path.join(self.__refs_dir,
+ self.__name + '.log')
+
+ os.rename(olddir, self._dir())
+ os.rename(old_top_ref_file, self.__top_ref_file)
+ if os.path.exists(old_log_ref_file):
+ os.rename(old_log_ref_file, self.__log_ref_file)
+
+ def __update_top_ref(self, ref):
+ write_string(self.__top_ref_file, ref)
+
+ def __update_log_ref(self, ref):
+ write_string(self.__log_ref_file, ref)
+
+ def update_top_ref(self):
+ top = self.get_top()
+ if top:
+ self.__update_top_ref(top)
+