packages feed

adblock2privoxy 1.3.0 → 1.3.1

raw patch · 4 files changed

+125/−6 lines, 4 files

Files

adblock2privoxy.cabal view
@@ -1,5 +1,5 @@ name:                adblock2privoxy-version:             1.3.0+version:             1.3.1 cabal-version:       >= 1.10 build-type:          Simple tested-with:         @@ -86,6 +86,7 @@                    PatternConverter,                    PolicyTree,                    PopupBlocker,+                   ProgramOptions,                    SourceInfo,                    Statistics,                    Task,@@ -97,4 +98,4 @@   type:      git   location:  ​http://projects.zubr.me/adblock2privoxy.git   subdir:    adblock2privoxy-  tag:       1.3.0+  tag:       1.3.1
distribution/rpmbuild/SPECS/adblock2privoxy.spec view
@@ -1,11 +1,11 @@ Name:    adblock2privoxy-Version: 1.3.0+Version: 1.3.1 Release: 1%{?dist} Summary: Convert adblock config files to privoxy format  License: GPL-3 URL:     https://projects.zubr.me/wiki/adblock2privoxy-Source0: http://hackage.haskell.org/package/adblock2privoxy-1.3.0/adblock2privoxy-1.3.0.tar.gz+Source0: http://hackage.haskell.org/package/adblock2privoxy-1.3.1/adblock2privoxy-1.3.1.tar.gz Vendor:  Alexey Zubritskiy <adblock2privoxy@zubr.me> Group:   Web @@ -67,5 +67,5 @@   %changelog-* Sun Jan 04 2015 Alexey Zubritskiy <adblock2privoxy@zubr.me> - 1.3.0+* Mon Jan 05 2015 Alexey Zubritskiy <adblock2privoxy@zubr.me> - 1.3.1 - Rpm release for new version (generated from cabal file)
man/man1/adblock2privoxy.1 view
@@ -1,4 +1,4 @@-.TH "ADBLOCK2PRIVOXY" "1" "2015\-01\-04" "adblock2privoxy 1.3.0" "General Commands Manual"+.TH "ADBLOCK2PRIVOXY" "1" "2015\-01\-05" "adblock2privoxy 1.3.1" "General Commands Manual" .SH ADBLOCK2PRIVOXY .PP \f[B]Convert adblock config files to privoxy format\f[]
+ src/ProgramOptions.hs view
@@ -0,0 +1,118 @@+module ProgramOptions+(+Options(..),+fillFromLog,+parseOptions,+logOptions,+writeError,+versionText+) where+import Control.Monad.State+import Control.Applicative hiding (many)+import Text.ParserCombinators.Parsec hiding ((<|>),State,Line)+import System.Console.GetOpt+import System.FilePath+import Paths_adblock2privoxy (version)+import Data.Version (showVersion)+++data Options = Options+     { _showVersion :: Bool+     , _privoxyDir  :: FilePath+     , _webDir      :: FilePath+     , _taskFile    :: FilePath+     , _cssDomain   :: String +     , _forced      :: Bool+     }++options :: [OptDescr (Options -> Options)]+options =+     [ Option "v" ["version"]+         (NoArg (\ opts -> opts { _showVersion = True }))+         "Show version number"+     , Option "p"   ["privoxyDir"]+         (ReqArg (\ f opts -> opts { _privoxyDir = f })+                 "PATH")+         "Privoxy config output path"+     , Option "w"   ["webDir"]+         (ReqArg (\ f opts -> opts { _webDir = f })+                 "PATH")+         "Css files output path (optional, privoxyDir is used by default)"+     , Option "d"   ["domainCSS"]+         (ReqArg (\ d opts -> opts { _cssDomain = d })+                 "DOMAIN")+         "Domain of CSS web server (required for Element Hide functionality)"+     , Option "t"   ["taskFile"]+         (ReqArg (\ f opts -> opts { _taskFile = f })+                 "PATH")+         "Path to task file containing urls to process and options. privoxyDir, webDir and domainCSS values are taken from this file if not specified explicitly"+     , Option "f" ["forced"]+         (NoArg (\ opts -> opts { _forced = True }))+         "Run even if no sources are expired"+     ]++parseOptions :: [String] -> IO (Options, [String])+parseOptions argv = +   case getOpt Permute options argv of+      (opts,nonOpts,[]  ) -> +                case foldl (flip id) emptyOptions opts of+                        Options False "" _ "" _ _ -> writeError "Privoxy dir or task file should be specified.\n"+                        opts'@Options{_showVersion = True} -> return (opts', nonOpts)+                        opts' -> return (setDefaults opts', nonOpts)+      (_,_,errs) -> writeError $ concat errs+   where+        setDefaults opts@(Options _ (privoxyDir@(_:_)) "" _ _ _) = setDefaults opts{ _webDir = privoxyDir }+        setDefaults opts@(Options _ privoxyDir _ "" _ _) = setDefaults opts{ _taskFile = privoxyDir </> "ab2p.task" }+        setDefaults opts = opts  ++versionText :: String +versionText = "adblock2privoxy version " ++ showVersion version++writeError :: String -> IO a+writeError msg = ioError $ userError $ msg ++ "\n" ++ usageInfo header options+        where         +        header = versionText +++                "\nSee home page for more details and updates: http://projects.zubr.me/wiki/adblock2privoxy\n" +++                "Usage: adblock2privoxy [OPTION...] [URL...]"+++logOptions :: Options -> [String] +logOptions options' = [+        startMark,+        "Privoxy path: " ++ _privoxyDir options',+        "Web path: " ++ _webDir options',+        "CSS web server domain: " ++ _cssDomain options',+        endMark,+        ""]++startMark :: String+startMark = "----- options -----"++endMark :: String+endMark = "------- end ------"++emptyOptions :: Options+emptyOptions = Options False "" "" "" "" False++        +fillFromLog :: Options -> [String] -> Options+fillFromLog existing lns = execState (sequence $ parseLogOptions <$> lns') existing+   where +   lns' = filter (not.null) $ takeWhile (/= endMark).dropWhile (/= startMark) $ lns++parseLogOptions :: String -> State Options ()+parseLogOptions text = do+    info <- get+    let +        ifEmpty getter x = +                let oldValue = getter info in+                if null oldValue then x else oldValue +        privoxyPathParser = (\x -> info{_privoxyDir = ifEmpty _privoxyDir x}) <$> (string "Privoxy path: " *> many1 anyChar)+        webPathParser = (\x -> info{_webDir = ifEmpty _webDir x}) <$> (string "Web path: " *> many1 anyChar)+        cssDomainParser = (\x -> info{_cssDomain = ifEmpty _cssDomain x}) <$> (string "CSS web server domain: " *> many1 anyChar)+        stringParser = skipMany (char ' ') *> +            (try privoxyPathParser <|> try webPathParser <|> cssDomainParser)+    case parse stringParser "" text of+        Left _ -> return ()+        Right info' -> put info' +