Skip to content

Commit a37a208

Browse files
authored
Merge branch 'develop' into chinese_style
2 parents e7333a0 + f307e04 commit a37a208

File tree

2 files changed

+101
-39
lines changed

2 files changed

+101
-39
lines changed

cmds/cmd_package.py

Lines changed: 70 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
# Change Logs:
2222
# Date Author Notes
2323
# 2018-05-28 SummerGift Add copyright information
24+
# 2018-12-28 Ernest Chen Add package information and enjoy package maker
2425
# 2019-01-07 SummerGift The prompt supports utf-8 encoding
2526
#
2627

@@ -902,52 +903,94 @@ def package_update(isDeleteOld=False):
902903
print ("Operation completed successfully.")
903904
else:
904905
print ("Operation failed.")
905-
906-
906+
907907
def package_wizard():
908908
"""Packages creation wizard.
909909
910910
The user enters the package name, version number, category, and automatically generates the package index file.
911911
"""
912-
913-
print ('Welcome to using package wizard, please enter the package information.')
914-
print ('The messages in [] is default setting. Press enter to use the default settings.')
915-
print ('Please enter package name:')
912+
# Welcome
913+
print ('\033[4;32;40mWelcome to using package wizard, please follow below steps.\033[0m\n')
914+
915+
#Simple introduction about the wizard
916+
print ('note :')
917+
print (' \033[5;35;40m[ ]\033[0m means default setting or optional information.')
918+
print (' \033[5;35;40mEnter\033[0m means using default option or ending and proceeding to the next step.')
919+
920+
#first step
921+
print ('\033[5;33;40m\n1.Please input a new package name :\033[0m')
916922
name = raw_input()
917-
if name == '':
918-
print ('Error: you must enter the package name. Try again.\n')
919-
return
923+
while name == '' or name.isspace() == True :
924+
print ('\033[1;31;40mError: you must input a package name. Try again.\033[0m')
925+
name = raw_input()
920926

921927
default_description = 'a ' + name + ' package for rt-thread'
922928
#description = user_input('menuconfig option name,default:\n',default_description)
923929
description = default_description
924-
ver = user_input('Version of this package, default:\n', '1.0.0')
930+
931+
#second step
932+
ver = user_input('\033[5;33;40m\n2.Please input this package version, default :\033[0m', '1.0.0')
925933
ver_standard = ver.replace('.', '')
926934
#keyword = user_input('keyword,default:\n', name)
927935
keyword = name
928936

937+
#third step
929938
packageclass = ('iot', 'language', 'misc', 'multimedia',
930939
'peripherals', 'security', 'system', 'tools')
931-
print ('Please choose a class for your package. Such as 1 is an iot pacakge, 2 is a language package.')
932-
print ("[1:iot]|[2:language]|[3:misc]|[4:multimedia]|[5:peripherals]|[6:security]|[7:system]|[8:tools]")
933-
940+
print ('\033[5;33;40m\n3.Please choose a package category from 1 to 8 : \033[0m')
941+
print ("\033[1;32;40m[1:iot]|[2:language]|[3:misc]|[4:multimedia]|[5:peripherals]|[6:security]|[7:system]|[8:tools]\033[0m")
934942
classnu = raw_input()
935-
if classnu == '':
936-
print ('Error: you must choose a class for your package. Try again.\n')
937-
return
938-
939-
if classnu >= '1' and classnu <= '8':
940-
pkgsclass = packageclass[int(classnu) - 1]
941-
# print pkgsclass
942-
else:
943-
print ('Error: input out of bound. You must enter the number from 1 to 8.')
944-
return
943+
while classnu == '' or classnu.isdigit()== False or int(classnu) < 1 or int(classnu) >8:
944+
if classnu == '' :
945+
print ('\033[1;31;40mError: You must choose a package category. Try again.\033[0m')
946+
else :
947+
print ('\033[1;31;40mError: You must input an integer number from 1 to 8. Try again.\033[0m')
948+
classnu = raw_input()
949+
950+
pkgsclass = packageclass[int(classnu) - 1]
951+
952+
953+
#fourth step
954+
print ('\033[5;33;40m\n4.Please input author name of this package :\033[0m')
955+
authorname = raw_input()
956+
while authorname == '':
957+
print ('\033[1;31;40mError: you must input author name of this package. Try again.\033[0m')
958+
authorname = raw_input()
959+
960+
#fifth step
961+
authoremail = raw_input('\033[5;33;40m\n5.Please input author email of this package :\n\033[0m')
962+
while authoremail == '':
963+
print ('\033[1;31;40mError: you must input author email of this package. Try again.\033[0m')
964+
authoremail = raw_input()
965+
966+
#sixth step
967+
print ('\033[5;33;40m\n6.Please choose a license of this package from 1 to 4, or input other license name :\033[0m')
968+
print ("\033[1;32;40m[1:Apache-2.0]|[2:MIT]|[3:LGPL-2.1]|[4:GPL-2.0]\033[0m")
969+
license_index = ('Apache-2.0', 'MIT', 'LGPL-2.1', 'GPL-2.0')
970+
license_class = raw_input()
971+
while license_class == '' :
972+
print ('\033[1;31;40mError: you must choose or input a license of this package. Try again.\033[0m')
973+
license_class = raw_input()
974+
975+
if license_class.isdigit()== True and int(license_class) >= 1 and int(license_class) <= 4:
976+
license = license_index[int(license_class) - 1]
977+
else :
978+
license = license_class
979+
980+
#seventh step
981+
print ('\033[5;33;40m\n7.Please input the repository of this package :\033[0m')
982+
print ("\033[1;32;40mFor example, hello package's repository url is 'https://github.com/RT-Thread-packages/hello'.\033[0m")
983+
984+
repository = raw_input()
985+
while repository == '':
986+
print ('\033[1;31;40mError: you must input a repository of this package. Try again.\033[0m')
987+
repository = raw_input()
945988

