Skip to content

Commit

Permalink
Merge pull request #13 from 2mol/dev
Browse files Browse the repository at this point in the history
merge dev for 1.0
  • Loading branch information
2mol authored Jul 14, 2018
2 parents cc1b922 + 39b054e commit f46ddf8
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 27 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ pboy.cabal
*~
*.swp
*.pdf
result
8 changes: 8 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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**.

Expand Down
5 changes: 2 additions & 3 deletions SPEC.md → Spec.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -48,4 +48,3 @@
## Questions

- opening files: rely on `open` system command. Is that always available?

13 changes: 4 additions & 9 deletions package.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: pboy
version: 0.1.0.0
version: 1.0.0
github: "2mol/pboy"
license: BSD3
author: "Juri Chomé"
Expand All @@ -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 <https://github.com/2mol/pboy#readme>

dependencies:
Expand All @@ -26,9 +21,9 @@ dependencies:
- unordered-containers
- either
- time
- fmt
- brick
- vty
- fmt
- microlens
- microlens-th
- filepath
Expand Down
47 changes: 37 additions & 10 deletions src/Lib.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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 ((&))
Expand Down Expand Up @@ -55,14 +56,18 @@ fileSupported fileInfo =
let extension = F.takeExtension $ _fileName fileInfo
in S.member extension constSupportedExtensions


-- Getting Filename suggestions:

fileNameSuggestions :: Config -> FilePath -> IO (NonEmpty Text)
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

Expand All @@ -84,19 +89,23 @@ 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
& Maybe.catMaybes

pure $ baseName :| take 5 (List.nub suggestions)


lengthCheck :: Text -> Bool
lengthCheck t = T.length t >= 3 && T.length t <= 64

Expand All @@ -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
Expand All @@ -129,6 +139,7 @@ validChars x =
'-' -> True
_ -> C.isLetter x || C.isSpace x


-- shelving files into library folder

finalFileName :: Text -> Text
Expand All @@ -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 =
Expand All @@ -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
5 changes: 3 additions & 2 deletions stack.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
Expand Down

0 comments on commit f46ddf8

Please sign in to comment.