代码拉取完成,页面将自动刷新
同步操作将从 阿超/rtthread-packages 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
# coding=utf-8
import sys
import os
import stat
import time
import datetime
import subprocess
import shlex
import shutil
import json
import requests
def execute_command(cmdstring, cwd=None, shell=True):
"""Execute the system command at the specified address."""
if shell:
cmdstring_list = cmdstring
sub = subprocess.Popen(cmdstring_list, cwd=cwd, stdin=subprocess.PIPE,
stdout=subprocess.PIPE, shell=shell, bufsize=4096)
stdout_str = ''
while sub.poll() is None:
stdout_str += sub.stdout.read()
time.sleep(0.1)
return stdout_str
def determine_url_valid(url_from_srv):
"""Check the validity of urls."""
headers = {'Connection': 'keep-alive',
'Accept-Encoding': 'gzip, deflate',
'Accept': '*/*',
'User-Agent': 'curl/7.54.0'}
try:
for i in range(0, 3):
r = requests.get(url_from_srv, stream=True, headers=headers)
if r.status_code == requests.codes.not_found:
if i == 2:
print("Warning : %s is invalid." % url_from_srv)
return False
time.sleep(1)
else:
break
return True
except Exception, e:
# print('e.message:%s\t' % e.message)
print('Network connection error or the url : %s is invalid.\n' %
url_from_srv)
def check_json_file(work_root):
"""Check the json file."""
file_count = 1
folder_walk_result = os.walk(work_root)
for path, d, filelist in folder_walk_result:
for filename in filelist:
if filename == 'package.json':
json_pathname = os.path.join(path, 'package.json')
print("\nNo.%d" % file_count)
file_count += 1
if not json_file_content_check(json_pathname):
return False
return True
def json_file_content_check(json_pathname):
"""Check the content of json file."""
with open(json_pathname, 'r+') as f:
json_content = f.read()
package_info = json.loads(json_content)
print(package_info['name'])
if package_info['category'] == '' :
print ('The category of ' + package_info['name'] + ' package is lost.')
return False
if package_info['author']['name'] == '' :
print ('The author name of ' + package_info['name'] + ' package is lost.')
return False
if package_info['author']['email'] == '' :
print ('The author email of ' + package_info['name'] + ' package is lost.')
return False
if package_info['license'] == '' :
print ('The license of ' + package_info['name'] + ' package is lost.')
return False
if package_info['repository'] == '' :
print ('The repository of ' + package_info['name'] + ' package is lost.')
return False
else :
if not determine_url_valid(package_info['repository']):
return False
for i in range(0, len(package_info['site'])):
package_version = package_info['site'][i]['version']
package_url = package_info['site'][i]['URL']
print("%s : %s" % (package_version, package_url))
if not package_url[-4:] == '.git':
print(package_info['site'][i]['filename'])
if not determine_url_valid(package_url):
return False
return True
def main():
"""The entry point of the script."""
try:
work_root = os.getcwd()
print(work_root)
if not check_json_file(work_root):
sys.exit(1)
sys.exit(0)
except Exception, e:
print('error.message: %s\n\t' % (e.message))
sys.exit(1)
if __name__ == '__main__':
main()
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。