1
0
Fork 0
mirror of https://github.com/borgbackup/borg.git synced 2024-12-23 00:07:38 +00:00

Initial optparse implementation.

This commit is contained in:
Jonas Borgström 2010-02-23 22:12:22 +01:00
parent 575efb5e0b
commit e65ed8623f

View file

@ -3,6 +3,8 @@
import hashlib import hashlib
import zlib import zlib
import cPickle import cPickle
from optparse import OptionParser
from store import Store from store import Store
CHUNKSIZE = 256 * 1024 CHUNKSIZE = 256 * 1024
@ -103,10 +105,11 @@ def __init__(self):
self.store = Store('/tmp/store') self.store = Store('/tmp/store')
self.cache = Cache('/tmp/cache', self.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: if archive_name in self.cache.archives:
raise Exception('Archive "%s" already exists' % archive_name) raise Exception('Archive "%s" already exists' % archive_name)
items = [] items = []
for path in paths:
for root, dirs, files in os.walk(path): for root, dirs, files in os.walk(path):
for d in dirs: for d in dirs:
name = os.path.join(root, d) name = os.path.join(root, d)
@ -151,13 +154,33 @@ def process_file(self, path, cache):
print 'File: %s (%d chunks)' % (path, len(chunks)) print 'File: %s (%d chunks)' % (path, len(chunks))
return {'type': 'FILE', 'path': path, 'size': size, 'chunks': 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(): def main():
archiver = Archiver() archiver = Archiver()
if sys.argv[1] == 'delete': archiver.run()
archiver.delete_archive(sys.argv[2])
else:
archiver.create_archive(sys.argv[1], sys.argv[2])
if __name__ == '__main__': if __name__ == '__main__':
main() main()