Skip to content

Commit 6880b1b

Browse files
authored
Merge pull request #88 from SummerGGift/fix_linux_pkg_bug
【同步】:develop 分支
2 parents 25aab49 + c8d089c commit 6880b1b

File tree

2 files changed

+36
-12
lines changed

2 files changed

+36
-12
lines changed

archive.py

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,19 +27,29 @@
2727
import zipfile
2828
import os
2929
import pkgsdb
30+
import platform
31+
import shutil
3032

3133

3234
def unpack(archive_fn, path, pkg, pkgs_name_in_json):
3335
pkg_ver = pkg['ver']
3436
flag = True
3537

38+
iswindows = False
39+
40+
if platform.system() == "Windows":
41+
iswindows = True
42+
3643
if ".tar.bz2" in archive_fn:
3744
arch = tarfile.open(archive_fn, "r:bz2")
3845
for tarinfo in arch:
3946
arch.extract(tarinfo, path)
4047
a = tarinfo.name
4148
if not os.path.isdir(os.path.join(path, a)):
42-
right_path = a.replace('/', '\\')
49+
if iswindows:
50+
right_path = a.replace('/', '\\')
51+
else:
52+
right_path = a
4353
a = os.path.join(os.path.split(right_path)[0], os.path.split(right_path)[1])
4454
pkgsdb.savetodb(a, archive_fn)
4555
arch.close()
@@ -50,7 +60,10 @@ def unpack(archive_fn, path, pkg, pkgs_name_in_json):
5060
arch.extract(tarinfo, path)
5161
a = tarinfo.name
5262
if not os.path.isdir(os.path.join(path, a)):
53-
right_path = a.replace('/', '\\')
63+
if iswindows:
64+
right_path = a.replace('/', '\\')
65+
else:
66+
right_path = a
5467
a = os.path.join(os.path.split(right_path)[0], os.path.split(right_path)[1])
5568
pkgsdb.savetodb(a, archive_fn)
5669
arch.close()
@@ -60,7 +73,11 @@ def unpack(archive_fn, path, pkg, pkgs_name_in_json):
6073
for item in arch.namelist():
6174
arch.extract(item, path)
6275
if not os.path.isdir(os.path.join(path, item)):
63-
right_path = item.replace('/', '\\')
76+
if iswindows:
77+
right_path = item.replace('/', '\\')
78+
else:
79+
right_path = item
80+
6481
# Gets the folder name and change_dirname only once
6582
if flag:
6683
dir_name = os.path.split(right_path)[0]
@@ -72,12 +89,14 @@ def unpack(archive_fn, path, pkg, pkgs_name_in_json):
7289
arch.close()
7390

7491
# Change the folder name
75-
7692
change_dirname = pkgs_name_in_json + '-' + pkg_ver
7793

7894
if os.path.isdir(os.path.join(path, change_dirname)):
79-
cmd = 'rd /s /q ' + os.path.join(path, change_dirname)
80-
os.system(cmd)
95+
if iswindows:
96+
cmd = 'rd /s /q ' + os.path.join(path, change_dirname)
97+
os.system(cmd)
98+
else:
99+
shutil.rmtree(os.path.join(path, change_dirname))
81100

82101
os.rename(os.path.join(path, dir_name),os.path.join(path, change_dirname))
83102

cmds/cmd_package.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -671,7 +671,12 @@ def get_package_remove_path(pkg, bsp_packages_path):
671671
ver = pkg['ver']
672672
if dirpath[0] == '/' or dirpath[0] == '\\':
673673
dirpath = dirpath[1:]
674-
dirpath = os.path.basename(dirpath.replace('/', '\\'))
674+
675+
if platform.system() == "Windows":
676+
dirpath = os.path.basename(dirpath.replace('/', '\\'))
677+
else:
678+
dirpath = os.path.basename(dirpath)
679+
675680
removepath = os.path.join(bsp_packages_path, dirpath)
676681

677682
# Handles the deletion of git repository folders with version Numbers
@@ -898,15 +903,15 @@ def package_wizard():
898903

899904
#third step
900905
packageclass = ('iot', 'language', 'misc', 'multimedia',
901-
'peripherals', 'security', 'system', 'tools')
902-
print ('\033[5;33;40m\n3.Please choose a package category from 1 to 8 : \033[0m')
903-
print ("\033[1;32;40m[1:iot]|[2:language]|[3:misc]|[4:multimedia]|[5:peripherals]|[6:security]|[7:system]|[8:tools]\033[0m")
906+
'peripherals', 'security', 'system', 'tools', 'peripherals/sensors')
907+
print ('\033[5;33;40m\n3.Please choose a package category from 1 to 9 : \033[0m')
908+
print ("\033[1;32;40m[1:iot]|[2:language]|[3:misc]|[4:multimedia]|[5:peripherals]|[6:security]|[7:system]|[8:tools]|[9:sensors]\033[0m")
904909
classnu = raw_input()
905-
while classnu == '' or classnu.isdigit()== False or int(classnu) < 1 or int(classnu) >8:
910+
while classnu == '' or classnu.isdigit()== False or int(classnu) < 1 or int(classnu) >9:
906911
if classnu == '' :
907912
print ('\033[1;31;40mError: You must choose a package category. Try again.\033[0m')
908913
else :
909-
print ('\033[1;31;40mError: You must input an integer number from 1 to 8. Try again.\033[0m')
914+
print ('\033[1;31;40mError: You must input an integer number from 1 to 9. Try again.\033[0m')
910915
classnu = raw_input()
911916

912917
pkgsclass = packageclass[int(classnu) - 1]

0 commit comments

Comments
 (0)