Initial commit
[cleanm.git] / index.icl
1 implementation module index
2
3 import StdEnv
4 import Data.Maybe
5 import Data.Error
6 import System.File
7 import System.Directory
8 import Text.GenJSON
9 import Data.Tree
10
11 derive JSONEncode RTree, FileInfo, Tm, MaybeError
12 derive JSONDecode RTree, FileInfo, Tm, MaybeError
13
14 :: MusicDB :== RTree MusicEntry
15 :: MusicEntry =
16 { fe_filepath :: !FilePath
17 , fe_fileinfo :: !MaybeOSError FileInfo
18 , fe_musicentry :: [!Tag!]
19 }
20 :: Tag =
21 { tag_key :: !String
22 , tag_value :: !String
23 }
24
25 index :: MusicDB (RTree (FilePath, MaybeOSError FileInfo)) *World -> *(MusicDB, *World)
26 index (RNode mn mcs) (RNode (fp, mfi) fcs) w = (RNode mn mcs, w)
27
28 dbfile = "db.json"
29 root = "/mnt/data/music"
30
31 writeDB db w
32 # (ok, f, w) = fopen dbfile FWriteData w
33 | not ok = abort "Cannot open file\n"
34 # (ok, w) = fclose (f <<< toJSON db) w
35 | not ok = abort "Cannot close file\n"
36 = w
37
38 Start w
39 # (mfi, w) = getFileInfo root w
40 | isError mfi = abort "Cannot open root\n"
41 # (Ok fi) = mfi
42 | not fi.directory = abort "Root is not a directory\n"
43 # (tree, w) = readDirectoryTree root Nothing w
44 # (db, w) = index (RNode {fe_filepath=root,fe_fileinfo=mfi,fe_musicentry=[!!]} []) tree w
45 = writeDB tree w