Blame view

blimp.nim 14.5 KB
b9ad52ff   Göran Krampe   Added default con...
1
  import md5, os, osproc, parseopt2, strutils, parsecfg, streams, lapp, subexes
74272cdb   Göran Krampe   First commit
2
  
5fc367ad   Göran Krampe   Renamed to blimp,...
3
  # blimp is a little utility program for handling large files
74272cdb   Göran Krampe   First commit
4
  # in git repositories. Its inspired by git-fat and s3annex
aaf9bcef   Göran Krampe   Upped to version ...
5
6
  # but doesn't rely on S3 for storage - it uses rsync like git-fat.
  # It is a single binary without any dependencies.
74272cdb   Göran Krampe   First commit
7
  #
5fc367ad   Göran Krampe   Renamed to blimp,...
8
9
10
11
  # Manual use:
  #
  # Use "blimp d mybigfile" to deflate it before commit.
  # Use "blimp i mybigfile" to inflate it back to original size.
74272cdb   Göran Krampe   First commit
12
  #
aaf9bcef   Göran Krampe   Upped to version ...
13
14
15
  # When deflated the file only has:
  #   "hash:" <filename> + <an md5sum>
  # ...inside it.
74272cdb   Göran Krampe   First commit
16
  #
aaf9bcef   Göran Krampe   Upped to version ...
17
18
  # The file is copied over to a local dir:
  #  <blimpstore>/<filename>-<md5sum>
5fc367ad   Göran Krampe   Renamed to blimp,...
19
  #
dab0c5b0   Göran Krampe   Added --version, ...
20
  # Configuration is in these locations in order:
78569137   Göran Krampe   Added directory e...
21
  #
dab0c5b0   Göran Krampe   Added --version, ...
22
  #   ./.blimp.conf
5fc367ad   Göran Krampe   Renamed to blimp,...
23
  #   <gitroot>/.blimp.conf
aaf9bcef   Göran Krampe   Upped to version ...
24
  #   ~/<blimpstore>/.blimp.conf
dab0c5b0   Göran Krampe   Added --version, ...
25
  #   ~/.blimp.conf
aaf9bcef   Göran Krampe   Upped to version ...
26
27
28
29
  #
  # This way you can have settings per directory, per git clone,
  # per store and per user. A default blimpstore with a commented .blimp.conf
  # is created in ~/blimpstore if you run blimp and no .blimp.conf is found.
dab0c5b0   Göran Krampe   Added --version, ...
30
31
32
33
34
35
  
  const 
    versionMajor* = 0
    versionMinor* = 2
    versionPatch* = 1
    versionAsString* = $versionMajor & "." & $versionMinor & "." & $versionPatch
74272cdb   Göran Krampe   First commit
36
  
b9ad52ff   Göran Krampe   Added default con...
37
  var
aaf9bcef   Göran Krampe   Upped to version ...
38
    blimpStore, remoteBlimpStore, uploadCommandFormat, downloadCommandFormat, deleteCommandFormat, rsyncPassword, blimpVersion: string = nil
78569137   Göran Krampe   Added directory e...
39
    homeDir, currentDir, gitRootDir: string
aaf9bcef   Göran Krampe   Upped to version ...
40
41
    verbose, stdio: bool
    stdinContent: string = nil
74272cdb   Göran Krampe   First commit
42
  
