diff options
-rw-r--r-- | .gitignore | 3 | ||||
-rw-r--r-- | ChangeLog.md | 3 | ||||
-rw-r--r-- | LICENSE | 3 | ||||
-rw-r--r-- | Main.hs | 45 | ||||
-rw-r--r-- | README.md | 1 | ||||
-rw-r--r-- | Setup.hs | 2 | ||||
-rw-r--r-- | app/Main.hs | 6 | ||||
-rw-r--r-- | package.yaml | 46 | ||||
-rw-r--r-- | src/Lib.hs | 6 | ||||
-rw-r--r-- | test/Spec.hs | 2 |
10 files changed, 55 insertions, 62 deletions
@@ -1,3 +1,2 @@ | |||
1 | .stack-work/ | 1 | .stack-work/ |
2 | new.cabal | 2 | pdf-autoprint.cabal |
3 | *~ \ No newline at end of file | ||
diff --git a/ChangeLog.md b/ChangeLog.md deleted file mode 100644 index e415883..0000000 --- a/ChangeLog.md +++ /dev/null | |||
@@ -1,3 +0,0 @@ | |||
1 | # Changelog for new | ||
2 | |||
3 | ## Unreleased changes | ||
diff --git a/LICENSE b/LICENSE deleted file mode 100644 index 960c7f7..0000000 --- a/LICENSE +++ /dev/null | |||
@@ -1,3 +0,0 @@ | |||
1 | Copyright Andrew Cady (c) 2018 | ||
2 | |||
3 | All rights reserved. | ||
@@ -0,0 +1,45 @@ | |||
1 | {-# LANGUAGE NoImplicitPrelude #-} | ||
2 | {-# LANGUAGE ScopedTypeVariables #-} | ||
3 | module Main where | ||
4 | |||
5 | import Rebase.Prelude | ||
6 | import System.Directory (createDirectoryIfMissing, renameFile) | ||
7 | import System.FilePath (takeFileName, (</>)) | ||
8 | import System.FSNotify (Event (..), watchDir, withManager) | ||
9 | import System.Process.Typed (proc, runProcess) | ||
10 | |||
11 | verbose :: Bool | ||
12 | verbose = True | ||
13 | |||
14 | pdfDirectory, seenDir, pdfPrinterExecutable :: FilePath | ||
15 | pdfDirectory = "." | ||
16 | seenDir = pdfDirectory </> "seen" | ||
17 | pdfPrinterExecutable = "PDFtoPrinter.exe" | ||
18 | |||
19 | main :: IO () | ||
20 | main = do | ||
21 | createDirectoryIfMissing False seenDir | ||
22 | withManager $ \mgr -> do | ||
23 | void $ watchDir mgr pdfDirectory (const True) handleEvent | ||
24 | forever $ threadDelay 1000000 | ||
25 | |||
26 | handleEvent :: Event -> IO () | ||
27 | handleEvent (Added f _) | (".pdf" `isSuffixOf` f) = handleNewPdf f | ||
28 | handleEvent x = when verbose $ print x | ||
29 | |||
30 | handleNewPdf :: FilePath -> IO () | ||
31 | handleNewPdf f = | ||
32 | -- Note: there is no sense in checking the return result, as PDFtoPrinter.exe | ||
33 | -- returns success even when it fails to parse the PDF. | ||
34 | runProcessVerbose pdfPrinterExecutable [f] >> | ||
35 | moveFileIntoDir f seenDir | ||
36 | |||
37 | |||
38 | runProcessVerbose :: FilePath -> [String] -> IO ExitCode | ||
39 | runProcessVerbose exe args = do | ||
40 | when verbose $ putStrLn $ "+ " ++ exe ++ " " ++ unwords args | ||
41 | runProcess (proc exe args) | ||
42 | |||
43 | moveFileIntoDir :: FilePath -> FilePath -> IO () | ||
44 | moveFileIntoDir f d = renameFile f $ d </> takeFileName f | ||
45 | |||
diff --git a/README.md b/README.md deleted file mode 100644 index 4f7fd6a..0000000 --- a/README.md +++ /dev/null | |||
@@ -1 +0,0 @@ | |||
1 | # new | ||
diff --git a/Setup.hs b/Setup.hs deleted file mode 100644 index 9a994af..0000000 --- a/Setup.hs +++ /dev/null | |||
@@ -1,2 +0,0 @@ | |||
1 | import Distribution.Simple | ||
2 | main = defaultMain | ||
diff --git a/app/Main.hs b/app/Main.hs deleted file mode 100644 index de1c1ab..0000000 --- a/app/Main.hs +++ /dev/null | |||
@@ -1,6 +0,0 @@ | |||
1 | module Main where | ||
2 | |||
3 | import Lib | ||
4 | |||
5 | main :: IO () | ||
6 | main = someFunc | ||
diff --git a/package.yaml b/package.yaml index 03cb634..435c2f7 100644 --- a/package.yaml +++ b/package.yaml | |||
@@ -1,52 +1,24 @@ | |||
1 | name: new | 1 | name: pdf-autoprint |
2 | version: 0.1.0.0 | 2 | version: 0.1.0.0 |
3 | github: "afcady/new" | ||
4 | license: AllRightsReserved | 3 | license: AllRightsReserved |
5 | author: "Andrew Cady" | 4 | author: "Andrew Cady" |
6 | maintainer: "d@jerkface.net" | 5 | maintainer: "d@jerkface.net" |
7 | copyright: "2018 Andrew Cady" | 6 | copyright: "2018 Andrew Cady" |
8 | 7 | ||
9 | extra-source-files: | ||
10 | - README.md | ||
11 | - ChangeLog.md | ||
12 | |||
13 | # Metadata used when publishing your package | ||
14 | # synopsis: Short description of your package | ||
15 | # category: Web | ||
16 | |||
17 | # To avoid duplicated efforts in documentation and dealing with the | ||
18 | # complications of embedding Haddock markup inside cabal files, it is | ||
19 | # common to point users to the README.md file. | ||
20 | |||
21 | description: Please see the README on Github at <https://github.com/afcady/new#readme> | ||
22 | |||
23 | dependencies: | 8 | dependencies: |
24 | - base >= 4.7 && < 5 | 9 | - base |
25 | - rebase | 10 | - rebase |
26 | - lens | 11 | - directory |
27 | 12 | - fsnotify | |
28 | library: | 13 | - typed-process |
29 | source-dirs: src | 14 | - filepath |
30 | 15 | ||
31 | executables: | 16 | executables: |
32 | new-exe: | 17 | pdf-autoprint: |
33 | main: Main.hs | 18 | main: Main.hs |
34 | source-dirs: app | ||
35 | ghc-options: | 19 | ghc-options: |
36 | - -threaded | 20 | - -threaded |
37 | - -rtsopts | 21 | - -rtsopts |
38 | - -with-rtsopts=-N | 22 | - -with-rtsopts=-N |
39 | - -W -Wall | 23 | - -W |
40 | dependencies: | 24 | - -Wall |
41 | - new | ||
42 | |||
43 | # tests: | ||
44 | # new-test: | ||
45 | # main: Spec.hs | ||
46 | # source-dirs: test | ||
47 | # ghc-options: | ||
48 | # - -threaded | ||
49 | # - -rtsopts | ||
50 | # - -with-rtsopts=-N | ||
51 | # dependencies: | ||
52 | # - new | ||
diff --git a/src/Lib.hs b/src/Lib.hs deleted file mode 100644 index d36ff27..0000000 --- a/src/Lib.hs +++ /dev/null | |||
@@ -1,6 +0,0 @@ | |||
1 | module Lib | ||
2 | ( someFunc | ||
3 | ) where | ||
4 | |||
5 | someFunc :: IO () | ||
6 | someFunc = putStrLn "someFunc" | ||
diff --git a/test/Spec.hs b/test/Spec.hs deleted file mode 100644 index cd4753f..0000000 --- a/test/Spec.hs +++ /dev/null | |||
@@ -1,2 +0,0 @@ | |||
1 | main :: IO () | ||
2 | main = putStrLn "Test suite not yet implemented" | ||