Skip to content

Commit

Permalink
Merge pull request #23 from 2mol/dev-1.2
Browse files Browse the repository at this point in the history
1.2
  • Loading branch information
2mol authored Apr 21, 2019
2 parents 0deaefb + 3ab6978 commit 9a2681e
Show file tree
Hide file tree
Showing 8 changed files with 74 additions and 19 deletions.
23 changes: 23 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
version: 2.1
jobs:
build:
docker:
- image: fpco/stack-build:lts
steps:
- checkout
- restore_cache:
name: Restore Cached Dependencies
keys:
- pboy-{{ checksum "pboy.cabal" }}-{{ checksum "stack.yaml" }}
- run:
name: Install executable
command: stack install
- save_cache:
name: Cache Dependencies
key: pboy-{{ checksum "pboy.cabal" }}-{{ checksum "stack.yaml" }}
paths:
- "/root/.stack"
- ".stack-work"
- store_artifacts:
path: ~/.local/bin/pboy
destination: pboy
4 changes: 4 additions & 0 deletions Changelog.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
Changelog

1.2, 2019-04-21
- faster performance on large pdfs by only parsing the first couple of pages.
- won't create the default directories until the first file is moved.

1.1, 2019-04-19
- "first start" screen, showing the config file location.
- help screen.
Expand Down
21 changes: 15 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ If you're a Homebrew user, you can install the latest version and its dependenci
$ brew install 2mol/tools/pboy
```

## Get the binary release
## Linux/Mac binary release

Download the archive for your operating system from [https://github.com/2mol/pboy/releases](https://github.com/2mol/pboy/releases). Extract and install it with

Expand All @@ -39,18 +39,26 @@ $ mv pboy ~/.local/bin/

For the latter to work, `~/.local/bin/` needs to exist and be in your `PATH`. Alternatively, put it in `/usr/local/bin`.

## Stack
## Linux, any distro

I am still looking to package Paperboy for Debian/Ubuntu, Arch/Manjaro, Fedora, Doge Linux, or whatever else people install these days.

Any pointers or help with regards to generate `.deb`, `.rpm`, AUR `PKGBUILD`, etc is appreciated. Ideally this could be mostly automated in CI, in the end Paperboy is just a single binary with a dependency or two. How do other packages do it? If you got a good example or link, open a GitHub issue!

## Cabal/Stack

Make sure you have `poppler` installed, which will provide both `pdftotext` and `pdfinfo`. On Linux, install `poppler` with your package manager of choice. If you are on Mac and using Homebrew you can do `brew install poppler`.

Assuming you have stack, the following will compile, then install the `pboy` executable in your `.local/bin`:
Assuming you have cabal or stack, the following will compile, then install the `pboy` executable in your `.local/bin`:

```
$ git clone git@github.com:2mol/pboy.git
$ cd pboy
$ stack install
```

Replace `stack install` with `cabal new-install` at your leisure.

## Nix

If you have Nix, then you can install `pboy` with a single command:
Expand All @@ -61,13 +69,13 @@ $ nix-env -if https://github.com/2mol/pboy/tarball/master

# Config

TODO: config file location & format changed
Paperboy creates a `pboy.ini` in your XDG config directory. This is probably in `~/.config/pboy/pboy.ini`, the welcome or help screen will tell you. Use this to change your library and incoming folders, as well as to specify whether you want to move the imported files or just copy them.

Paperboy creates a `.pboy.toml` in your home directory. Use this to change your library and incoming folders, as well as to specify whether you want to move the imported files or just copy them.
**Note**: The config file location & format changed in version 1.1. Sorry to existing users, but the update should be trivial. Simply tweak the inbox and library folders in the new config. You can then delete `~/.pboy.toml`.

# Current Limitations

For large files, `pdftotext` can take quite a long time to parse the entire document, which is stupid because we're only using the first couple of lines for file name suggestions.
Paperboy doesn't do anything fancy with providing renaming patterns yet. For example, some people requested to be able to specify a format like `author-document_name-date.pdf`, others have asked if they could compose multiple suggestions into one. I haven't figured out a way to do this while keeping the UI simple and straightforward, so the idea needs a bit of design work first.

# Contribute

Expand All @@ -77,5 +85,6 @@ You're very welcome to suggest new features or open issues. See the Roadmap http

- [brick](https://github.com/jtdaugherty/brick) is a lovely way to a write a command-line UI.
- [nmattia](https://github.com/nmattia) did the work to get Paperboy to build with [nix](https://github.com/NixOS/nix) and patiently explained some of the basics to me.
- OsugiSakae and bri-an on reddit helped me with an annoying performance issue!

The name 'Paperboy' is a reference to [this game](https://en.wikipedia.org/wiki/Paperboy_(video_game)), which I had for the NES and never quite mastered.
14 changes: 11 additions & 3 deletions Roadmap.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,20 @@

## Future releases

- [ ] don't create any folders unless the first file import is triggered.
- [ ] improve performance of parsing large pdfs
- [ ] ability to mark documents as 'to-read'.
- [ ] warn when importing an already existing filename.
- [ ] refresh if any files move outside of the application.


## Done

1.2

- [x] don't create any folders unless the first file import is triggered.
- [x] improve performance of parsing large pdfs

1.1

- [x] show version number in the UI.
- [x] use xdg path for writing config file instead of home direcory.
- [x] use http://hackage.haskell.org/package/path for filepaths.
Expand All @@ -26,6 +31,8 @@
- [x] ability to specify multiple folders as inboxes.
- [x] help screen

pre 1.1

- [x] use nix for CI and releases.
- [x] compiled releases for Mac & Linux so that people other than Haskellers with 24Gb worth of stack/GHC installs can actually use this.
- [x] homebrew for mac
Expand All @@ -45,10 +52,11 @@ want:

maybe:

- recursively list both inbox and library.
- try out circleCI
- move away from ghr for releases and use inbuilt travis uploads instead.
- use https://github.com/tfausak/github-release
- subfolders.
- tag files to sync to phone (or kindle).
- try various open commands with `asum` from `Data.Foldable`
- option to switch between underscores and spaces.
- option to switch between underscores and spaces.
3 changes: 2 additions & 1 deletion pboy.cabal
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
cabal-version: 2.4

name: pboy
version: 1.1
version: 1.2
synopsis: a small .pdf management utility
description: Please see the README on Github at <https://github.com/2mol/pboy#readme>
homepage: https://github.com/2mol/pboy#readme
Expand All @@ -15,6 +15,7 @@ build-type: Simple
extra-source-files:
README.md
Changelog.txt
LICENSE

source-repository head
type: git
Expand Down
4 changes: 2 additions & 2 deletions src/Config.hs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ defaultConfig = readConfigData defaultConfigData

createConfig :: Path Abs File -> IO ()
createConfig cpath = do
_ <- Path.createDirIfMissing True (Path.parent cpath)
_ <- Path.ensureDir (Path.parent cpath)
TIO.writeFile (Path.fromAbsFile cpath) configContent
where
configContent =
Expand Down Expand Up @@ -109,7 +109,7 @@ configSpec =
& C.comment
[ "The folder to watch for incoming files."
, "Paths are relative to your home directory, but absolute paths are valid too."
, "I will watch multiple folders if you give me a comma-separated list"
, "I will watch multiple folders if you give me a comma-separated list."
]

libraryDirD .= C.field "library" C.string
Expand Down
15 changes: 9 additions & 6 deletions src/Lib.hs
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,12 @@ data FileInfo = FileInfo

listFiles :: Path Abs Dir -> IO [FileInfo]
listFiles path = do
Path.ensureDir path
files <- snd <$> Path.listDir path
fileInfos <- mapM getFileInfo files
pure $ filter isPdf fileInfos
dirExists <- Path.doesDirExist path
if dirExists then do
files <- snd <$> Path.listDir path
fileInfos <- mapM getFileInfo files
pure $ filter isPdf fileInfos
else pure []


sortFileInfoByDate :: [FileInfo] -> [FileInfo]
Expand Down Expand Up @@ -98,7 +100,7 @@ fileNameSuggestions file = do
getTopLines :: Path Abs File -> IO [Text]
getTopLines file = do
plainTextContent <-
E.try (P.readProcess "pdftotext" [Path.fromAbsFile file, "-"] "")
E.try (P.readProcess "pdftotext" [Path.fromAbsFile file, "-", "-f", "1", "-l", "4"] "")
:: IO (Either SomeException String)
let
topLines =
Expand Down Expand Up @@ -158,7 +160,8 @@ finalFileName text =

fileFile :: Config -> Text -> Path Abs File -> IO ()
fileFile conf newFileName file = do
newFile <- Path.parseRelFile (T.unpack newFileName ++ Path.fileExtension file)
_ <- Path.ensureDir (conf ^. Config.libraryDir)
newFile <- Path.parseRelFile (T.unpack newFileName <> Path.fileExtension file)
let
newFilePath =
conf ^. Config.libraryDir </> newFile
Expand Down
9 changes: 8 additions & 1 deletion stack.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
resolver: nightly-2019-03-25
resolver: lts-13.17
packages:
- .

extra-deps:
- brick-0.47@sha256:4936c50acfdf09620dad5217fb384fc0d59626f75abed8b48250b419ec2ab623
- config-ini-0.2.4.0@sha256:38a6d484d471c6fac81445de2eac8c4e8c82760962fca5491ae1c3bfca9c4047
- data-clist-0.1.2.2@sha256:4d70add0a200a178853cd37c6469101bac3c36aebb3aa9c503ff225211b1a8c9
- text-zipper-0.10.1@sha256:8b73a97a3717a17df9b0a722b178950c476ff2268ca5c583e99d010c94af849e
- word-wrap-0.4.1@sha256:f72233b383ef569c557bfd9812cbb8e306c415ce509082c0bd15ee51c0239ccc

0 comments on commit 9a2681e

Please sign in to comment.