b9ad52ff   Göran Krampe   Added default con...
43
44
45
  let
    defaultConfig = """
  [rsync]
aaf9bcef   Göran Krampe   Upped to version ...
46
  # Set your local blimpstore directory. You can use %home%, %cwd% and %gitroot% in paths, works cross platform.
78569137   Göran Krampe   Added directory e...
47
48
49
50
51
52
53
54
55
56
57
  # Example:
  #   # Place it inside the git clone
  #   blimpstore = "%gitroot%/.git/blimpstore"
  #   # Place it in current working directory (not very useful)
  #   blimpstore = "%cwd%/blimpstore"
  #
  # Default:
  #   # Place it in the users home directory
  #   blimpstore = "%home%/blimpstore"
  
  # Set this to your remote rsync location
dab0c5b0   Göran Krampe   Added --version, ...
58
  remote = "blimpuser@some-rsync-server.com::blimpstore"
aaf9bcef   Göran Krampe   Upped to version ...
59
  # Set this to your rsync password, it will be written out as a password-file called .blimp.pass on every rsync.
dab0c5b0   Göran Krampe   Added --version, ...
60
  password = "some-good-rsync-password-for-blimpuser"
e914743a   Göran Krampe   Added remove comm...
61
  
aaf9bcef   Göran Krampe   Upped to version ...
62
63
64
  # The following three formats should not need editing.
  # $1 is the blimp filename, $2 is remote location and $3 is the local blimpstore directory set above.
  # NOTE: The password-file .blimp.pass will be created by blimp on every command, do not remove that option.
dab0c5b0   Göran Krampe   Added --version, ...
65
66
  upload = "rsync --password-file $3/.blimp.pass -avzP $3/$1 $2/"
  download = "rsync --password-file $3/.blimp.pass -avzP $2/$1 $3/"
78569137   Göran Krampe   Added directory e...
67
  # This deletes a single file from destination, that is already deleted in source. Yeah... insane! But it works.
dab0c5b0   Göran Krampe   Added --version, ...
68
  delete = "rsync --password-file $3/.blimp.pass -dv --delete --existing --ignore-existing --include '$1' --exclude '*' $3/ $2"
aaf9bcef   Göran Krampe   Upped to version ...
69
70
71
72
  
  [blimp]
  # Minimal version, otherwise stop
  # version = 0.2 
b9ad52ff   Göran Krampe   Added default con...
73
  """
74272cdb   Göran Krampe   First commit
74
  
78569137   Göran Krampe   Added directory e...
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
  # Find git root dir or nil
  proc gitRoot(): string =
    try:
      let tup = execCmdEx("git rev-parse --show-toplevel")
      if tup[1] == 0:
        result = strip(tup[0])
      else:
        result = nil
    except:
      result = nil
  
  # Simple expansion of %home%, %cwd% and %gitroot%
  proc expandDirs(templ: string): string =
    result = templ.replace("%home%", homeDir)
    result = result.replace("%cwd%", currentDir)
    if result.contains("%gitroot%"):
      if gitRootDir.isNil: quit("Not in a git clone, can not expand %gitroot% in '" & templ & "'") 
      result = result.replace("%gitroot%", gitRootDir)
  
dab0c5b0   Göran Krampe   Added --version, ...
94
  # Load a blimp.conf file
74272cdb   Göran Krampe   First commit
95
  proc parseConfFile(filename: string) =
74272cdb   Göran Krampe   First commit
96
97
    var f = newFileStream(filename, fmRead)
    if f != nil:
dab0c5b0   Göran Krampe   Added --version, ...
98
      if verbose: echo "Reading config: " & filename
74272cdb   Göran Krampe   First commit
99
      var p: CfgParser
dab0c5b0   Göran Krampe   Added --version, ...
100
      
74272cdb   Göran Krampe   First commit
101
102
103
104
105
106
107
108
109
      open(p, f, filename)
      while true:
        var e = next(p)
        case e.kind
        of cfgEof: 
          break
        of cfgSectionStart:
          continue # Ignore
        of cfgKeyValuePair:
b9ad52ff   Göran Krampe   Added default con...
110
          case e.key
dab0c5b0   Göran Krampe   Added --version, ...
111
          of "blimpstore":
78569137   Göran Krampe   Added directory e...
112
            if blimpStore.isNil: blimpStore = expandDirs(e.value)
b9ad52ff   Göran Krampe   Added default con...
113
          of "remote":
78569137   Göran Krampe   Added directory e...
114
            if remoteBlimpStore.isNil: remoteBlimpStore = expandDirs(e.value)
dab0c5b0   Göran Krampe   Added --version, ...
115
116
          of "password":
            if rsyncPassword.isNil: rsyncPassword = e.value
b9ad52ff   Göran Krampe   Added default con...
117
          of "upload":
78569137   Göran Krampe   Added directory e...
118
            if uploadCommandFormat.isNil: uploadCommandFormat = expandDirs(e.value)
b9ad52ff   Göran Krampe   Added default con...
119
          of "download":
78569137   Göran Krampe   Added directory e...
120
            if downloadCommandFormat.isNil: downloadCommandFormat = expandDirs(e.value)
e914743a   Göran Krampe   Added remove comm...
121
          of "delete":
78569137   Göran Krampe   Added directory e...
122
            if deleteCommandFormat.isNil: deleteCommandFormat = expandDirs(e.value)
aaf9bcef   Göran Krampe   Upped to version ...
123
124
          of "version":
            if blimpVersion.isNil: blimpVersion = e.value
