X-Git-Url: https://git.decadent.org.uk/gitweb/?a=blobdiff_plain;f=daklib%2Fholding.py;h=221a25775a2832bcbea206ad18ffb7e9700687c3;hb=27e00376e81d1c37ff327ee0d39670b266418869;hp=d77eecde10d1bcdb61d4a9be8d35febd54b3d772;hpb=1359e943ab10977306602036675b22da89e9a964;p=dak.git diff --git a/daklib/holding.py b/daklib/holding.py old mode 100755 new mode 100644 index d77eecde..221a2577 --- a/daklib/holding.py +++ b/daklib/holding.py @@ -28,20 +28,30 @@ Simple singleton class for storing info about Holding directory import os from errno import ENOENT, EEXIST, EACCES +import shutil -from singleton import Singleton from config import Config from utils import fubar ############################################################################### -class Holding(Singleton): +class Holding(object): + __shared_state = {} + def __init__(self, *args, **kwargs): - super(Holding, self).__init__(*args, **kwargs) + self.__dict__ = self.__shared_state - def _startup(self): - self.in_holding = {} - self.holding_dir = Config()["Dir::Queue::Holding"] + if not getattr(self, 'initialised', False): + self.initialised = True + + self.in_holding = {} + self.holding_dir = Config()["Dir::Holding"] + # ftptrainees haven't access to holding, use a temp directory instead + if not os.access(self.holding_dir, os.W_OK): + self.holding_dir = Config()["Dir::TempPath"] + + def chdir_to_holding(self): + os.chdir(self.holding_dir) def copy_to_holding(self, filename): base_filename = os.path.basename(filename) @@ -50,7 +60,7 @@ class Holding(Singleton): try: fd = os.open(dest, os.O_RDWR | os.O_CREAT | os.O_EXCL, 0640) os.close(fd) - except OSError, e: + except OSError as e: # Shouldn't happen, but will if, for example, someone lists a # file twice in the .changes. if e.errno == EEXIST: @@ -58,7 +68,7 @@ class Holding(Singleton): try: shutil.copy(filename, dest) - except IOError, e: + except IOError as e: # In either case (ENOENT or EACCES) we want to remove the # O_CREAT | O_EXCLed ghost file, so add the file to the list # of 'in holding' even if it's not the real file. @@ -74,7 +84,7 @@ class Holding(Singleton): return None - def clean(self, filename): + def clean(self): cwd = os.getcwd() os.chdir(self.holding_dir) for f in self.in_holding.keys():