summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2012-10-13 10:06:45 +0100
committerLars Wirzenius <liw@liw.fi>2012-10-13 10:06:45 +0100
commit6bc2a04374e008ebae51aa0d9f09c2fa9d98af13 (patch)
tree4626647fb24a66f8b38ce61fbe9720fa2f74f04a
parent65cb8c2df6a8d29a9594872395e75cafd273eb32 (diff)
downloadcachedir-6bc2a04374e008ebae51aa0d9f09c2fa9d98af13.tar.gz
Implement tag, untag, find subcommands
-rwxr-xr-xcachedir30
1 files 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()