Skip to content

Commit 30604a1

Browse files
authored
Merge pull request #66 from ErnestChen1/master
[add] some choices about package index
2 parents be636e2 + b08481c commit 30604a1

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-5-28 SummerGift Add copyright information
24+
# 2018-12-28 Ernest Chen Add package information and enjoy package maker
2425
#
2526

2627
import os
@@ -893,52 +894,94 @@ def package_update(isDeleteOld=False):
893894
print ("Operation completed successfully.")
894895
else:
895896
print ("Operation failed.")
896-
897-
897+
898898
def package_wizard():
899899
"""Packages creation wizard.
900900
901901
The user enters the package name, version number, category, and automatically generates the package index file.
902902
"""
903-
904-
print ('Welcome to using package wizard, please enter the package information.')
905-
print ('The messages in [] is default setting. Press enter to use the default settings.')
906-
print ('Please enter package name:')
903+
# Welcome
904+
print ('\033[4;32;40mWelcome to using package wizard, please follow below steps.\033[0m\n')
905+
906+
#Simple introduction about the wizard
907+
print ('note :')
908+
print (' \033[5;35;40m[ ]\033[0m means default setting or optional information.')
909+
print (' \033[5;35;40mEnter\033[0m means using default option or ending and proceeding to the next step.')
910+
911+
#first step
912+
print ('\033[5;33;40m\n1.Please input a new package name :\033[0m')
907913
name = raw_input()
908-
if name == '':
909-
print ('Error: you must enter the package name. Try again.\n')
910-
return
914+
while name == '' or name.isspace() == True :
915+
print ('\033[1;31;40mError: you must input a package name. Try again.\033[0m')
916+
name = raw_input()
911917

912918
default_description = 'a ' + name + ' package for rt-thread'
913919
#description = user_input('menuconfig option name,default:\n',default_description)
914920
description = default_description
915-
ver = user_input('Version of this package, default:\n', '1.0.0')
921+
922+
#second step
923+
ver = user_input('\033[5;33;40m\n2.Please input this package version, default :\033[0m', '1.0.0')
916924
ver_standard = ver.replace('.', '')
917925
#keyword = user_input('keyword,default:\n', name)
918926
keyword = name
919927

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

937980
pkg_path = name
938981
if not os.path.exists(pkg_path):
939982
os.mkdir(pkg_path)
940983
else:
941-
print ("Error: the package directory is exits!")
984+
print ("\033[1;31;40mError: the package directory is exits!\033[0m")
942985

943986
s = Template(Kconfig_file)
944987
uppername = str.upper(name)
@@ -949,14 +992,13 @@ def package_wizard():
949992
f.close()
950993

951994
s = Template(Package_json_file)
952-
package = s.substitute(
953-
name=name, description=description, version=ver, keyword=keyword)
995+
package = s.substitute(name=name, pkgsclass=pkgsclass,authorname=authorname,authoremail=authoremail, description=description, version=ver, keyword=keyword,license=license, repository=repository)
954996
f = file(os.path.join(pkg_path, 'package.json'), 'wb')
955997
f.write(package)
956998
f.close()
957999

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

9611003
def upgrade_packages_index():
9621004
"""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)