Commits

Steve Losh committed 0bdb5a6

guts: Add the smash command, for when you *really* hate a package.

  • Participants
  • Parent commits 08ef03f

Comments (0)

Files changed (3)

File lib/gorilla/guts/cli.py

                 ui.error('%s is not installed!\n' % card.name)
                 continue
             
+            ui.write('Removing %s ...\n' % card.name)
+            
             removed = shelf.remove()
             
             if removed:
         ui.error('You must specify a package to remove!\n')
 
 def _handle_smash(ui, **opts):
-    pass
+    if opts['args']:
+        for name in opts['args']:
+            try:
+                card = Card(name)
+            except Card.DoesNotExist, exc:
+                ui.error('Unknown package: %s\n' % exc.name)
+                continue
+            
+            shelf = Shelf(card)
+            
+            if not shelf.present:
+                ui.error('%s is not present!\n' % card.name)
+                continue
+            
+            ui.write('Smashing %s ...\n' % card.name)
+            
+            if shelf.installed:
+                removed = shelf.remove()
+                
+                if not removed:
+                    ui.error('There was a problem smashing %s!\n' % card.name)
+            
+            smashed = shelf.smash()
+            
+            if smashed:
+                ui.write('Successfully smashed %s.\n' % card.name)
+            else:
+                ui.error('There was a problem smashing %s!\n' % card.name)
+    else:
+        ui.error('You must specify a package to smash!\n')
 
 def _handle_grab(ui, **opts):
     try:
         'help': 'search for packages',
         'usage': '%s search STRING [STRING ...]',
     },
+    'smash': {
+        'aliases': ['delete'],
+        'handler': _handle_smash,
+        'options': {},
+        'help': 'remove (and delete) a package',
+        'usage': '%s smash PACKAGE [PACKAGE ...]',
+    },
 }
 
 def main(ui, args):

File lib/gorilla/guts/repo.py

         self.command = ['hg', '-R', self.path]
     
     def clone(self):
-        command = self.command + ['clone', self.sources[0], '--noupdate']
+        command = ['hg', 'clone', self.sources[0], self.path, '--noupdate']
         
         rc = subprocess.call(command, shell=False, stdout=subprocess.PIPE)
         return rc == 0

File lib/gorilla/guts/shelf.py

-import os, re, subprocess
+import os, re, shutil, subprocess
 from gorilla.guts import util
 from gorilla.guts.catalog import Card
 from gorilla.guts.repo import MercurialRepo
         
         return True
     
+    def smash(self):
+        shutil.rmtree(self.path)
+        return True
+