From 6bc2a04374e008ebae51aa0d9f09c2fa9d98af13 Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Sat, 13 Oct 2012 10:06:45 +0100 Subject: Implement tag, untag, find subcommands --- cachedir | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/cachedir b/cachedir index e534cac..1067d3d 100755 --- a/cachedir +++ b/cachedir @@ -16,6 +16,7 @@ import cliapp +import os __version__ = '0.0' @@ -23,7 +24,32 @@ __version__ = '0.0' class Cachedir(cliapp.Application): - pass - + _tag_name = 'CACHEDIR.TAG' + _tag = 'Signature: 8a477f597d28d172789f06886806bc55\n' + + def _join(self, dirname): + return os.path.join(dirname, self._tag_name) + + def cmd_tag(self, args): + '''Add cache tag to directories.''' + + for dirname in args: + with open(self._join(dirname), 'w') as f: + f.write(self._tag) + + def cmd_untag(self, args): + '''Remove cache tag from directories.''' + + for dirname in args: + os.remove(self._join(dirname)) + + def cmd_find(self, args): + '''Find cache directories under the given directories.''' + + for startdir in args: + for dirname, subdirs, filenames in os.walk(startdir): + if os.path.exists(self._join(dirname)): + self.output.write('%s\n' % dirname) + Cachedir(version=__version__).run() -- cgit v1.2.1