hadoop-tools 0.4 → 0.4.0.1
raw patch · 2 files changed
+84/−4 lines, 2 files
Files
- hadoop-tools.cabal +27/−4
- src/Glob.hs +57/−0
hadoop-tools.cabal view
@@ -1,7 +1,29 @@ name: hadoop-tools-version: 0.4-synopsis: Fast command line tools for working with Hadoop.-description: Fast command line tools for working with Hadoop.+version: 0.4.0.1++synopsis:+ Fast command line tools for working with Hadoop.++description:+ hh - Blazing fast interaction with HDFS+ .+ Currently we only support v7 of the RPC protocol (< CDH5).+ .+ Support for v9 (>= CDH5) is coming soon.+ .+ > hh cat - Print the contents of a file to stdout+ > hh cd - Change working directory+ > hh chmod - Change permissions+ > hh du - Show the amount of space used by file or directory+ > hh find - Recursively search a directory tree+ > hh get - Get a file+ > hh ls - List the contents of a directory+ > hh mkdir - Create a directory in the specified location+ > hh pwd - Print working directory+ > hh rm - Delete a file or directory+ > hh mv - Rename a file or directory+ > hh version - Show version information+ homepage: http://github.com/jystic/hadoop-tools license: Apache-2.0 license-file: LICENSE@@ -21,6 +43,7 @@ ghc-prof-options: -auto-all -caf-all other-modules:+ Glob Paths_hadoop_tools build-depends:@@ -31,7 +54,7 @@ , configurator >= 0.3 , exceptions >= 0.6 , filepath >= 1.3- , hadoop-rpc >= 0.1+ , hadoop-rpc >= 0.1.1.1 , old-locale >= 1.0 , optparse-applicative >= 0.10 , protobuf >= 0.2.0.4
+ src/Glob.hs view
@@ -0,0 +1,57 @@+{-# LANGUAGE OverloadedStrings #-}++module Glob+ ( Glob+ , compile+ , matches+ ) where++------------------------------------------------------------------------++import Control.Applicative ((<$>))+import Data.ByteString (ByteString)+import qualified Data.ByteString.Char8 as B+import Data.Monoid ((<>))+import System.IO.Unsafe (unsafeDupablePerformIO)+import qualified Text.Regex.PCRE.ByteString as Regex++------------------------------------------------------------------------++newtype Glob = Glob { unGlob :: Regex.Regex }++compile :: ByteString -> IO Glob+compile = (glob <$>) . Regex.compile Regex.compBlank Regex.execBlank . globToRegex+ where+ glob (Left (_, str)) = error str+ glob (Right regex) = Glob regex++matches :: Glob -> ByteString -> Bool+matches g = fromResult . unsafeDupablePerformIO . Regex.execute (unGlob g)+ where+ fromResult (Right (Just _)) = True+ fromResult _ = False++------------------------------------------------------------------------+-- Stolen from Real World Haskell++globToRegex :: ByteString -> ByteString+globToRegex bs = B.pack ("^" <> globToRegex' (B.unpack bs) <> "$")++globToRegex' :: String -> String+globToRegex' "" = ""+globToRegex' ('*':cs) = ".*" ++ globToRegex' cs+globToRegex' ('?':cs) = '.' : globToRegex' cs+globToRegex' ('[':'!':c:cs) = "[^" ++ c : charClass cs+globToRegex' ('[':c:cs) = '[' : c : charClass cs+globToRegex' ('[':_) = error "unterminated character class"+globToRegex' (c:cs) = escape c ++ globToRegex' cs++escape :: Char -> String+escape c | c `elem` regexChars = '\\' : [c]+ | otherwise = [c]+ where regexChars = "\\+()^$.{}]|"++charClass :: String -> String+charClass (']':cs) = ']' : globToRegex' cs+charClass (c:cs) = c : charClass cs+charClass [] = error "unterminated character class"