Skip to content

Commit 08b57c9

Browse files
committed
【完善】:代码优化
1 parent f254441 commit 08b57c9

File tree

1 file changed

+10
-19
lines changed

1 file changed

+10
-19
lines changed

archive.py

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -33,17 +33,14 @@ def unpack(archive_fn, path, pkg, pkgs_name_in_json):
3333

3434
flag = True
3535

36-
#print(pkg)
37-
3836
if ".tar.bz2" in archive_fn:
3937
arch = tarfile.open(archive_fn, "r:bz2")
4038
for tarinfo in arch:
4139
arch.extract(tarinfo, path)
4240
a = tarinfo.name
4341
if not os.path.isdir(os.path.join(path, a)):
4442
right_path = a.replace('/', '\\')
45-
a = os.path.join(os.path.split(right_path)[
46-
0], os.path.split(right_path)[1])
43+
a = os.path.join(os.path.split(right_path)[0], os.path.split(right_path)[1])
4744
pkgsdb.savetodb(a, archive_fn)
4845
arch.close()
4946

@@ -54,8 +51,7 @@ def unpack(archive_fn, path, pkg, pkgs_name_in_json):
5451
a = tarinfo.name
5552
if not os.path.isdir(os.path.join(path, a)):
5653
right_path = a.replace('/', '\\')
57-
a = os.path.join(os.path.split(right_path)[
58-
0], os.path.split(right_path)[1])
54+
a = os.path.join(os.path.split(right_path)[0], os.path.split(right_path)[1])
5955
pkgsdb.savetodb(a, archive_fn)
6056
arch.close()
6157

@@ -71,19 +67,14 @@ def unpack(archive_fn, path, pkg, pkgs_name_in_json):
7167
change_dirname = pkgs_name_in_json + '-' + pkg['ver']
7268
flag = False
7369

74-
right_name_to_db = right_path.replace(
75-
dir_name, change_dirname, 1)
76-
#print(right_name_to_db)
70+
right_name_to_db = right_path.replace(dir_name, change_dirname, 1)
7771
pkgsdb.savetodb(right_name_to_db, archive_fn, right_path)
7872
arch.close()
7973

80-
#Change the folder name
74+
# Change the folder name
8175

8276
change_dirname = pkgs_name_in_json + '-' + pkg['ver']
83-
#print(os.path.join(path, dir_name))
84-
#print(os.path.join(path, change_dirname))
85-
#print(pkgs_name_in_json)
86-
77+
8778
if os.path.isdir(os.path.join(path, change_dirname)):
8879
cmd = 'rd /s /q ' + os.path.join(path, change_dirname)
8980
os.system(cmd)
@@ -96,7 +87,7 @@ def packtest(path):
9687
if ".zip" in path:
9788
try:
9889
if zipfile.is_zipfile(path):
99-
# test zip again to make sure it's a right zip file.
90+
# Test zip again to make sure it's a right zip file.
10091
arch = zipfile.ZipFile(path, "r")
10192
if arch.testzip():
10293
ret = False
@@ -105,23 +96,23 @@ def packtest(path):
10596
ret = False
10697
print('package check error. \n')
10798
except Exception, e:
108-
print('packtest e.message:%s\t'%e.message)
99+
print('packtest e.message:%s\t' % e.message)
109100
# arch.close()
110101
print("The archive package is broken. \n")
111102
ret = False
112103

113104
if ".tar.bz2" in path:
114105
try:
115106
if not tarfile.is_tarfile(path):
116-
ret = False
107+
ret = False
117108
except Exception, e:
118109
ret = False
119110

120111
if ".tar.gz" in path:
121112
try:
122113
if not tarfile.is_tarfile(path):
123-
ret = False
114+
ret = False
124115
except Exception, e:
125116
ret = False
126-
117+
127118
return ret

0 commit comments

Comments
 (0)