packages feed

dnf-repo 0.5 → 0.5.1

raw patch · 6 files changed

+72/−36 lines, 6 filesdep +http-directory

Dependencies added: http-directory

Files

ChangeLog.md view
@@ -1,10 +1,21 @@ # dnf-repo releases +## 0.5.1 (2022-11-08)+- check if new copr or koji repo exists with http-directory+- remove initial/trailing / or : from reponames+- add --quiet option: limits output to dnf --quiet and permanent changes+- add --repourl to use a repo baseurl+- output state info to stderr+- expire: don't print action and tweak prompt+ ## 0.5 (2022-10-23) - support repo Glob patterns-- repo pattern now only matches one (first) repo by default (without glob)+- prefer shortest common prefix repo match if not glob - add --clear-expires command; expire commands now prompt - abort if no match for repopat action+- accumulate repostate unchanged warnings+- drop overspecific --disable/--enable-defaults+- more consistent output, particularly newlines - simple testsuite  ## 0.4 (2022-10-20)
README.md view
@@ -1,14 +1,14 @@ # dnf-repo  A wrapper of the dnf package manager for fine control of-enabled/disabled yum repos (eg coprs).+enabled/disabled yum repos (eg Copr repos).  dnf is the package manager used by Fedora Linux and also modern RHEL.  DNF is a bit slow at handling multiple repos because it attempts to refresh the cached repodata frequently. So it can be advantageous to disable smaller repos by default and only enable them as needed-(eg periodically).+periodically.  This tool can temporarily enable/disable repo(s) selected by substring(s). Changes to repos' enabled states can be saved too.@@ -22,25 +22,27 @@  ```shellsession $ dnf-repo --version-0.5+0.5.1 $ dnf-repo --help DNF wrapper repo tool -Usage: dnf-repo [--version] [-n|--dryrun] [-D|--debug] [-l|--list] [-s|--save]-                [(-w|--weak-deps) | (-W|--no-weak-deps)] [--exact]+Usage: dnf-repo [--version] [-n|--dryrun] [-q|--quiet] [-D|--debug] [-l|--list]+                [-s|--save] [(-w|--weak-deps) | (-W|--no-weak-deps)] [--exact]                 [(-d|--disable REPOPAT) | (-e|--enable REPOPAT) |                   (-x|--expire REPOPAT) | (-X|--clear-expires) |                   (-E|--delete-repofile REPOPAT) | (-t|--enable-testing) |                   (-T|--disable-testing) | (-m|--enable-modular) |                   (-M|--disable-modular) | --enable-debuginfo |                   --disable-debuginfo | --enable-source | --disable-source |-                  (-c|--add-copr COPR) | (-k|--add-koji REPO)] [DNFARGS]+                  (-c|--add-copr COPR) | (-k|--add-koji REPO) |+                  (-u|--repourl URL)] [DNFARGS]   see https://github.com/juhp/dnf-repo#readme  Available options:   -h,--help                Show this help text   --version                Show version   -n,--dryrun              Dry run+  -q,--quiet               Suppress necessary output   -D,--debug               Debug output   -l,--list                List all repos   -s,--save                Save the repo enable/disable state@@ -64,6 +66,7 @@   -c,--add-copr COPR       Create repo file for copr repo   -k,--add-koji REPO       Create repo file for koji repo (f37-build, rawhide,                            epel9-build, etc)+  -u,--repourl URL         temporary repo from a baseurl ```  ## Usage examples@@ -151,8 +154,8 @@ Use {cabal,stack,cabal-rpm} install.  ## Contributing-The source repository is https://github.com/juhp/dnf-repo/- dnf-repo is currently distributed under a BSD license. -Contributions including suggestions for improvement are welcome.+The source repository is https://github.com/juhp/dnf-repo/++Contributions including reports and suggestions for improvement are welcome.
dnf-repo.cabal view
@@ -1,5 +1,5 @@ name:                dnf-repo-version:             0.5+version:             0.5.1 synopsis:            DNF wrapper tool to control repos description:         A command-line wrapper of the dnf package manager to@@ -42,6 +42,7 @@                        extra,                        filepath,                        Glob,+                       http-directory >= 0.1.9,                        simple-cmd,                        simple-cmd-args >= 0.1.8   default-language:    Haskell2010
src/ExpireRepos.hs view
@@ -15,7 +15,7 @@ expireRepo dryrun debug repo = do   old <- read <$> readFile expiredFile :: IO [String]   let expired = nub $ old ++ [repo]-  ok <- yesno $ "Expire cache of " ++ repo+  ok <- yesno $ "Mark '" ++ repo ++ "' cache expired"   when ok $ do     doSudo dryrun debug "sed" ["-i", "-e",                                "s/" ++ renderShow old ++ "/" ++ renderShow expired ++ "/",
src/Main.hs view
@@ -7,6 +7,7 @@ import Control.Monad.Extra import Data.Bifunctor (bimap) import Data.List.Extra+import Network.HTTP.Directory (httpExists', (+/+)) import SimpleCmd import SimpleCmdArgs import System.Directory@@ -27,6 +28,7 @@     "see https://github.com/juhp/dnf-repo#readme" $     runMain     <$> switchWith 'n' "dryrun" "Dry run"+    <*> switchWith 'q' "quiet" "Suppress necessary output"     <*> switchWith 'D' "debug" "Debug output"     <*> switchWith 'l' "list" "List all repos"     <*> switchWith 's' "save" "Save the repo enable/disable state"@@ -37,7 +39,10 @@     <*> many (strArg "DNFARGS")   where     repoOptionWith =-      (fmap . fmap . fmap . fmap) (replace "/" ":") . strOptionWith+      (fmap . fmap . fmap . fmap) cleanupReponame . strOptionWith+      where+        cleanupReponame =+          dropWhileEnd (== ':') . replace "/" ":" . dropWhile (== '/')      modeOpt =       DisableRepo <$> repoOptionWith 'd' "disable" "REPOPAT" "Disable repos" <|>@@ -54,7 +59,8 @@       flagLongWith' (Specific EnableSource) "enable-source" "Enable source repos" <|>       flagLongWith' (Specific DisableSource) "disable-source" "Disable source repos" <|>       AddCopr <$> repoOptionWith 'c' "add-copr" "COPR" "Create repo file for copr repo" <|>-      AddKoji <$> repoOptionWith 'k' "add-koji" "REPO" "Create repo file for koji repo (f37-build, rawhide, epel9-build, etc)"+      AddKoji <$> repoOptionWith 'k' "add-koji" "REPO" "Create repo file for koji repo (f37-build, rawhide, epel9-build, etc)" <|>+      RepoURL <$> strOptionWith 'u' "repourl" "URL" "Use temporary repo from a baseurl"  coprRepoTemplate :: FilePath coprRepoTemplate = "copr.fedorainfracloud.orgCOLONOWNERCOLONREPO.repo"@@ -66,9 +72,9 @@ -- FIXME --enable-all-coprs (for updating etc) -- FIXME confirm repos if many -- FIXME --disable-non-cores (modular,testing,cisco, etc)-runMain :: Bool -> Bool -> Bool -> Bool -> Maybe Bool -> Bool -> [Mode]+runMain :: Bool -> Bool -> Bool -> Bool -> Bool -> Maybe Bool -> Bool -> [Mode]         -> [String] -> IO ()-runMain dryrun debug listrepos save mweakdeps exact modes args = do+runMain dryrun quiet debug listrepos save mweakdeps exact modes args = do   hSetBuffering stdout NoBuffering   withCurrentDirectory "/etc/yum.repos.d" $ do     forM_ modes $@@ -81,10 +87,10 @@     nameStates <- sort <$> concatMapM readRepos repofiles     let actions = selectRepo exact nameStates modes         moreoutput = not (null args) || null actions || listrepos-    unless (null actions) $ do+    unless (null actions || quiet) $ do       mapM_ (printAction save) actions       when moreoutput $-        putStrLn ""+        warning ""     outputs <-       forM actions $       \case@@ -98,8 +104,8 @@           deleteRepo dryrun debug repofile           return True         _ -> return False-    when (or outputs && (save || moreoutput)) $-      putStrLn ""+    when (or outputs && (save || moreoutput) && not quiet) $+      warning ""     when save $ do       if null actions         then putStrLn "no changes to save"@@ -116,15 +122,17 @@       sleep 1       let repoargs = concatMap changeRepo actions           weakdeps = maybe [] (\w -> ["--setopt=install_weak_deps=" ++ show w]) mweakdeps-        in doSudo dryrun debug "dnf" $ repoargs ++ weakdeps ++ args+          quietopt = if quiet then ("-q" :) else id+        in doSudo dryrun debug "dnf" $ quietopt repoargs ++ weakdeps ++ args  -- FIXME pull non-fedora copr repo file--- FIXME delete created copr repo file if repo doesn't exist addCoprRepo :: Bool -> Bool -> String -> IO () addCoprRepo dryrun debug repo = do   case stripInfix ":" repo of     Nothing -> error' $ "invalid copr: " ++ repo     Just (copr_owner,copr_repo) -> do+      let repourl = "https://download.copr.fedorainfracloud.org/results" +/+ copr_owner +/+ copr_repo+      unlessM (httpExists' repourl) $ error' $ "no such copr repo: " ++ repourl       template <- getDataFileName coprRepoTemplate       repodef <- cmd "sed" ["-e", "s/@COPR_OWNER@/" ++ copr_owner ++ "/g", "-e", "s/@COPR_REPO@/" ++ copr_repo ++ "/g", template]       let repofile = ("_copr:" ++) $@@ -141,9 +149,10 @@         doSudo dryrun debug "cp" [tmpfile, repofile]         putStrLn "" --- FIXME check url exists! addKojiRepo :: Bool -> Bool -> String -> IO () addKojiRepo dryrun debug repo = do+  let repourl = "https://kojipkgs.fedoraproject.org/repos" +/+ repo +/+ "/latest/x86_64/"+  unlessM (httpExists' repourl) $ error' $ "no such koji repo: " ++ repourl   template <- getDataFileName kojiRepoTemplate   repodef <- cmd "sed" ["-e", "s/@REPO@/" ++ repo ++ "/g", template]   let repofile = replace "REPO" repo kojiRepoTemplate
src/YumRepoFile.hs view
@@ -14,15 +14,16 @@   ) where -import Data.List.Extra (isPrefixOf, isInfixOf, isSuffixOf, nub, sort, sortOn,-                        stripInfix, trim)+import Data.List.Extra (dropPrefix, dropSuffix,+                        isPrefixOf, isInfixOf, isSuffixOf, nub,+                        replace, sort, sortOn, stripInfix, trim) import Data.Maybe (mapMaybe) import SimpleCmd (error', warning) import System.FilePath.Glob (compile, match)  type RepoState = (String,(Bool,FilePath)) -data Mode = AddCopr String | AddKoji String+data Mode = AddCopr String | AddKoji String | RepoURL String           | EnableRepo String | DisableRepo String           | ExpireRepo String | ClearExpires           | DeleteRepo String@@ -32,6 +33,7 @@ modePattern :: Mode -> Maybe String modePattern (AddCopr c) = Just c modePattern (AddKoji k) = Just k+modePattern (RepoURL _) = Nothing modePattern (EnableRepo r) = Just r modePattern (DisableRepo r) = Just r modePattern (ExpireRepo r) = Just r@@ -60,31 +62,32 @@                   | Expire String                   | UnExpire                   | Delete FilePath Bool+                  | BaseURL String   deriving (Eq,Ord,Show)  printAction :: Bool -> ChangeEnable -> IO () printAction save (Disable r s) =   if s-  then putStrLn $-       if save-       then "disable " ++ quote r-       else "with " ++ quote r ++ " disabled"+  then+    if save+    then putStrLn $ "disable " ++ quote r+    else warning $ "with " ++ quote r ++ " disabled"   else warning $ quote r ++ " already disabled" printAction save (Enable r s) =   if s-  then putStrLn $-       if save-       then "enable " ++ quote r-       else "with " ++ quote r ++ " enabled"+  then+    if save+    then putStrLn $ "enable " ++ quote r+    else warning $ "with " ++ quote r ++ " enabled"   else warning $ quote r ++ " already enabled"-printAction _ (Expire r) =-  putStrLn $ "expire " ++ quote r+printAction _ (Expire _) = return () printAction _ UnExpire =   putStrLn "unexpire:" printAction _ (Delete f s) =   if s   then putStrLn $ "delete " ++ quote f   else warning $ quote f ++ " deletion skipped"+printAction _ (BaseURL _) = return ()  quote :: String -> String quote s = '\'' : s ++ "'"@@ -95,10 +98,18 @@ maybeRepoName x@(Expire r) = Just (x, r) maybeRepoName UnExpire = Nothing maybeRepoName (Delete _ _) = Nothing+maybeRepoName (BaseURL _) = Nothing  changeRepo :: ChangeEnable -> [String] changeRepo (Disable r True) = ["--disablerepo", r] changeRepo (Enable r True) = ["--enablerepo", r]+changeRepo (BaseURL url) = ["--repofrompath", repoUrlName ++ "," ++ url]+  where+    repoUrlName = replace "/" ":" $+                  dropSuffix "/" $+                  dropPrefix "http://" $+                  dropPrefix "https://" url+ changeRepo _ = []  saveRepo :: ChangeEnable -> [String]@@ -161,6 +172,7 @@           maybeChange repo isSuffixOf (not enabled) (Enable name)         AddKoji repo ->           maybeChange repo isSuffixOf (not enabled) (Enable name)+        RepoURL url -> Just $ BaseURL url         EnableRepo pat ->           maybeChange pat matchesRepo (not enabled) (Enable name)         DisableRepo pat ->