summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Cady <d@jerkface.net>2018-03-09 23:11:20 -0500
committerAndrew Cady <d@jerkface.net>2018-03-09 23:31:42 -0500
commitd0d5ec92d912a286d51ea4df2c95f7cc5fd44bb1 (patch)
tree822155339ce7ef743fa5fec5950b28dd4298cfdc
parent54b275a0e4d8307b9351123523db264543c1f233 (diff)
implement pdf-autoprint
-rw-r--r--.gitignore3
-rw-r--r--ChangeLog.md3
-rw-r--r--LICENSE3
-rw-r--r--Main.hs45
-rw-r--r--README.md1
-rw-r--r--Setup.hs2
-rw-r--r--app/Main.hs6
-rw-r--r--package.yaml46
-rw-r--r--src/Lib.hs6
-rw-r--r--test/Spec.hs2
10 files changed, 55 insertions, 62 deletions
diff --git a/.gitignore b/.gitignore
index c0b8e96..a7c533f 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,3 +1,2 @@
1.stack-work/ 1.stack-work/
2new.cabal 2pdf-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 @@
1Copyright Andrew Cady (c) 2018
2
3All rights reserved.
diff --git a/Main.hs b/Main.hs
new file mode 100644
index 0000000..4df4426
--- /dev/null
+++ b/Main.hs
@@ -0,0 +1,45 @@
1{-# LANGUAGE NoImplicitPrelude #-}
2{-# LANGUAGE ScopedTypeVariables #-}
3module Main where
4
5import Rebase.Prelude
6import System.Directory (createDirectoryIfMissing, renameFile)
7import System.FilePath (takeFileName, (</>))
8import System.FSNotify (Event (..), watchDir, withManager)
9import System.Process.Typed (proc, runProcess)
10
11verbose :: Bool
12verbose = True
13
14pdfDirectory, seenDir, pdfPrinterExecutable :: FilePath
15pdfDirectory = "."
16seenDir = pdfDirectory </> "seen"
17pdfPrinterExecutable = "PDFtoPrinter.exe"
18
19main :: IO ()
20main = do
21 createDirectoryIfMissing False seenDir
22 withManager $ \mgr -> do
23 void $ watchDir mgr pdfDirectory (const True) handleEvent
24 forever $ threadDelay 1000000
25
26handleEvent :: Event -> IO ()
27handleEvent (Added f _) | (".pdf" `isSuffixOf` f) = handleNewPdf f
28handleEvent x = when verbose $ print x
29
30handleNewPdf :: FilePath -> IO ()
31handleNewPdf 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
38runProcessVerbose :: FilePath -> [String] -> IO ExitCode
39runProcessVerbose exe args = do
40 when verbose $ putStrLn $ "+ " ++ exe ++ " " ++ unwords args
41 runProcess (proc exe args)
42
43moveFileIntoDir :: FilePath -> FilePath -> IO ()
44moveFileIntoDir 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 @@
1import Distribution.Simple
2main = 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 @@
1module Main where
2
3import Lib
4
5main :: IO ()
6main = someFunc
diff --git a/package.yaml b/package.yaml
index 03cb634..435c2f7 100644
--- a/package.yaml
+++ b/package.yaml
@@ -1,52 +1,24 @@
1name: new 1name: pdf-autoprint
2version: 0.1.0.0 2version: 0.1.0.0
3github: "afcady/new"
4license: AllRightsReserved 3license: AllRightsReserved
5author: "Andrew Cady" 4author: "Andrew Cady"
6maintainer: "d@jerkface.net" 5maintainer: "d@jerkface.net"
7copyright: "2018 Andrew Cady" 6copyright: "2018 Andrew Cady"
8 7
9extra-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
21description: Please see the README on Github at <https://github.com/afcady/new#readme>
22
23dependencies: 8dependencies:
24- base >= 4.7 && < 5 9- base
25- rebase 10- rebase
26- lens 11- directory
27 12- fsnotify
28library: 13- typed-process
29 source-dirs: src 14- filepath
30 15
31executables: 16executables:
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 @@
1module Lib
2 ( someFunc
3 ) where
4
5someFunc :: IO ()
6someFunc = 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 @@
1main :: IO ()
2main = putStrLn "Test suite not yet implemented"