74272cdb   Göran Krampe   First commit
125
126
127
128
129
130
131
132
          else:
            quit("Unknown configuration: " & e.key)
        of cfgOption:
          quit("Unknown configuration: " & e.key)
        of cfgError:
          quit("Parsing " & filename & ": " & e.msg)
      close(p)
  
db95b901   Göran Krampe   Various fixes, mo...
133
134
135
136
  # Trivial helper to enable verbose
  proc run(cmd: string): auto =
    if verbose: echo(cmd)
    execCmd(cmd)
74272cdb   Göran Krampe   First commit
137
  
dab0c5b0   Göran Krampe   Added --version, ...
138
139
  # Every rsync command, make sure we have a password file
  proc rsyncRun(cmd: string): auto =
78569137   Göran Krampe   Added directory e...
140
141
142
143
    if not rsyncPassword.isNil:
      writeFile(blimpStore / ".blimp.pass", rsyncPassword)
      if execCmd("chmod 600 " & blimpStore / ".blimp.pass") != 0:
        quit("Failed to chmod 600 " & blimpStore / ".blimp.pass")
dab0c5b0   Göran Krampe   Added --version, ...
144
145
    run(cmd)
  
5fc367ad   Göran Krampe   Renamed to blimp,...
146
147
148
  # Upload a file to the remote master blimpStore
  proc uploadFile(blimpFilename: string) =
    if remoteBlimpStore.isNil:
e914743a   Göran Krampe   Added remove comm...
149
      echo("Remote blimpstore not set in configuration file, skipping uploading content:\n\t" & blimpFilename)
74272cdb   Göran Krampe   First commit
150
      return
dab0c5b0   Göran Krampe   Added --version, ...
151
    let errorCode = rsyncRun(format(uploadCommandFormat, blimpFilename, remoteBlimpStore, blimpStore))
b9ad52ff   Göran Krampe   Added default con...
152
153
    if errorCode != 0:
      quit("Something went wrong uploading " & blimpFilename & " to " & remoteBlimpStore, 2)
74272cdb   Göran Krampe   First commit
154
    
5fc367ad   Göran Krampe   Renamed to blimp,...
155
156
157
158
  # Download a file to the remote master blimpStore
  proc downloadFile(blimpFilename: string) =
    if remoteBlimpStore.isNil:
      quit("Remote blimpstore not set in configuration file, can not download content:\n\t" & blimpFilename)
dab0c5b0   Göran Krampe   Added --version, ...
159
    let errorCode = rsyncRun(format(downloadCommandFormat, blimpFilename, remoteBlimpStore, blimpStore))
b9ad52ff   Göran Krampe   Added default con...
160
161
    if errorCode != 0:
      quit("Something went wrong downloading " & blimpFilename & " from " & remoteBlimpStore, 3)
5fc367ad   Göran Krampe   Renamed to blimp,...
162
  
e914743a   Göran Krampe   Added remove comm...
163
164
165
166
  # Delete a file from the remote master blimpStore
  proc remoteDeleteFile(blimpFilename: string) =
    if remoteBlimpStore.isNil:
      return
dab0c5b0   Göran Krampe   Added --version, ...
167
    let errorCode = rsyncRun(format(deleteCommandFormat, blimpFilename, remoteBlimpStore, blimpStore))
e914743a   Göran Krampe   Added remove comm...
168
169
    if errorCode != 0:
      quit("Something went wrong deleting " & blimpFilename & " from " & remoteBlimpStore, 3)
5fc367ad   Göran Krampe   Renamed to blimp,...
170
171
172
173
  
  # Copy content to blimpStore, no upload yet.
  proc copyToBlimpStore(filename, blimpFilename: string) =
    if not existsFile(blimpStore / blimpFilename):
aaf9bcef   Göran Krampe   Upped to version ...
174
175
176
177
178
179
180
181
      if stdio:
        try:
          writeFile(blimpStore / blimpFilename, stdinContent)
        except:
          quit("Failed writing file: " & blimpStore / blimpFilename & " from stdin", 1)
      else:
        copyFile(filename, blimpStore / blimpFilename)
        uploadFile(blimpFilename)
5fc367ad   Göran Krampe   Renamed to blimp,...
182
183
  
  # Copy content from blimpStore, and downloading first if needed
