-
Notifications
You must be signed in to change notification settings - Fork 0
/
tfs.py
executable file
·71 lines (57 loc) · 1.62 KB
/
tfs.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from filesystem import CodeFileSystem
from crypto import CryptoFilter
import config
import argparse
import posixpath
import os
class CryptoCloudFS(CryptoFilter, CodeFileSystem):
def __init__(self, conf, k, m, passwd):
CryptoFilter.__init__(self, passwd)
CodeFileSystem.__init__(self, conf.gen_stors(), k, m)
# def _get_path(self, path=None):
# if path == "":
# return self.pwd
# elif path[0] == "/":
# return path
# else:
# return posixpath.join(self.pwd, path)
def ls(fs, path):
print " ".join(fs.list(path))
def mkdir(fs, path):
fs.mknod(path, isdir=True)
fs.sync()
def put(fs, path, srcpath):
if path[-1] == "/":
path = posixpath.join(path, os.path.split(os.path.abspath(srcpath))[1])
else:
path
fs.mknod(path)
with open(srcpath, "rb") as f:
fs.update(path, f)
fs.sync()
def get(fs, path, destpath):
with open(destpath, "wb") as f:
fs.get(path, f)
def cat(fs, path):
print fs.get(path)
def rm(fs, path):
fs.delete(path)
fs.sync()
def copylocal(fs, path, localpath):
fs.copy_from_local(localpath, path)
def copy2local(fs, path, localpath):
fs.copy_to_local(path, localpath)
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument("cmd")
parser.add_argument("path", default="/", nargs="?")
parser.add_argument("localpath", default=None, nargs="?")
args = parser.parse_args()
conf = config.Config("config.yml")
cfs = CryptoCloudFS(conf, conf.RSCoding["k"], conf.RSCoding["m"], str(conf.Encryption["key"]))
if args.localpath:
globals()[args.cmd](cfs, args.path, args.localpath)
else:
globals()[args.cmd](cfs, args.path)