Commit 6884d53440fa3fd4baddf307b5f2e879d5a69917
1 parent
f9e9a47e
Fixed unixy path on win32, improved .blimp.conf template.
Showing
1 changed file
with
51 additions
and
25 deletions
blimp.nim
... | ... | @@ -2,7 +2,7 @@ import md5, os, osproc, parseopt2, strutils, parsecfg, streams, lapp, subexes, t |
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 |
5 | -# but doesn't rely on S3 for storage - it uses sftp but | |
5 | +# but doesn't rely on S3 for storage - it uses scp but | |
6 | 6 | # performs the file operations using externally configured commands. |
7 | 7 | # It is a single binary without any dependencies. |
8 | 8 | # |
... | ... | @@ -34,13 +34,14 @@ var |
34 | 34 | areas = newTable[string, RemoteArea]() |
35 | 35 | remoteArea: RemoteArea |
36 | 36 | |
37 | -let | |
38 | - defaultConfig = """ | |
37 | +let defaultConfig = """ | |
39 | 38 | [blimp] |
40 | 39 | # Minimal version, otherwise stop |
41 | 40 | # version = """ & versionAsString & """ |
42 | - | |
43 | -# Set your local blimpstore directory. You can use %home%, %cwd% and %gitroot% in paths, works cross platform. | |
41 | +# | |
42 | +# Set your local blimpstore directory. You can use %home%, | |
43 | +# %cwd% and %gitroot% in paths, works cross platform. | |
44 | +# | |
44 | 45 | # Example: |
45 | 46 | # # Place it inside the git clone |
46 | 47 | # blimpstore = "%gitroot%/.git/blimpstore" |
... | ... | @@ -50,21 +51,36 @@ let |
50 | 51 | # |
51 | 52 | # Default: |
52 | 53 | # # Place it in the users home directory |
53 | -# blimpstore = "%home%/blimpstore" | |
54 | - | |
55 | -[areas] | |
56 | -# This is where ypu define up/download areas. The area called "remote" is the | |
57 | -# default area used unless --area is used. | |
58 | -# $1 is the blimp filename, $2 is the remote url and $3 is the local blimpstore directory set above. | |
59 | -remote-url = "blimpuser@some-server.com:/var/opt/blimpstore" | |
60 | -remote-upload = "scp -pq $3/$1 $2/" | |
61 | -remote-download = "scp -pq $2/$1 $3/" | |
62 | - | |
63 | -# Example area that can be used with upload/download commands and --area option. | |
64 | -release-url = "blimpuser@some-server.com:/var/opt/release" | |
65 | -release-upload = "scp -r $3/$1 $2/" | |
66 | -release-download = "scp -r $2/$1 $3/" | |
67 | -""" | |
54 | +blimpstore = "%home%/blimpstore" | |
55 | + | |
56 | + | |
57 | +[remote] | |
58 | +# The "remote" area represents the shared remote blimpstore. | |
59 | +# This area is the default area used unless --area is used. | |
60 | +url = "blimp@build.3dicc.com:/var/opt/blimpstore" | |
61 | + | |
62 | +# On Windows we rely on msysgit that includes scp. | |
63 | +# On XP, make sure to put your ssh keys | |
64 | +# in c:\Program Files\git\.ssh (slightly odd place) | |
65 | +# On Win7 it uses c:\Users\gokr\.ssh - you can check with | |
66 | +# "ssh -v somehost" to see where it looks for the keys. | |
67 | +# | |
68 | +# When expanding the command templates below: | |
69 | +# $1 is the blimp filename | |
70 | +# $2 is the area url above | |
71 | +# $3 is the local blimpstore directory | |
72 | +upload = "scp -pq '$3/$1' '$2/'" | |
73 | +download = "scp -pq '$2/$1' '$3/'" | |
74 | + | |
75 | + | |
76 | +[release] | |
77 | +# This area can be used with upload/download commands and --area option. | |
78 | +# -r makes it possible to give directories as arguments for recursive handling. | |
79 | +url = "blimp@build.3dicc.com:/var/opt/release" | |
80 | +upload = "scp -r '$3/$1' '$2/'" | |
81 | +download = "scp -r '$2/$1' '$3/'" | |
82 | +""" | |
83 | + | |
68 | 84 | |
69 | 85 | proc cmd(cmd: string): string = |
70 | 86 | try: |
... | ... | @@ -133,7 +149,7 @@ proc parseConfFile(filename: string) = |
133 | 149 | of "blimp": |
134 | 150 | case e.key |
135 | 151 | of "blimpstore": |
136 | - if blimpStore.isNil: blimpStore = e.value | |
152 | + if blimpStore.isNil: blimpStore = expandDirs(e.value) | |
137 | 153 | of "version": |
138 | 154 | if blimpVersion.isNil: blimpVersion = e.value |
139 | 155 | else: |
... | ... | @@ -165,13 +181,24 @@ proc run(cmd: string): int = |
165 | 181 | if verbose: echo(cmd) |
166 | 182 | execCmd(cmd) |
167 | 183 | |
184 | +# Perhaps not perfect but tries to convert c:\foo\bar to /c/foo/bar | |
185 | +# but only if we are on windows, otherwise we do nothing. | |
186 | +proc toUnixyPath(path: string): string = | |
187 | + when defined(windows): | |
188 | + if path.len > 1 and path[1] == ':': | |
189 | + let parts = path.split({':', '\\'}) | |
190 | + result = "/" & parts.join("/") | |
191 | + else: | |
192 | + result = path | |
193 | + else: | |
194 | + result = path | |
168 | 195 | |
169 | 196 | # Upload a file to the remote area |
170 | 197 | proc uploadFile(filename, fromDir: string) = |
171 | 198 | if remoteArea.isNil: |
172 | 199 | echo("Remote area not set in configuration file, skipping uploading content:\n\t" & filename) |
173 | 200 | return |
174 | - let errorCode = run(format(remoteArea.upload, filename, remoteArea.url, fromDir)) | |
201 | + let errorCode = run(format(remoteArea.upload, filename, remoteArea.url, toUnixyPath(fromDir))) | |
175 | 202 | if errorCode != 0: |
176 | 203 | quit("Something went wrong uploading " & filename & " to " & remoteArea.url, 2) |
177 | 204 | |
... | ... | @@ -179,7 +206,7 @@ proc uploadFile(filename, fromDir: string) = |
179 | 206 | proc downloadFile(filename, toDir: string) = |
180 | 207 | if remoteArea.isNil: |
181 | 208 | quit("Remote area not set in configuration file, can not download content:\n\t" & filename) |
182 | - let errorCode = run(format(remoteArea.download, filename, remoteArea.url, toDir)) | |
209 | + let errorCode = run(format(remoteArea.download, filename, remoteArea.url, toUnixyPath(toDir))) | |
183 | 210 | if errorCode != 0: |
184 | 211 | quit("Something went wrong downloading " & filename & " from " & remoteArea.url, 3) |
185 | 212 | |
... | ... | @@ -187,7 +214,7 @@ proc downloadFile(filename, toDir: string) = |
187 | 214 | proc remoteDeleteFile(filename: string) = |
188 | 215 | if remoteArea.isNil: |
189 | 216 | return |
190 | - let errorCode = run(format(remoteArea.delete, filename, remoteArea.url, blimpStore)) | |
217 | + let errorCode = run(format(remoteArea.delete, filename, remoteArea.url, toUnixyPath(blimpStore))) | |
191 | 218 | if errorCode != 0: |
192 | 219 | quit("Something went wrong deleting " & filename & " from " & remoteArea.url, 3) |
193 | 220 | |
... | ... | @@ -454,7 +481,6 @@ homeDir = getHomeDir() |
454 | 481 | homeDir = homeDir[0.. -2] # Not sure why it keeps a trailing "/" on Linux |
455 | 482 | currentDir = getCurrentDir() |
456 | 483 | gitRootDir = gitRoot() |
457 | -echo gitRootDir | |
458 | 484 | |
459 | 485 | # Using lapp to get args, on parsing failure this will show usage automatically |
460 | 486 | var args = parse(synopsis) | ... | ... |