diff --git a/.gitignore b/.gitignore index f3f0182..400f9a5 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ pboy.cabal *~ *.swp *.pdf +result diff --git a/ChangeLog.md b/ChangeLog.md index adf4fa4..984bccc 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -9,6 +9,14 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - arXiv support. +## [1.0.0] - 2018-07-14 + +1.0 release. + +### Added + +Exception handling for missing command-line utilities. + ## [0.1.0] - 2018-07-02 First proper binary release diff --git a/README.md b/README.md index 19b865a..dad18b0 100644 --- a/README.md +++ b/README.md @@ -68,13 +68,11 @@ Paperboy creates a `.pboy.toml` in your home directory. Use this to change your # Current Limitations -Consider this to be beta quality right now. Nothing in this tool will break your computer, but there is not a lot of exception handling for missing folders or missing utility programs. - For large files, `pdftotext` can take quite a long time to parse the document, which is stupid because we're only using the first couple of lines for file name suggestions. # Contribute -Feel free to open issues, fix the Readme or send pull requests against the spec file https://github.com/2mol/pboy/blob/master/SPEC.md. You're generally very welcome to share any opinions, documentation improvements, fixes, refactoring suggestions etc. +Feel free to open issues, fix the Readme or send pull requests against the spec file https://github.com/2mol/pboy/blob/master/Spec.md. You're generally very welcome to share any opinions, documentation improvements, fixes, refactoring suggestions etc. See the abovementioned document to get an idea of what some of the next priotities are, especially the section **Next actionable**. diff --git a/SPEC.md b/Spec.md similarity index 95% rename from SPEC.md rename to Spec.md index 6c3d656..0e72c33 100644 --- a/SPEC.md +++ b/Spec.md @@ -26,13 +26,13 @@ ## Next actionable -- [ ] exception handling if `pdftotext` or `pdfinfo` are missing. +- [x] exception handling if `pdftotext` or `pdfinfo` are missing. - [ ] warn when importing an already existing filename. - [ ] option to open the document while in the middle of a rename/import. This way ambiguities about the title can be clarified. - [ ] allow renaming files after they have been imported. - [ ] refresh if any files move outside of the application. - [ ] nicer "first-use experience": Right now we simply write a default config file. It would be good to have an initial setup dialog asking for the inbox and library folder paths. -- [ ] compiled releases for Mac & Linux so that people other than Haskellers with 24Gb worth of stack/GHC installs can actually use this. +- [x] compiled releases for Mac & Linux so that people other than Haskellers with 24Gb worth of stack/GHC installs can actually use this. ## Possible future features @@ -48,4 +48,3 @@ ## Questions - opening files: rely on `open` system command. Is that always available? - diff --git a/package.yaml b/package.yaml index 9ffeb62..7009e5b 100644 --- a/package.yaml +++ b/package.yaml @@ -1,5 +1,5 @@ name: pboy -version: 0.1.0.0 +version: 1.0.0 github: "2mol/pboy" license: BSD3 author: "Juri Chomé" @@ -9,14 +9,9 @@ copyright: "2018 Juri Chomé" extra-source-files: - README.md - ChangeLog.md +- Spec.md -# Metadata used when publishing your package -# synopsis: Short description of your package -# category: misc - -# To avoid duplicated efforts in documentation and dealing with the -# complications of embedding Haddock markup inside cabal files, it is -# common to point users to the README.md file. +synopsis: "a small .pdf management utility" description: Please see the README on Github at dependencies: @@ -26,9 +21,9 @@ dependencies: - unordered-containers - either - time - - fmt - brick - vty + - fmt - microlens - microlens-th - filepath diff --git a/src/Lib.hs b/src/Lib.hs index 789891d..1f39eb3 100644 --- a/src/Lib.hs +++ b/src/Lib.hs @@ -4,6 +4,7 @@ module Lib where import Config (Config) import qualified Config +import Control.Exception as E import qualified Data.Char as C import Data.Either.Combinators (rightToMaybe) import Data.Function ((&)) @@ -55,6 +56,7 @@ fileSupported fileInfo = let extension = F.takeExtension $ _fileName fileInfo in S.member extension constSupportedExtensions + -- Getting Filename suggestions: fileNameSuggestions :: Config -> FilePath -> IO (NonEmpty Text) @@ -62,7 +64,10 @@ fileNameSuggestions config filePath = do let fileName = F.takeFileName filePath fullFilePath = (config ^. Config.inboxDir) fileName - plainTextContent <- P.readProcess "pdftotext" [fullFilePath, "-"] "" + + plainTextContent <- + P.readProcess "pdftotext" [fullFilePath, "-"] "" + & tryJust displayErr pdfInfo <- PDFI.pdfInfo fullFilePath @@ -84,12 +89,15 @@ fileNameSuggestions config filePath = do >>= boolToMaybe lengthCheck topContent = - T.pack plainTextContent - & T.lines - & take 16 -- totally arbitrary. subject to improvement later - & fmap sanitize - & filter lengthCheck - & fmap Just + case plainTextContent of + Left _ -> [] + Right content -> + T.pack content + & T.lines + & take 16 -- totally arbitrary. subject to improvement later + & fmap sanitize + & filter lengthCheck + & fmap Just suggestions = cleanFileName : maybeTitle : topContent @@ -97,6 +105,7 @@ fileNameSuggestions config filePath = do pure $ baseName :| take 5 (List.nub suggestions) + lengthCheck :: Text -> Bool lengthCheck t = T.length t >= 3 && T.length t <= 64 @@ -107,6 +116,7 @@ boolToMaybe check a = then Just a else Nothing + -- 1. remove double spaces / double underscores -- 2. strip out all except ascii, alphanumeric, spaces, underscores, dashes -- 3. display with spaces in UI, replace with '_' for filenames later @@ -129,6 +139,7 @@ validChars x = '-' -> True _ -> C.isLetter x || C.isSpace x + -- shelving files into library folder finalFileName :: Text -> Text @@ -151,7 +162,8 @@ fileFile conf origFileName newFileName = do Config.Copy -> D.copyFile origFilePath newFilePath Config.Move -> D.renameFile origFilePath newFilePath -openFile :: Config -> FilePath -> IO () + +openFile :: Config -> FilePath -> IO (Either String ()) openFile conf fileName = do let cleanFileName = @@ -160,6 +172,21 @@ openFile conf fileName = do filePath = conf ^. Config.libraryDir cleanFileName - _ <- P.readProcess "open" [filePath] "" + linuxOpen <- + P.readProcess "xdg-open" [filePath] "" + & tryJust displayErr + + case linuxOpen of + Left _ -> + do + _ <- + P.readProcess "open" [filePath] "" + & tryJust displayErr + pure $ Right () + Right _ -> + pure $ Right () + - pure () +displayErr :: SomeException -> Maybe String +displayErr e = + Just $ displayException e diff --git a/stack.yaml b/stack.yaml index fd10d33..d4364fc 100644 --- a/stack.yaml +++ b/stack.yaml @@ -15,7 +15,7 @@ # resolver: # name: custom-snapshot # location: "./custom-snapshot.yaml" -resolver: lts-11.9 +resolver: lts-12.0 # User packages to be built. # Various formats can be used as shown in the example below. @@ -40,7 +40,8 @@ packages: # Dependency packages to be pulled from upstream that are not in the resolver # (e.g., acme-missiles-0.3) extra-deps: [ - htoml-megaparsec-2.0.0.1 + htoml-megaparsec-2.0.0.2, + fmt-0.6 ] # Override default flag values for local packages and extra-deps