946989
pkg_path = name
947990
if not os.path.exists(pkg_path):
948991
os.mkdir(pkg_path)
949992
else:
950-
print ("Error: the package directory is exits!")
993+
print ("\033[1;31;40mError: the package directory is exits!\033[0m")
951994

952995
s = Template(Kconfig_file)
953996
uppername = str.upper(name)
@@ -958,14 +1001,13 @@ def package_wizard():
9581001
f.close()
9591002

9601003
s = Template(Package_json_file)
961-
package = s.substitute(
962-
name=name, description=description, version=ver, keyword=keyword)
1004+
package = s.substitute(name=name, pkgsclass=pkgsclass,authorname=authorname,authoremail=authoremail, description=description, version=ver, keyword=keyword,license=license, repository=repository)
9631005
f = file(os.path.join(pkg_path, 'package.json'), 'wb')
9641006
f.write(package)
9651007
f.close()
9661008

967-
print ('\nThe package index was created successfully.')
968-
1009+
print ('\nThe package index has been created \033[1;32;40msuccessfully\033[0m.')
1010+
print ('Please \033[5;34;40mupdate\033[0m other information of this package based on Kconfig and package.json in directory '+name+'.')
9691011

9701012
def upgrade_packages_index():
9711013
"""Update the package repository index."""

package.py

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
# Change Logs:
2222
# Date Author Notes
2323
# 2018-5-28 SummerGift Add copyright information
24+
# 2018-12-28 Ernest Chen Add package information and enjoy package maker
2425
#
2526

2627
import os
@@ -79,17 +80,36 @@
7980
8081
'''
8182

82-
Package_json_file = '''
83-
{
84-
"name": "${name}",
85-
"description": "${description}",
86-
"keywords": [
87-
"${keyword}"
88-
],
89-
"site" : [
90-
{"version" : "v${version}", "URL" : "https://${name}-${version}.zip", "filename" : "${name}-${version}.zip","VER_SHA" : "fill in the git version SHA value"},
91-
{"version" : "latest", "URL" : "https://xxxxx.git", "filename" : "Null for git package","VER_SHA" : "fill in latest version branch name, such as master"}
92-
]
83+
Package_json_file = '''{
84+
"name": "${name}",
85+
"description": "${description}",
86+
"keywords": [
87+
"${keyword}"
88+
],
89+
"category": "${pkgsclass}",
90+
"author": {
91+
"name": "${authorname}",
92+
"email": "${authoremail}"
93+
},
94+
"license": "${license}",
95+
"repository": "${repository}",
96+
"icon": "unknown",
97+
"homepage": "unknown",
98+
"doc": "unknown",
99+
"site": [
100+
{
101+
"version": "v${version}",
102+
"URL": "https://${name}-${version}.zip",
103+
"filename": "${name}-${version}.zip",
104+
"VER_SHA": "fill in the git version SHA value"
105+
},
106+
{
107+
"version": "latest",
108+
"URL": "https://xxxxx.git",
109+
"filename": "Null for git package",
110+
"VER_SHA": "fill in latest version branch name, such as master"
111+
}
112+
]
93113
}
94114
'''
95115

0 commit comments

Comments
 (0)