Skip to content

Commit

Permalink
add Information statistics (#145)
Browse files Browse the repository at this point in the history
* add Information statistics

* Remove printing
  • Loading branch information
wugensheng-code committed Mar 3, 2022
1 parent f7c1f55 commit 1aa9491
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
7 changes: 7 additions & 0 deletions cmds/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,12 @@ config SYS_PKGS_DOWNLOAD_ACCELERATE
bool "Use China Mainland server"
default y

config SYS_PKGS_USING_STATISTICS
bool "Send usage data for improve product"
default y
help
Reads the user's mac address and returns it to the rt-thread official,
which is used to count the number of users

endmenu

35 changes: 35 additions & 0 deletions cmds/cmd_package/cmd_package_upgrade.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,23 @@
#

import os
import uuid
from vars import Import
from .cmd_package_utils import git_pull_repo, get_url_from_mirror_server, find_macro_in_config
from .cmd_package_update import need_using_mirror_download

try:
import requests
except ImportError:
print("****************************************\n"
"* Import requests module error.\n"
"* Please install requests module first.\n"
"* pip install step:\n"
"* $ pip install requests\n"
"* command install step:\n"
"* $ sudo apt-get install python-requests\n"
"****************************************\n")


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

def get_mac_address():
mac=uuid.UUID(int = uuid.getnode()).hex[-12:]
return ":".join([mac[e:e+2] for e in range(0,11,2)])


def Information_statistics():

env_root = Import('env_root')

# get the .config file from env
env_kconfig_path = os.path.join(env_root, 'tools\scripts\cmds')
env_config_file = os.path.join(env_kconfig_path, '.config')

mac_addr = get_mac_address()
env_config_file = os.path.join(env_kconfig_path, '.config')
if find_macro_in_config(env_config_file, 'SYS_PKGS_USING_STATISTICS'):
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')
if response.status_code != 200:
return
else:
return

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

Information_statistics()
upgrade_packages_index(force_upgrade=force_upgrade)
upgrade_env_script()

0 comments on commit 1aa9491

Please sign in to comment.