e914743a   Göran Krampe   Added remove comm...
184
  proc copyFromBlimpStore(blimpFilename, filename: string) =
5fc367ad   Göran Krampe   Renamed to blimp,...
185
186
    if not existsFile(blimpStore / blimpFilename):
      downloadFile(blimpFilename)
aaf9bcef   Göran Krampe   Upped to version ...
187
188
189
190
191
192
193
194
    if stdio:
      try:
        var content = readFile(blimpStore / blimpFilename)
        write(stdout, content)
      except:
        quit("Failed reading file: " & blimpStore / blimpFilename & " to stdout", 1)
    else:
      copyFile(blimpStore / blimpFilename, filename)
74272cdb   Göran Krampe   First commit
195
  
e914743a   Göran Krampe   Added remove comm...
196
197
198
199
200
201
  # Delete from blimpStore and remote.
  proc deleteFromBlimpStore(blimpFilename, filename: string) =
    if existsFile(blimpStore / blimpFilename):
      removeFile(blimpStore / blimpFilename)
    remoteDeleteFile(blimpFilename)
  
aaf9bcef   Göran Krampe   Upped to version ...
202
203
  proc blimpFileNameFromString(line: string): string =
    let hashline = split(strip(line), {':'})
e914743a   Göran Krampe   Added remove comm...
204
205
206
207
208
    if hashline[0] == "hash":
      result = hashline[1]
    else:
      result = nil
  
aaf9bcef   Göran Krampe   Upped to version ...
209
210
211
212
213
214
215
216
217
218
  # Pick out blimpFilename (filename & "-" & hash)
  proc blimpFileName(filename: string): string =
    if stdio:
      blimpFileNameFromString(stdinContent)
    else:
      var hashfile: File
      if not open(hashfile, filename):
        quit("Failed opening file: " & filename, 4)
      blimpFileNameFromString(string(readLine(hashfile)))  
  
e914743a   Göran Krampe   Added remove comm...
219
220
  # Get hash and compute blimpFilename
  proc computeBlimpFilename(filename: string): string =
dab0c5b0   Göran Krampe   Added --version, ...
221
222
223
224
225
226
227
    var content: string
    try:
      content = readFile(filename)
    except:
      quit("Failed opening file: " & filename, 1)
    let hash = getMD5(content)
    result = filename & "-" & hash
e914743a   Göran Krampe   Added remove comm...
228
   
5fc367ad   Göran Krampe   Renamed to blimp,...
229
  # Copy original file to blimpStore and replace with hash stub in git.
74272cdb   Göran Krampe   First commit
230
  proc deflate(filename: string) =
dab0c5b0   Göran Krampe   Added --version, ...
231
232
233
234
235
236
237
    if verbose: echo "Deflating " & filename
    var blimpFilename = blimpFilename(filename)
    if not blimpFilename.isNil:
      echo("\t" & filename & " is already deflated, skipping.")
    else:
      blimpFilename = computeBlimpFilename(filename)
      copyToBlimpStore(filename, blimpFilename)
aaf9bcef   Göran Krampe   Upped to version ...
238
239
240
241
      if stdio:
        write(stdout, "hash:" & blimpFilename)
      else:
        writeFile(filename, "hash:" & blimpFilename)
dab0c5b0   Göran Krampe   Added --version, ...
242
      if verbose: echo("\t" & filename & " deflated.")
e914743a   Göran Krampe   Added remove comm...
243
  
5fc367ad   Göran Krampe   Renamed to blimp,...
244
  # Parse out hash from hash stub and copy back original content from blimpStore.
74272cdb   Göran Krampe   First commit
245
  proc inflate(filename: string) =
dab0c5b0   Göran Krampe   Added --version, ...
246
    if verbose: echo "Inflating " & filename
e914743a   Göran Krampe   Added remove comm...
247
248
    let blimpFilename = blimpFilename(filename)
    if blimpFilename.isNil:
dab0c5b0   Göran Krampe   Added --version, ...
249
      echo("\t" & filename & " is not deflated, skipping.")
e914743a   Göran Krampe   Added remove comm...
250
251
    else:
      copyFromBlimpStore(blimpfilename, filename)
dab0c5b0   Göran Krampe   Added --version, ...
252
      if verbose: echo("\t" & filename & " inflated.")
