epub-tools 2.0.0 → 2.1.0
raw patch · 26 files changed
+149/−66 lines, 26 filesdep ~epub-metadatasetup-changed
Dependency ranges changed: epub-metadata
Files
- LICENSE +1/−1
- Setup.hs +1/−1
- epub-tools.cabal +4/−4
- resources/default.rules +11/−10
- resources/epubname-dsl-docs +9/−3
- src/EpubTools/EpubMeta/Display.hs +1/−1
- src/EpubTools/EpubMeta/Edit.hs +1/−1
- src/EpubTools/EpubMeta/Export.hs +1/−1
- src/EpubTools/EpubMeta/Import.hs +1/−1
- src/EpubTools/EpubMeta/Opts.hs +2/−2
- src/EpubTools/EpubMeta/Util.hs +1/−1
- src/EpubTools/EpubName/Format/Author.hs +1/−1
- src/EpubTools/EpubName/Format/Compile.hs +7/−3
- src/EpubTools/EpubName/Format/Format.hs +16/−4
- src/EpubTools/EpubName/Format/PubYear.hs +1/−1
- src/EpubTools/EpubName/Format/Util.hs +1/−1
- src/EpubTools/EpubName/Main.hs +1/−1
- src/EpubTools/EpubName/Opts.hs +2/−2
- src/EpubTools/EpubName/Util.hs +1/−1
- src/EpubTools/EpubZip/Opts.hs +2/−2
- src/EpubTools/epubmeta.hs +1/−1
- src/EpubTools/epubname.hs +1/−1
- src/EpubTools/epubzip.hs +6/−4
- testsuite/EpubTools/Test/EpubName/Format.hs +74/−16
- testsuite/EpubTools/Test/EpubName/PubYear.hs +1/−1
- testsuite/EpubTools/test-epubname.hs +1/−1
LICENSE view
@@ -1,4 +1,4 @@-Copyright (c) 2008-2012 Dino Morelli+Copyright (c) 2008-2013 Dino Morelli All rights reserved. Redistribution and use in source and binary forms, with or without
Setup.hs view
@@ -1,6 +1,6 @@ #! /usr/bin/env runhaskell --- Copyright: 2008-2012 Dino Morelli+-- Copyright: 2008-2013 Dino Morelli -- License: BSD3 (see LICENSE) -- Author: Dino Morelli <dino@ui3.info>
epub-tools.cabal view
@@ -1,10 +1,10 @@ name: epub-tools cabal-version: >= 1.8-version: 2.0.0+version: 2.1.0 build-type: Simple license: BSD3 license-file: LICENSE-copyright: 2008-2012 Dino Morelli +copyright: 2008-2013 Dino Morelli author: Dino Morelli maintainer: Dino Morelli <dino@ui3.info> stability: stable@@ -28,7 +28,7 @@ executable epubmeta main-is: EpubTools/epubmeta.hs build-depends: base >= 3 && < 5, bytestring, directory,- epub-metadata >= 2.3.1, filepath, mtl, process,+ epub-metadata >= 2.3.2, filepath, mtl, process, zip-archive hs-source-dirs: src other-modules: EpubTools.EpubMeta.Display@@ -41,7 +41,7 @@ executable epubname main-is: EpubTools/epubname.hs- build-depends: base >= 3 && < 5, directory, epub-metadata >= 2.3.1, + build-depends: base >= 3 && < 5, directory, epub-metadata >= 2.3.1, filepath, mtl, parsec, regex-compat hs-source-dirs: src other-modules: EpubTools.EpubName.Format.Author
resources/default.rules view
@@ -52,16 +52,20 @@ titlePat ".* Magazine Issue ([0-9]+) ::.*" name "GUDMagazine(pad 2 1)" -magInterzone+magInterzone_old titlePat "^(Interzone)[^0-9]*([0-9]+)$" name "(1)SFF(pad 3 2)" +magInterzone+ titlePat "^(Interzone) ([0-9]+).*$"+ name "(1)SFF(pad 3 2)"+ magLightspeed_date titlePat "(Lightspeed) Magazine, (.*) (.*)" name "(1)(3)-(monthNum 2)" magLightspeed_issue- titlePat "(Lightspeed) Magazine Issue (.*)"+ titlePat "(Lightspeed).* Issue (.*)" name "(1)(pad 3 2)" magNemesis@@ -84,17 +88,14 @@ titlePat "^(Weird Tales)[^0-9]*([0-9]+)$" name "(scrub 1)(pad 3 2)" -compOfTheYear- titlePat "(.*of the Year.*)"- name "(scrub 1)"--compYearsBest- titlePat "(.*Year's Best.*)"- name "(scrub 1)"- magLocus titlePat "^(Locus), ([a-zA-Z]+) ([0-9]{4})$" name "(scrub 1)Magazine(3)-(monthNum 2)"++anthology+ subjectMatch "anthology"+ titlePat "(.*)"+ name "(scrub 1)(year)" ordinary_book titlePat "(.*)"
resources/epubname-dsl-docs view
@@ -11,7 +11,8 @@ Rules have the following format: label- authorPat "..."+ authorMatch "..."+ subjectMatch "..." titlePat "..." name "..." @@ -19,10 +20,15 @@ The indented fields are rule commands and consist of: - authorPat - Optional. If present, it's a regexp pattern that must+ authorMatch - Optional. If present, it's a regexp pattern that must match an author in the book's metadata. If it doesn't match, this rule is rejected. This may be a partial match, "bar" will match if- authors looks like "foo bar baz"+ any author looks like "foo bar baz"++ subjectMatch - Optional. If present, it's a regexp pattern that must+ match an subject in the book's metadata. If it doesn't match, this+ rule is rejected. This may be a partial match, "bar" will match if+ any subject looks like "foo bar baz" titlePat - a regular expression for picking apart the title string in the book's metadata. The pieces in capture groups ( ) are exposed
src/EpubTools/EpubMeta/Display.hs view
@@ -1,4 +1,4 @@--- Copyright: 2010-2012 Dino Morelli+-- Copyright: 2010-2013 Dino Morelli -- License: BSD3 (see LICENSE) -- Author: Dino Morelli <dino@ui3.info>
src/EpubTools/EpubMeta/Edit.hs view
@@ -1,4 +1,4 @@--- Copyright: 2010-2012 Dino Morelli+-- Copyright: 2010-2013 Dino Morelli -- License: BSD3 (see LICENSE) -- Author: Dino Morelli <dino@ui3.info>
src/EpubTools/EpubMeta/Export.hs view
@@ -1,4 +1,4 @@--- Copyright: 2010-2012 Dino Morelli+-- Copyright: 2010-2013 Dino Morelli -- License: BSD3 (see LICENSE) -- Author: Dino Morelli <dino@ui3.info>
src/EpubTools/EpubMeta/Import.hs view
@@ -1,4 +1,4 @@--- Copyright: 2010-2012 Dino Morelli+-- Copyright: 2010-2013 Dino Morelli -- License: BSD3 (see LICENSE) -- Author: Dino Morelli <dino@ui3.info>
src/EpubTools/EpubMeta/Opts.hs view
@@ -1,4 +1,4 @@--- Copyright: 2010-2012 Dino Morelli+-- Copyright: 2010-2013 Dino Morelli -- License: BSD3 (see LICENSE) -- Author: Dino Morelli <dino@ui3.info> @@ -103,5 +103,5 @@ , "" , "For more information please see the IDPF OPF specification found here: http://idpf.org/epub/20/spec/OPF_2.0.1_draft.htm" , ""- , "Version 2.0.0 Dino Morelli <dino@ui3.info>"+ , "Version 2.1.0 Dino Morelli <dino@ui3.info>" ]
src/EpubTools/EpubMeta/Util.hs view
@@ -1,4 +1,4 @@--- Copyright: 2008-2012 Dino Morelli+-- Copyright: 2008-2013 Dino Morelli -- License: BSD3 (see LICENSE) -- Author: Dino Morelli <dino@ui3.info>
src/EpubTools/EpubName/Format/Author.hs view
@@ -1,4 +1,4 @@--- Copyright: 2008-2012 Dino Morelli+-- Copyright: 2008-2013 Dino Morelli -- License: BSD3 (see LICENSE) -- Author: Dino Morelli <dino@ui3.info>
src/EpubTools/EpubName/Format/Compile.hs view
@@ -1,4 +1,4 @@--- Copyright: 2008-2012 Dino Morelli+-- Copyright: 2008-2013 Dino Morelli -- License: BSD3 (see LICENSE) -- Author: Dino Morelli <dino@ui3.info> @@ -26,13 +26,17 @@ pFormatter = do l <- many1Till (noneOf " ") eol a <- optionMaybe $ try $ pCommand "authorMatch"+ s <- optionMaybe $ try $ pCommand "subjectMatch" t <- pCommand "titlePat" n <- pName newline <|> return ' '- let aReplF = maybe (return ()) authorMatches a return $ case head l of '!' -> Nothing- _ -> Just $ Formatter l aReplF (extractTitle t) n+ _ -> Just $ Formatter l+ [ maybe (return ()) authorMatches a+ , maybe (return ()) subjectMatches s+ ]+ (extractTitle t) n pName :: Parser [ReplF]
src/EpubTools/EpubName/Format/Format.hs view
@@ -1,4 +1,4 @@--- Copyright: 2008-2012 Dino Morelli+-- Copyright: 2008-2013 Dino Morelli -- License: BSD3 (see LICENSE) -- Author: Dino Morelli <dino@ui3.info> @@ -10,6 +10,7 @@ , year , Formatter (..) , tryFormatting+ , subjectMatches , extractTitle ) where@@ -17,6 +18,7 @@ import Codec.Epub.Opf.Package import Control.Monad.Error import Data.List ( isPrefixOf )+import Data.Maybe ( isJust ) import Text.Printf import Text.Regex @@ -31,7 +33,7 @@ data Formatter = Formatter String -- formatter label- (EN ()) -- author match pattern+ [EN ()] -- field pattern matchers (EN [String]) -- title pattern parser [ReplF] -- name building actions @@ -139,6 +141,16 @@ rules file notation, in the rule blocks -} +{- This is used by subjectMatch to construct a subject matcher for a+ specific rule. Throws an error if no subject matches the pattern.+-}+subjectMatches :: String -> EN ()+subjectMatches re = do+ subjects <- asks $ metaSubjects . gMetadata+ unless (any isJust $ map (matchRegex (mkRegex re)) subjects) $+ throwError "Subject string not found"++ {- This is used by the titlePat command to construct a title pattern matcher for a specific rule -}@@ -165,8 +177,8 @@ -- Try a specific formatter tryFormatter :: Formatter -> EN (String, FilePath)-tryFormatter (Formatter label authorMatch titlePat nameBuilders) = do- authorMatch+tryFormatter (Formatter label matchers titlePat nameBuilders) = do+ sequence_ matchers matches <- titlePat newName <- name matches nameBuilders return (label, sanitizeString newName)
src/EpubTools/EpubName/Format/PubYear.hs view
@@ -1,4 +1,4 @@--- Copyright: 2011, 2012 Dino Morelli+-- Copyright: 2011-2013 Dino Morelli -- License: BSD3 (see LICENSE) -- Author: Dino Morelli <dino@ui3.info>
src/EpubTools/EpubName/Format/Util.hs view
@@ -1,4 +1,4 @@--- Copyright: 2008-2012 Dino Morelli+-- Copyright: 2008-2013 Dino Morelli -- License: BSD3 (see LICENSE) -- Author: Dino Morelli <dino@ui3.info>
src/EpubTools/EpubName/Main.hs view
@@ -1,4 +1,4 @@--- Copyright: 2008-2012 Dino Morelli+-- Copyright: 2008-2013 Dino Morelli -- License: BSD3 (see LICENSE) -- Author: Dino Morelli <dino@ui3.info>
src/EpubTools/EpubName/Opts.hs view
@@ -1,4 +1,4 @@--- Copyright: 2008-2012 Dino Morelli+-- Copyright: 2008-2013 Dino Morelli -- License: BSD3 (see LICENSE) -- Author: Dino Morelli <dino@ui3.info> @@ -194,5 +194,5 @@ , "For more information on the EPUB format, please see the IDPF OPF specification found here: http://idpf.org/epub/20/spec/OPF_2.0.1_draft.htm" , "" , ""- , "Version 2.0.0 Dino Morelli <dino@ui3.info>"+ , "Version 2.1.0 Dino Morelli <dino@ui3.info>" ]
src/EpubTools/EpubName/Util.hs view
@@ -1,4 +1,4 @@--- Copyright: 2008-2012 Dino Morelli+-- Copyright: 2008-2013 Dino Morelli -- License: BSD3 (see LICENSE) -- Author: Dino Morelli <dino@ui3.info>
src/EpubTools/EpubZip/Opts.hs view
@@ -1,4 +1,4 @@--- Copyright: 2010-2012 Dino Morelli+-- Copyright: 2010-2013 Dino Morelli -- License: BSD3 (see LICENSE) -- Author: Dino Morelli <dino@ui3.info> @@ -68,5 +68,5 @@ , "" , "For more information please see the IDPF OPF specification found here: http://idpf.org/epub/20/spec/OPF_2.0.1_draft.htm" , ""- , "Version 2.0.0 Dino Morelli <dino@ui3.info>"+ , "Version 2.1.0 Dino Morelli <dino@ui3.info>" ]
src/EpubTools/epubmeta.hs view
@@ -1,4 +1,4 @@--- Copyright: 2010-2012 Dino Morelli+-- Copyright: 2010-2013 Dino Morelli -- License: BSD3 (see LICENSE) -- Author: Dino Morelli <dino@ui3.info>
src/EpubTools/epubname.hs view
@@ -1,4 +1,4 @@--- Copyright: 2008-2012 Dino Morelli+-- Copyright: 2008-2013 Dino Morelli -- License: BSD3 (see LICENSE) -- Author: Dino Morelli <dino@ui3.info>
src/EpubTools/epubzip.hs view
@@ -1,4 +1,4 @@--- Copyright: 2011, 2012 Dino Morelli+-- Copyright: 2011-2013 Dino Morelli -- License: BSD3 (see LICENSE) -- Author: Dino Morelli <dino@ui3.info> @@ -58,13 +58,15 @@ case en of Right zipPath -> do exists <- liftIO $ doesFileExist zipPath- if ((not . optOverwrite $ opts) && exists)- then do++ case ((optOverwrite opts), exists) of+ (False, True) -> do _ <- liftIO $ printf "File %s exists, use --overwrite to force\n" zipPath throwError $ ExitFailure 1- else liftIO $ removeFile zipPath+ (True, True) -> liftIO $ removeFile zipPath+ (_ , _ ) -> return () _ <- liftIO $ do archive <- mkEpubArchive "."
testsuite/EpubTools/Test/EpubName/Format.hs view
@@ -1,4 +1,4 @@--- Copyright: 2012 Dino Morelli+-- Copyright: 2012-2013 Dino Morelli -- License: BSD3 (see LICENSE) -- Author: Dino Morelli <dino@ui3.info> @@ -55,8 +55,9 @@ , testGudShort , testGudLong , testGudVeryLong- , testInterzoneShort- , testInterzoneLong+ , testInterzoneOldShort+ , testInterzoneOldLong+ , testInterzone , testNemesisShort , testNemesisLong , testMagSomethingWicked@@ -75,8 +76,10 @@ , testMagUniverse , testMagClarkesworld , testLightspeedDate+ , testLightspeedMagIssue , testLightspeedIssue , testMagWeirdTales+ , testAnthology ] @@ -670,9 +673,9 @@ ) -testInterzoneShort :: (Options, [Formatter]) -> Test-testInterzoneShort (opts, fs) = TestCase $- assertNewName opts fs "Interzone Magazine, short" meta expected+testInterzoneOldShort :: (Options, [Formatter]) -> Test+testInterzoneOldShort (opts, fs) = TestCase $+ assertNewName opts fs "Interzone Magazine, old style, short" meta expected where meta = emptyMetadata { metaCreators = [MetaCreator Nothing Nothing @@ -681,14 +684,14 @@ "Interzone SFF #212"] } expected =- ( "magInterzone"+ ( "magInterzone_old" , "InterzoneSFF212.epub" ) -testInterzoneLong :: (Options, [Formatter]) -> Test-testInterzoneLong (opts, fs) = TestCase $- assertNewName opts fs "Interzone Magazine, long" meta expected+testInterzoneOldLong :: (Options, [Formatter]) -> Test+testInterzoneOldLong (opts, fs) = TestCase $+ assertNewName opts fs "Interzone Magazine, old style, long" meta expected where meta = emptyMetadata { metaCreators = [MetaCreator Nothing Nothing @@ -697,11 +700,27 @@ "Interzone Science Fiction and Fantasy Magazine #216"] } expected =- ( "magInterzone"+ ( "magInterzone_old" , "InterzoneSFF216.epub" ) +testInterzone :: (Options, [Formatter]) -> Test+testInterzone (opts, fs) = TestCase $+ assertNewName opts fs "Interzone Magazine, Smashwords style" meta expected+ where+ meta = emptyMetadata+ { metaCreators = [MetaCreator Nothing Nothing + "TTA Press"]+ , metaTitles = [MetaTitle Nothing + "Interzone 233 Mar - Apr 2011"]+ }+ expected =+ ( "magInterzone"+ , "InterzoneSFF233.epub"+ )++ testNemesisShort :: (Options, [Formatter]) -> Test testNemesisShort (opts, fs) = TestCase $ assertNewName opts fs "Nemesis Magazine, short" meta expected@@ -776,9 +795,10 @@ "Rich Horton"] , metaTitles = [MetaTitle Nothing "Science Fiction: The Best of the Year, 2007 Edition"]+ , metaSubjects = ["anthology"] } expected =- ( "compOfTheYear"+ ( "anthology" , "ScienceFiction_TheBestOfTheYear2007Edition.epub" ) @@ -794,9 +814,10 @@ "Jonathan Strahan"] , metaTitles = [MetaTitle Nothing "The Best Science Fiction and Fantasy of the Year: Volume 2"]+ , metaSubjects = ["anthology"] } expected =- ( "compOfTheYear"+ ( "anthology" , "TheBestScienceFictionAndFantasyOfTheYear_Volume2.epub" ) @@ -810,9 +831,10 @@ "Rich Horton, Michael Swanwick, Karen Joy Fowler"] , metaTitles = [MetaTitle Nothing "The Year's Best Science Fiction: 2008 Edition"]+ , metaSubjects = ["anthology"] } expected =- ( "compYearsBest"+ ( "anthology" , "TheYearsBestScienceFiction_2008Edition.epub" ) @@ -1014,8 +1036,8 @@ ) -testLightspeedIssue :: (Options, [Formatter]) -> Test-testLightspeedIssue (opts, fs) = TestCase $+testLightspeedMagIssue :: (Options, [Formatter]) -> Test+testLightspeedMagIssue (opts, fs) = TestCase $ assertNewName opts fs "Lightspeed Magazine, issue number in title" meta expected where@@ -1030,6 +1052,21 @@ ) +testLightspeedIssue :: (Options, [Formatter]) -> Test+testLightspeedIssue (opts, fs) = TestCase $+ assertNewName opts fs+ "Lightspeed Magazine, issue number in title" meta expected+ where+ meta = emptyMetadata+ { metaTitles = [MetaTitle Nothing + "Lightspeed Issue 33"]+ }+ expected =+ ( "magLightspeed_issue"+ , "Lightspeed033.epub"+ )++ testMagWeirdTales :: (Options, [Formatter]) -> Test testMagWeirdTales (opts, fs) = TestCase $ assertNewName opts fs "Weird Tales magazine" meta expected@@ -1047,4 +1084,25 @@ expected = ( "magWeirdTales" , "WeirdTales350.epub"+ )+++testAnthology :: (Options, [Formatter]) -> Test+testAnthology (opts, fs) = TestCase $+ assertNewName opts fs "anthology" meta expected+ where+ meta = emptyMetadata+ { metaTitles = [MetaTitle Nothing "Creepy Secrets"]+ , metaCreators =+ [ MetaCreator (Just "aut") (Just "Snively, Mortimer")+ "Mortimer Snively"+ , MetaCreator (Just "aut") (Just "Baxter, Joanne")+ "Joanne Baxter"+ ]+ , metaDates = [MetaDate (Just "publication") "2010-11-01"]+ , metaSubjects = ["fantasy and horror anthology"]+ }+ expected =+ ( "anthology"+ , "CreepySecrets_2010.epub" )
testsuite/EpubTools/Test/EpubName/PubYear.hs view
@@ -1,4 +1,4 @@--- Copyright: 2012 Dino Morelli+-- Copyright: 2012-2013 Dino Morelli -- License: BSD3 (see LICENSE) -- Author: Dino Morelli <dino@ui3.info>
testsuite/EpubTools/test-epubname.hs view
@@ -1,4 +1,4 @@--- Copyright: 2008-2012 Dino Morelli+-- Copyright: 2008-2013 Dino Morelli -- License: BSD3 (see LICENSE) -- Author: Dino Morelli <dino@ui3.info>