mirror of
https://github.com/borgbackup/borg.git
synced 2024-12-22 15:57:15 +00:00
Initial optparse implementation.
This commit is contained in:
parent
575efb5e0b
commit
e65ed8623f
1 changed files with 36 additions and 13 deletions
|
@ -3,6 +3,8 @@
|
|||
import hashlib
|
||||
import zlib
|
||||
import cPickle
|
||||
from optparse import OptionParser
|
||||
|
||||
from store import Store
|
||||
|
||||
CHUNKSIZE = 256 * 1024
|
||||
|
@ -103,10 +105,11 @@ def __init__(self):
|
|||
self.store = Store('/tmp/store')
|
||||
self.cache = Cache('/tmp/cache', self.store)
|
||||
|
||||
def create_archive(self, archive_name, path):
|
||||
def create_archive(self, archive_name, paths):
|
||||
if archive_name in self.cache.archives:
|
||||
raise Exception('Archive "%s" already exists' % archive_name)
|
||||
items = []
|
||||
for path in paths:
|
||||
for root, dirs, files in os.walk(path):
|
||||
for d in dirs:
|
||||
name = os.path.join(root, d)
|
||||
|
@ -151,13 +154,33 @@ def process_file(self, path, cache):
|
|||
print 'File: %s (%d chunks)' % (path, len(chunks))
|
||||
return {'type': 'FILE', 'path': path, 'size': size, 'chunks': chunks}
|
||||
|
||||
def run(self):
|
||||
parser = OptionParser()
|
||||
parser.add_option("-C", "--cache", dest="cache",
|
||||
help="cache directory to use", metavar="CACHE")
|
||||
parser.add_option("-s", "--store", dest="store",
|
||||
help="path to dedupe store", metavar="STORE")
|
||||
parser.add_option("-c", "--create", dest="create_archive",
|
||||
help="create ARCHIVE", metavar="ARCHIVE")
|
||||
parser.add_option("-d", "--delete", dest="delete_archive",
|
||||
help="delete ARCHIVE", metavar="ARCHIVE")
|
||||
parser.add_option("-l", "--list-archives", dest="list_archives",
|
||||
help="list archives")
|
||||
parser.add_option("-V", "--verify", dest="verify_archive",
|
||||
help="verify archive consistency")
|
||||
parser.add_option("-e", "--extract", dest="extract_archive",
|
||||
help="extract ARCHIVE")
|
||||
parser.add_option("-L", "--list-archive", dest="list_archive",
|
||||
help="verify archive consistency", metavar="ARCHIVE")
|
||||
(options, args) = parser.parse_args()
|
||||
if options.delete_archive:
|
||||
self.delete_archive(options.delete_archive)
|
||||
else:
|
||||
self.create_archive(options.create_archive, args)
|
||||
|
||||
def main():
|
||||
archiver = Archiver()
|
||||
if sys.argv[1] == 'delete':
|
||||
archiver.delete_archive(sys.argv[2])
|
||||
else:
|
||||
archiver.create_archive(sys.argv[1], sys.argv[2])
|
||||
archiver.run()
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
Loading…
Reference in a new issue