e914743a   Göran Krampe   Added remove comm...
253
254
255
256
257
258
259
  
  # Inflates file first (if deflated) and then removes current content for it,
  # both locally and in remote.
  proc remove(filename: string) =
    var blimpFilename = blimpFilename(filename)
    if not blimpFilename.isNil:
      copyFromBlimpStore(blimpfilename, filename)
74272cdb   Göran Krampe   First commit
260
    else:
e914743a   Göran Krampe   Added remove comm...
261
262
263
      blimpFilename = computeBlimpFilename(filename)
    deleteFromBlimpStore(blimpfilename, filename)
    echo("\t" & filename & " content removed from blimpstore locally and remotely.")
5fc367ad   Göran Krampe   Renamed to blimp,...
264
  
dab0c5b0   Göran Krampe   Added --version, ...
265
266
267
268
269
270
271
272
273
274
275
276
277
278
  
  proc setupBlimpStore() =
    try:
      if not existsDir(blimpStore):
        createDir(blimpStore)
    except:
      quit("Could not create " & blimpStore & " directory.", 1)
  
    try:
      if not existsFile(blimpStore / ".blimp.conf"):
        writeFile(blimpStore / ".blimp.conf", defaultConfig)
    except:
      quit("Could not create .blimp.conf config file in " & blimpStore & " directory.", 1)
  
78569137   Göran Krampe   Added directory e...
279
280
281
  proc `$`(x: string): string =
    if x.isNil: "nil" else: x
  
dab0c5b0   Göran Krampe   Added --version, ...
282
283
284
285
286
287
288
  proc dumpConfig() =
    echo "\nDump of configuration:"
    echo "\tblimpStore: " & blimpStore
    echo "\tremoteBlimpStore: " & remoteBlimpStore
    echo "\tuploadCommandFormat: " & uploadCommandFormat
    echo "\tdownloadCommandFormat: " & downloadCommandFormat
    echo "\tdeleteCommandFormat: " & deleteCommandFormat
78569137   Göran Krampe   Added directory e...
289
    echo "\trsyncPassword: " & $rsyncPassword
aaf9bcef   Göran Krampe   Upped to version ...
290
    echo "\tblimpVersion: " & $blimpVersion
dab0c5b0   Göran Krampe   Added --version, ...
291
    echo "\n"
74272cdb   Göran Krampe   First commit
292
  
db95b901   Göran Krampe   Various fixes, mo...
293
294
  let help = """
    blimp [options] <command> <filenames...>
dab0c5b0   Göran Krampe   Added --version, ...
295
296
      -h,--help                Show this
      --version                Show version of blimp
aaf9bcef   Göran Krampe   Upped to version ...
297
298
      -v,--verbose             Verbosity, only works without -s
      -s,--stdio               If given, use stdin/stdout for content.
dab0c5b0   Göran Krampe   Added --version, ...
299
      <command>   (string)     (d)eflate, (i)nflate, remove
aaf9bcef   Göran Krampe   Upped to version ...
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
      <filenames> (string...)        One or more filepaths to inflate/deflate
  
    blimp is a little utility program for handling large files
    in git repositories. Its inspired by git-fat and s3annex
    but doesn't rely on S3 for storage - it uses rsync like git-fat.
    It is a single binary without any dependencies.
  
    Manual use:
  
    Use "blimp d mybigfile" to deflate it before commit.
    Use "blimp i mybigfile" to inflate it back to original size.
  
    When deflated the file only has:
      "hash:" <filename> "-" <md5sum>
    ...inside it.
  
    Deflate is run before you add the big file to the index for committing.
    Deflate will replace the file contents with a hash, and copy the
    real content to your local blimpstore:
    
      "blimpstore"/<filename>-<md5sum>
  
    ...and if configured also upload it to "remote", using rsync.
  
    Configuration is in these locations in order:
   
      ./.blimp.conf
      "gitroot"/.blimp.conf
      ~/<blimpstore>/.blimp.conf
      ~/.blimp.conf
  
    This way you can have settings per directory, per git clone,
    per store and per user. A default blimpstore with a commented .blimp.conf
    is created in ~/blimpstore if you run blimp and no .blimp.conf is found.
  
    Edit ~/blimpstore/.blimp.conf (or in another location) and set a proper
    remote and the proper rsync password. This ensures that its also properly
    synced with a master rsync repository that is typically shared.
  
    Inflate will bring back the original content by copying from
    your local blimpstore, and if its not there, first downloading from the remote.
    Use this whenever you need to work/edit the big file - in order to get
    its real content.
  
    The filenames given are all processed. If -s is used content is processed via
    stdin/stdout and only one filename can be passed. This is used when running blimp
    via a git filter (smudge/clean).
  
    The remove command (no single character shortcut) will remove the file(s) content
    both from the local blimpstore and from the remote. This only removes
    the current content version, not older versions. The file itself is first
    inflated, if needed, and not deleted. This only "unblimps" the file.
  """
db95b901   Göran Krampe   Various fixes, mo...
353
  
74272cdb   Göran Krampe   First commit
354
  ################################ main #####################################
78569137   Göran Krampe   Added directory e...
355
356
357
358
359
  # Set some dirs
  homeDir = getHomeDir()
  homeDir = homeDir[0.. -2] # Not sure why it keeps a trailing "/" on Linux
  currentDir = getCurrentDir()
  gitRootDir = gitRoot()
74272cdb   Göran Krampe   First commit
360
  
dab0c5b0   Göran Krampe   Added --version, ...
361
362
363
  # Using lapp to get args, on parsing failure this will show usage automatically
  var args = parse(help)
  verbose = args["verbose"].asBool
aaf9bcef   Göran Krampe   Upped to version ...
364
365
366
367
368
369
370
371
372
373
374
375
  stdio = args["stdio"].asBool
  
  # Can't do verbose with -s, that messes up stdout,
  # read in all of stdin once and for all
  if stdio:
    verbose = false
    try:
      stdinContent = readAll(stdin)
      close(stdin)
    except:
      quit("Failed reading stdin", 1)
  
dab0c5b0   Göran Krampe   Added --version, ...
376
377
  
  # Parse configuration files, may shadow and override each other
78569137   Göran Krampe   Added directory e...
378
379
380
  parseConfFile(currentDir / ".blimp.conf")
  if not gitRootDir.isNil:
    parseConfFile(gitRootDir / ".blimp.conf")
74272cdb   Göran Krampe   First commit
381
  
dab0c5b0   Göran Krampe   Added --version, ...
382
383
  # If we haven't gotten a blimpstore yet, we set a default one
  if blimpStore.isNil:
78569137   Göran Krampe   Added directory e...
384
    blimpStore = homeDir / "blimpstore"
74272cdb   Göran Krampe   First commit
385
  
dab0c5b0   Göran Krampe   Added --version, ...
386
387
  if existsDir(blimpStore):
    parseConfFile(blimpStore / ".blimp.conf")
78569137   Göran Krampe   Added directory e...
388
  parseConfFile(homeDir / ".blimp.conf")
74272cdb   Göran Krampe   First commit
389
  
dab0c5b0   Göran Krampe   Added --version, ...
390
  if verbose: dumpConfig()
e914743a   Göran Krampe   Added remove comm...
391
  
dab0c5b0   Göran Krampe   Added --version, ...
392
393
394
  # These two are special, they short out
  if args.showHelp: quit(help)
  if args.showVersion: quit("blimp version: " & versionAsString)
74272cdb   Göran Krampe   First commit
395
  
aaf9bcef   Göran Krampe   Upped to version ...
396
397
398
399
  # Check blimpVersion
  if not blimpVersion.isNil and blimpVersion != versionAsString:
    quit("Wrong version of blimp, configuration wants: " & blimpVersion)
  
db95b901   Göran Krampe   Various fixes, mo...
400
401
  let command = args["command"].asString
  let filenames = args["filenames"].asSeq
dab0c5b0   Göran Krampe   Added --version, ...
402
403
404
405
406
  
  # Make sure the local blimpstore is setup.
  setupBlimpStore()
  
  
74272cdb   Göran Krampe   First commit
407
408
  # Do the deed
  if command == "d" or command == "deflate":
db95b901   Göran Krampe   Various fixes, mo...
409
410
    for fn in filenames:
      deflate(fn.asString)
74272cdb   Göran Krampe   First commit
411
  elif command == "i" or command == "inflate":
db95b901   Göran Krampe   Various fixes, mo...
412
413
    for fn in filenames:
      inflate(fn.asString)
e914743a   Göran Krampe   Added remove comm...
414
415
416
  elif command == "remove":
    for fn in filenames:
      remove(fn.asString)
74272cdb   Göran Krampe   First commit
417
418
419
420
421
  else:
    quit("Unknown command, only (d)eflate or (i)inflate are valid.", 6)
  
  # All good
  quit(0)