packages feed

cabal-uninstall (empty) → 0.1

raw patch · 4 files changed

+133/−0 lines, 4 filesdep +basedep +directorydep +filepathsetup-changed

Dependencies added: base, directory, filepath, process

Files

+ LICENSE view
@@ -0,0 +1,31 @@+Copyright (c) 2012, Monoid - Development and Consulting - Jan Christiansen++All rights reserved.++Redistribution and use in source and binary forms, with or without+modification, are permitted provided that the following conditions are met:++* Redistributions of source code must retain the above copyright+notice, this list of conditions and the following disclaimer.++* Redistributions in binary form must reproduce the above+copyright notice, this list of conditions and the following+disclaimer in the documentation and/or other materials provided+with the distribution.++* Neither the name of Monoid - Development and Consulting - +Jan Christiansen nor the names of other+contributors may be used to endorse or promote products derived+from this software without specific prior written permission.++THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ Setup.hs view
@@ -0,0 +1,3 @@+import Distribution.Simple++main = defaultMain
+ cabal-uninstall.cabal view
@@ -0,0 +1,25 @@+name:                     cabal-uninstall+version:                  0.1+cabal-version:            >= 1.6+stability:                alpha+description:              Very simple script to delete a cabal package.+synopsis:                 Uninstall cabal packages+license:                  BSD3+license-file:             LICENSE+author:                   Jan Christiansen+maintainer:               Jan Christiansen <info@monoid-it.de>+category:                 Distribution+build-type:		  Simple+bug-reports:              https://github.com/plancalculus/cabal-uninstall/issues+source-repository head+  type:      git+  location:  https://github.com/plancalculus/cabal-uninstall.git++executable cabal-uninstall+  main-is:                  cabal-uninstall.hs+  ghc-options:              -Wall+  build-depends:+    base >= 4 && < 5,+    filepath,+    directory,+    process
+ cabal-uninstall.hs view
@@ -0,0 +1,74 @@+module Main where+++import System.Environment (getArgs)+import System.Process (system, runInteractiveCommand)+import System.Exit (ExitCode(..))+import System.IO (hGetContents, hFlush, stdout)+import System.Directory (doesDirectoryExist, removeDirectoryRecursive)+import System.FilePath (takeDirectory, dropTrailingPathSeparator)+++main :: IO ()+main = do+  input <- getArgs+  case input of+       package:args -> do+         let useForce = parseForceArg args+         res <- directoryOfPackage package+         case (res, useForce) of+              (Left err        , _         ) -> putStr err+              (_               , Nothing   ) -> putStrLn usageInfo+              (Right packageDir, Just force) -> do+                exitcode <- unregisterPackage package force+                case exitcode of+                     ExitFailure _ -> return ()+                     ExitSuccess -> do+                       b <- doesDirectoryExist packageDir+                       if b then removePackageDirectory packageDir+                            else putStrLn "package directory already deleted"+       _ -> putStrLn usageInfo++usageInfo :: String+usageInfo =+  "usage: cabal-uninstall <package-name> [--force]\n\+  \use sudo if the package is installed globally"++internalErrorInfo :: String+internalErrorInfo =+  "internal error: please contact Jan Christiansen (christiansen@monoid-it.de)"++parseForceArg :: [String] -> Maybe Bool+parseForceArg []          = Just False+parseForceArg ["--force"] = Just True+parseForceArg _           = Nothing++directoryOfPackage :: String -> IO (Either String FilePath)+directoryOfPackage package = do+  let command = "ghc-pkg field " ++ package ++ " library-dirs"+  (_, hout, herr, _) <- runInteractiveCommand command+  result <- hGetContents hout+  case result of+       [] -> hGetContents herr >>= return . Left+       _  -> return (packageDir (words result))+ where+  packageDir ["library-dirs:", libDir] =+    Right (takeDirectory (dropTrailingPathSeparator libDir))+  packageDir _ = Left internalErrorInfo++removePackageDirectory :: FilePath -> IO ()+removePackageDirectory packageDir = do+  putStr ("delete library directory " ++ packageDir ++ "? (yes/no)")+  hFlush stdout+  choice <- getLine+  case choice of+       "yes" -> removeDirectoryRecursive packageDir+       _     -> return ()++unregisterPackage :: String -> Bool -> IO ExitCode+unregisterPackage package force = do+  putStrLn "unregistering package"+  system ("ghc-pkg unregister " ++ useForce force ++ package)+ where+  useForce True  = "--force "+  useForce False = ""