Commit b9ad52ff080b32da2fc4c520b48c69c7396a2526
1 parent
db95b901
Added default config file and subexes format for download/upload commands.
Showing
1 changed file
with
29 additions
and
9 deletions
blimp.nim
1 | -import md5, os, osproc, parseopt2, strutils, parsecfg, streams, lapp | |
1 | +import md5, os, osproc, parseopt2, strutils, parsecfg, streams, lapp, subexes | |
2 | 2 | |
3 | 3 | # blimp is a little utility program for handling large files |
4 | 4 | # in git repositories. Its inspired by git-fat and s3annex |
... | ... | @@ -19,9 +19,19 @@ import md5, os, osproc, parseopt2, strutils, parsecfg, streams, lapp |
19 | 19 | # <gitroot>/.blimp.conf |
20 | 20 | # ~/blimpstore/.blimp.conf |
21 | 21 | |
22 | -var blimpStore, remoteBlimpStore: string = nil | |
23 | -var verbose: bool | |
22 | +var | |
23 | + blimpStore, uploadCommandFormat, downloadCommandFormat: string | |
24 | + remoteBlimpStore: string = nil | |
25 | + verbose: bool | |
24 | 26 | |
27 | +let | |
28 | + defaultConfig = """ | |
29 | +[rsync] | |
30 | +remote = "blimp@some-rsync-server.com::blimpstore" | |
31 | +# $1 is filename, $2 is remote and $3 is the local blimpstore | |
32 | +upload = "rsync --password-file ~/blimp.pass -avzP $3/$1 $2/" | |
33 | +download = "rsync -avzP $2/$1 $3/" | |
34 | +""" | |
25 | 35 | |
26 | 36 | # Load blimp.conf file, overkill for now but... |
27 | 37 | proc parseConfFile(filename: string) = |
... | ... | @@ -37,8 +47,13 @@ proc parseConfFile(filename: string) = |
37 | 47 | of cfgSectionStart: |
38 | 48 | continue # Ignore |
39 | 49 | of cfgKeyValuePair: |
40 | - if e.key == "remote": | |
50 | + case e.key | |
51 | + of "remote": | |
41 | 52 | remoteBlimpStore = e.value |
53 | + of "upload": | |
54 | + uploadCommandFormat = e.value | |
55 | + of "download": | |
56 | + downloadCommandFormat = e.value | |
42 | 57 | else: |
43 | 58 | quit("Unknown configuration: " & e.key) |
44 | 59 | of cfgOption: |
... | ... | @@ -57,15 +72,17 @@ proc uploadFile(blimpFilename: string) = |
57 | 72 | if remoteBlimpStore.isNil: |
58 | 73 | echo("Remote blimpstore not set in configuration file, not uploading content:\n\t" & blimpFilename) |
59 | 74 | return |
60 | - let errorCode = run("rsync -a " & blimpStore / blimpFilename & " " & remoteBlimpStore) | |
61 | - if errorCode != 0: quit("Something went wrong uploading content to " & remoteBlimpStore, 2) | |
75 | + let errorCode = run(format(uploadCommandFormat, blimpFilename, remoteBlimpStore, blimpStore)) | |
76 | + if errorCode != 0: | |
77 | + quit("Something went wrong uploading " & blimpFilename & " to " & remoteBlimpStore, 2) | |
62 | 78 | |
63 | 79 | # Download a file to the remote master blimpStore |
64 | 80 | proc downloadFile(blimpFilename: string) = |
65 | 81 | if remoteBlimpStore.isNil: |
66 | 82 | quit("Remote blimpstore not set in configuration file, can not download content:\n\t" & blimpFilename) |
67 | - let errorCode = run("rsync -a " & remoteBlimpStore / blimpFilename & " " & blimpStore / "") | |
68 | - if errorCode != 0: quit("Something went wrong downloading " & blimpFilename & " from " & remoteBlimpStore, 3) | |
83 | + let errorCode = run(format(downloadCommandFormat, blimpFilename, remoteBlimpStore, blimpStore)) | |
84 | + if errorCode != 0: | |
85 | + quit("Something went wrong downloading " & blimpFilename & " from " & remoteBlimpStore, 3) | |
69 | 86 | |
70 | 87 | |
71 | 88 | # Copy content to blimpStore, no upload yet. |
... | ... | @@ -135,7 +152,10 @@ blimpStore = getHomeDir() / "blimpstore" |
135 | 152 | |
136 | 153 | # Make sure we have the dir, or create it. |
137 | 154 | try: |
138 | - if not existsDir(blimpStore): createDir(blimpStore) | |
155 | + if not existsDir(blimpStore): | |
156 | + createDir(blimpStore) | |
157 | + if not existsFile(blimpStore / ".blimp.conf"): | |
158 | + writeFile(blimpStore / ".blimp.conf", defaultConfig) | |
139 | 159 | except: |
140 | 160 | quit("Could not create " & blimpStore & " directory.", 1) |
141 | 161 | ... | ... |