Commit 20d2bc5b authored by Michael Hanus 's avatar Michael Hanus

Code refactoring, show versions in cpm list

parent e783cd1f
......@@ -52,7 +52,8 @@
\begin{abstract}
This document describes the Curry package manager (CPM), a tool to
distribute and install Curry libraries.
distribute and install Curry libraries and manage version dependencies
between these libraries.
\end{abstract}
\section{Installing the Curry Package Manager}
......
......@@ -354,23 +354,31 @@ compiler o cfg repo gc = tryFindLocalPackageSpec "." |>=
unsetEnviron "CURRYPATH"
succeedIO ()
install :: InstallOptions -> Config -> Repository -> GlobalCache -> IO (ErrorLogger ())
install (InstallOptions Nothing Nothing _) cfg repo gc = tryFindLocalPackageSpec "." |>=
install :: InstallOptions -> Config -> Repository -> GlobalCache
-> IO (ErrorLogger ())
install (InstallOptions Nothing Nothing _) cfg repo gc =
tryFindLocalPackageSpec "." |>=
\specDir -> installLocalDependencies cfg repo gc specDir |> succeedIO ()
install (InstallOptions (Just pkg) Nothing pre) cfg repo gc = do
fileExists <- doesFileExist pkg
if fileExists
then installFromZip cfg pkg
else case findLatestVersion repo pkg pre of
Nothing -> failIO $ "Package '" ++ pkg ++ "' not found in package repository."
Nothing -> failIO $ "Package '" ++ pkg ++
"' not found in package repository."
Just p -> acquireAndInstallPackageWithDependencies cfg repo gc p
install (InstallOptions (Just pkg) (Just ver) _) cfg repo gc = case findVersion repo pkg ver of
Nothing -> failIO $ "Package '" ++ pkg ++ "-" ++ (showVersion ver) ++ "' not found in package repository."
install (InstallOptions (Just pkg) (Just ver) _) cfg repo gc =
case findVersion repo pkg ver of
Nothing -> failIO $ "Package '" ++ pkg ++ "-" ++ (showVersion ver) ++
"' not found in package repository."
Just p -> acquireAndInstallPackageWithDependencies cfg repo gc p
install (InstallOptions Nothing (Just _) _) _ _ _ = failIO "Must specify package name"
install (InstallOptions Nothing (Just _) _) _ _ _ =
failIO "Must specify package name"
uninstall :: UninstallOptions -> Config -> Repository -> GlobalCache -> IO (ErrorLogger ())
uninstall (UninstallOptions pkg ver) cfg repo gc = uninstallPackage cfg repo gc pkg ver
uninstall :: UninstallOptions -> Config -> Repository -> GlobalCache
-> IO (ErrorLogger ())
uninstall (UninstallOptions pkg ver) cfg repo gc =
uninstallPackage cfg repo gc pkg ver
tryFindVersion :: String -> Version -> Repository -> IO (ErrorLogger Package)
tryFindVersion pkg ver repo = case findVersion repo pkg ver of
......@@ -386,14 +394,16 @@ listAll :: ListOptions -> Config -> Repository -> IO (ErrorLogger ())
listAll (ListOptions lv) _ repo = putStr rendered >> succeedIO ()
where
results = listPackages repo
rendered = render (table columns [nameLen + 4, 76 - nameLen]) ++
rendered = render (table columns [nameLen + 4, 66 - nameLen, 10]) ++
"\nUse `cpm info PACKAGE' for more information about a package.\n"
header = [["Name", "Synopsis"], ["----", "--------"], [" ", " "]]
formatGroup pg = [name (head pg), synopsis (head pg) ++ showPkgVersions pg]
showPkgVersions pg =
if lv then " (" ++ intercalate ", " (map (showVersion . version) pg) ++ ")"
else ""
columns = header ++ map formatGroup results
header = [ ["Name", "Synopsis", "Version"]
, ["----", "--------", "-------"]
, [" ", " ", " "]]
formatPkg p = [name p, synopsis p, showVersion (version p)]
formatGroup pg =
if lv then map formatPkg pg
else [formatPkg (head pg)]
columns = header ++ concatMap formatGroup results
nameLen = foldl max 0 $ map (length . name) (concat results)
search :: SearchOptions -> Config -> Repository -> IO (ErrorLogger ())
......
......@@ -119,10 +119,12 @@ acquireAndInstallPackage cfg pkg = case (source pkg) of
--- Installs a package from the given package source to the global package
--- cache.
installFromSource :: Config -> Package -> PackageSource -> IO (ErrorLogger ())
installFromSource cfg pkg (Git url rev) = do
pkgDirExists <- doesDirectoryExist pkgDir
if pkgDirExists
then log Info $ "Package " ++ (packageId pkg) ++ " already installed, skipping"
then
log Info $ "Package " ++ packageId pkg ++ " already installed, skipping"
else do
c <- inDirectory (packageInstallDir cfg) $ system cloneCommand
if c == 0
......@@ -132,34 +134,42 @@ installFromSource cfg pkg (Git url rev) = do
Just (Ref ref) -> checkoutGitRef pkgDir ref
Just VersionAsTag -> let tag = "v" ++ (showVersion $ version pkg)
in checkoutGitRef pkgDir tag |>
log Info ("Package " ++ (packageId pkg) ++ " installed")
else failIO $ "Failed to clone repository from '" ++ url ++ "', return code " ++ (show c)
log Info ("Package " ++ (packageId pkg) ++
" installed")
else failIO $ "Failed to clone repository from '" ++ url ++
"', return code " ++ (show c)
where
pkgDir = (packageInstallDir cfg) </> (packageId pkg)
cloneCommand = "git clone " ++ (quote url) ++ " " ++ (quote $ packageId pkg)
installFromSource cfg pkg (FileSource zip) = do
absZip <- getAbsolutePath zip
pkgDirExists <- doesDirectoryExist pkgDir
if pkgDirExists
then log Info $ "Package " ++ (packageId pkg) ++ " already installed, skipping"
then
log Info $ "Package " ++ packageId pkg ++ " already installed, skipping"
else do
createDirectory pkgDir
c <- inTempDir $ system $ "unzip -qq -d " ++ (quote pkgDir) ++ " " ++ (quote absZip)
c <- inTempDir $ system $ "unzip -qq -d " ++ (quote pkgDir) ++
" " ++ (quote absZip)
if c == 0
then log Info $ "Installed " ++ (packageId pkg)
else failIO $ "Failed to unzip package " ++ (show c)
where
pkgDir = (packageInstallDir cfg) </> (packageId pkg)
installFromSource cfg pkg (Http url) = do
installFromSource cfg pkg (Http url) = do
c <- inTempDir $ system $ "curl -s -o package.zip " ++ (quote url)
if c == 0
then do
pkgDirExists <- doesDirectoryExist pkgDir
if pkgDirExists
then log Info $ "Package " ++ (packageId pkg) ++ " already installed, skipping"
then log Info $ "Package " ++ packageId pkg ++
" already installed, skipping"
else do
createDirectory pkgDir
c' <- inTempDir $ system $ "unzip -qq -d " ++ (quote pkgDir) ++ " package.zip"
c' <- inTempDir $ system $ "unzip -qq -d " ++ (quote pkgDir) ++
" package.zip"
if c' == 0
then do
c'' <- inTempDir $ system ("rm package.zip")
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment