# HG changeset patch # User Bernhard Herzog # Date 1214249181 0 # Node ID 06af36f915f29a8c16c0e1999ed144c3c617702c # Parent c0ea6cbb0fd26f9e78f08bf8240ebefe136c8101 Move the filenameproperty factory from treepkg/packager.py to treepkg/util.py diff -r c0ea6cbb0fd2 -r 06af36f915f2 treepkg/packager.py --- a/treepkg/packager.py Mon Jun 23 16:12:01 2008 +0000 +++ b/treepkg/packager.py Mon Jun 23 19:26:21 2008 +0000 @@ -23,16 +23,6 @@ from cmdexpand import cmdexpand from builder import PBuilder -def _filenameproperty(filename, dir_attr="base_dir"): - """Create a property for a directory or filename. - If the filename is relative it is interpreted as relative to the - value of the attribute of self named by dir_attr which defaults to - 'base_dir'. - """ - def get(self): - return os.path.join(getattr(self, dir_attr), filename) - return property(get) - def _fromparent(attr): """Creates a property that delegates its value to self.parent.""" def get(self): @@ -224,11 +214,11 @@ self.status = status.RevisionStatus(os.path.join(self.base_dir, "status")) - log_dir = _filenameproperty("log") - work_dir = _filenameproperty("work") - binary_dir = _filenameproperty("binary") - src_dir = _filenameproperty("src") - build_log = _filenameproperty("build_log.txt", dir_attr="log_dir") + log_dir = util.filenameproperty("log") + work_dir = util.filenameproperty("work") + binary_dir = util.filenameproperty("binary") + src_dir = util.filenameproperty("src") + build_log = util.filenameproperty("build_log.txt", dir_attr="log_dir") def find_dsc_file(self): for filename in os.listdir(self.src_dir): @@ -321,9 +311,9 @@ self.pkg_dir_regex \ = re.compile(r"(?P[0-9]+)-(?P[0-9]+)$") - checkout_dir = _filenameproperty("checkout") - debian_dir = _filenameproperty("debian") - pkg_dir = _filenameproperty("pkg") + checkout_dir = util.filenameproperty("checkout") + debian_dir = util.filenameproperty("debian") + pkg_dir = util.filenameproperty("pkg") def init_treepkg(self): print "Initializing", self.name diff -r c0ea6cbb0fd2 -r 06af36f915f2 treepkg/util.py --- a/treepkg/util.py Mon Jun 23 16:12:01 2008 +0000 +++ b/treepkg/util.py Mon Jun 23 19:26:21 2008 +0000 @@ -140,3 +140,14 @@ f.write(modified) f.close() return modified != contents + + +def filenameproperty(filename, dir_attr="base_dir"): + """Create a property for a directory or filename. + If the filename is relative it is interpreted as relative to the + value of the attribute of self named by dir_attr which defaults to + 'base_dir'. + """ + def get(self): + return os.path.join(getattr(self, dir_attr), filename) + return property(get)