Skip to content

Commit 1aa9491

Browse files
add Information statistics (#145)
* add Information statistics * Remove printing
1 parent f7c1f55 commit 1aa9491

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

cmds/Kconfig

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,12 @@ config SYS_PKGS_DOWNLOAD_ACCELERATE
3131
bool "Use China Mainland server"
3232
default y
3333

34+
config SYS_PKGS_USING_STATISTICS
35+
bool "Send usage data for improve product"
36+
default y
37+
help
38+
Reads the user's mac address and returns it to the rt-thread official,
39+
which is used to count the number of users
40+
3441
endmenu
3542

cmds/cmd_package/cmd_package_upgrade.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,23 @@
2424
#
2525

2626
import os
27+
import uuid
2728
from vars import Import
2829
from .cmd_package_utils import git_pull_repo, get_url_from_mirror_server, find_macro_in_config
2930
from .cmd_package_update import need_using_mirror_download
3031

32+
try:
33+
import requests
34+
except ImportError:
35+
print("****************************************\n"
36+
"* Import requests module error.\n"
37+
"* Please install requests module first.\n"
38+
"* pip install step:\n"
39+
"* $ pip install requests\n"
40+
"* command install step:\n"
41+
"* $ sudo apt-get install python-requests\n"
42+
"****************************************\n")
43+
3144

3245
def upgrade_packages_index(force_upgrade=False):
3346
"""Update the package repository index."""
@@ -104,9 +117,31 @@ def upgrade_env_script():
104117
git_pull_repo(env_scripts_root, env_scripts_repo)
105118
print("==============================> Env scripts upgrade done \n")
106119

120+
def get_mac_address():
121+
mac=uuid.UUID(int = uuid.getnode()).hex[-12:]
122+
return ":".join([mac[e:e+2] for e in range(0,11,2)])
123+
124+
125+
def Information_statistics():
126+
127+
env_root = Import('env_root')
128+
129+
# get the .config file from env
130+
env_kconfig_path = os.path.join(env_root, 'tools\scripts\cmds')
131+
env_config_file = os.path.join(env_kconfig_path, '.config')
132+
133+
mac_addr = get_mac_address()
134+
env_config_file = os.path.join(env_kconfig_path, '.config')
135+
if find_macro_in_config(env_config_file, 'SYS_PKGS_USING_STATISTICS'):
136+
response = requests.get('https://www.rt-thread.org/studio/statistics/api/envuse?userid='+str(mac_addr)+'&username='+str(mac_addr)+'&envversion=1.0&studioversion=2.0&ip=127.0.0.1')
137+
if response.status_code != 200:
138+
return
139+
else:
140+
return
107141

108142
def package_upgrade(force_upgrade=False):
109143
"""Update the package repository directory and env function scripts."""
110144

145+
Information_statistics()
111146
upgrade_packages_index(force_upgrade=force_upgrade)
112147
upgrade_env_script()

0 commit comments

Comments
 (0)