-
Notifications
You must be signed in to change notification settings - Fork 38
/
utilsYunPan.py
61 lines (51 loc) · 1.26 KB
/
utilsYunPan.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
# -*- coding: utf8 -*-
"""
tools
360yunpan - 360YunPan Command-line tools, support: Linux Mac Windows
Licensed under the MIT license:
http://www.opensource.org/licenses/mit-license.php
Project home:
https://github.com/logbird/360yunpan
Version: 1.0.0
@Author [email protected]
"""
import sys
import json
import re
import os
import hashlib
import string
reload(sys)
sys.setdefaultencoding("utf-8")
def jsonRepair(str):
#str = str.replace(' ', '')
regx = r'([{|,])[\' ]*([a-zA-Z_]*)[\' ]*:'
str = re.sub(regx, r'\1"\2" :', str);
str = str.replace("'", '"')
return str
def getConfig(key):
config = {
'tmpDir' : sys.path[0] + '/tmp'
}
if config.has_key(key):
return config[key]
else:
return ''
def isText(s):
text_characters = "".join(map(chr, range(32, 127)) + list("\n\r\t\b"))
_null_trans = string.maketrans("", "")
'''
判断文件是文本还是二进制
'''
if "\0" in s:
return False
if not s:
return 1
t = s.translate(_null_trans, text_characters)
if float(len(t))/float(len(s)) > 0.30:
return False
return True
def checkFileHash(fpath, fhash):
'''根据路径和文件的hash值来验证文件是否产生变化
'''
pass