From ca9ea501f60719b7032dfb0485fe43ef9843ecc4 Mon Sep 17 00:00:00 2001 From: wugensheng <82647680+wugensheng-code@users.noreply.github.com> Date: Wed, 2 Mar 2022 18:30:31 +0800 Subject: [PATCH 1/4] add Information statistics --- cmds/Kconfig | 7 +++++ cmds/cmd_package/cmd_package_upgrade.py | 37 +++++++++++++++++++++++++ 2 files changed, 44 insertions(+) diff --git a/cmds/Kconfig b/cmds/Kconfig index f8084a92..cbc7543a 100644 --- a/cmds/Kconfig +++ b/cmds/Kconfig @@ -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 diff --git a/cmds/cmd_package/cmd_package_upgrade.py b/cmds/cmd_package/cmd_package_upgrade.py index c2b1ed79..c80a9adc 100644 --- a/cmds/cmd_package/cmd_package_upgrade.py +++ b/cmds/cmd_package/cmd_package_upgrade.py @@ -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.""" @@ -104,9 +117,33 @@ 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'): + print('start information 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: + print("Information statistics failed") + 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() From cd58f92666f010bc301c9b7fce8128e71805acb8 Mon Sep 17 00:00:00 2001 From: wugensheng <82647680+wugensheng-code@users.noreply.github.com> Date: Wed, 2 Mar 2022 18:49:41 +0800 Subject: [PATCH 2/4] Remove printing --- cmds/cmd_package/cmd_package_upgrade.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/cmds/cmd_package/cmd_package_upgrade.py b/cmds/cmd_package/cmd_package_upgrade.py index c80a9adc..b8a442a1 100644 --- a/cmds/cmd_package/cmd_package_upgrade.py +++ b/cmds/cmd_package/cmd_package_upgrade.py @@ -133,10 +133,8 @@ def Information_statistics(): 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'): - print('start information 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: - print("Information statistics failed") return else: return From bda48f434dde78f40fea9df72f505430c934000a Mon Sep 17 00:00:00 2001 From: shinu Date: Fri, 6 May 2022 12:09:00 +0800 Subject: [PATCH 3/4] Modify the information statistics code --- cmds/cmd_package/cmd_package_upgrade.py | 19 -------- statistics.py | 60 +++++++++++++++++++++++++ 2 files changed, 60 insertions(+), 19 deletions(-) create mode 100644 statistics.py diff --git a/cmds/cmd_package/cmd_package_upgrade.py b/cmds/cmd_package/cmd_package_upgrade.py index b8a442a1..7c48c227 100644 --- a/cmds/cmd_package/cmd_package_upgrade.py +++ b/cmds/cmd_package/cmd_package_upgrade.py @@ -121,27 +121,8 @@ 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() diff --git a/statistics.py b/statistics.py new file mode 100644 index 00000000..0b0ece40 --- /dev/null +++ b/statistics.py @@ -0,0 +1,60 @@ +# -*- coding:utf-8 -*- +# +# File : vars.py +# This file is part of RT-Thread RTOS +# COPYRIGHT (C) 2006 - 2018, RT-Thread Development Team +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with this program; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +# +# Change Logs: +# Date Author Notes +# 2022-5-6 WuGenSheng Add copyright information +# +import os +import uuid + +import requests + +from vars import Import + +from cmds import * + + +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(): + # get the .config file from env + env_kconfig_path = os.path.join(os.getcwd(), 'tools\\scripts\\cmdscmds') + 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 not os.path.isfile(env_config_file): + try: + 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 + except Exception as e: + exit(0) + elif os.path.isfile(env_config_file) and cmd_package.find_macro_in_config(env_config_file, 'SYS_PKGS_NOT_USING_STATISTICS'): + return True + + +if __name__ == '__main__': + Information_statistics() From 39c7f0b5ce98487bc1bd0c5de79f20de5df0c135 Mon Sep 17 00:00:00 2001 From: shinu Date: Fri, 6 May 2022 12:22:13 +0800 Subject: [PATCH 4/4] Restore some code --- cmds/cmd_package/cmd_package_upgrade.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/cmds/cmd_package/cmd_package_upgrade.py b/cmds/cmd_package/cmd_package_upgrade.py index 7c48c227..9200d598 100644 --- a/cmds/cmd_package/cmd_package_upgrade.py +++ b/cmds/cmd_package/cmd_package_upgrade.py @@ -121,8 +121,26 @@ 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()