Skip to content
Snippets Groups Projects
Commit 67c76fd7 authored by android-build-team Robot's avatar android-build-team Robot
Browse files

Snap for 5280121 from 197c6fbd to qt-release

Change-Id: I3d43621fa2734c59b1441ad0c0f8f7906d7a378d
parents 378d3006 197c6fbd
No related branches found
No related tags found
No related merge requests found
......@@ -27,6 +27,7 @@ python_binary_host {
name: "external_updater_notifier",
main: "notifier.py",
srcs: [
"git_utils.py",
"notifier.py",
],
}
......
......@@ -26,8 +26,8 @@ class ZipFileWithPermission(zipfile.ZipFile):
See https://bugs.python.org/issue15795
"""
def extract(self, member, path=None, pwd=None):
ret_val = super().extract(member, path, pwd)
def _extract_member(self, member, targetpath, pwd):
ret_val = super()._extract_member(member, targetpath, pwd)
if not isinstance(member, zipfile.ZipInfo):
member = self.getinfo(member)
......
......@@ -129,20 +129,22 @@ def _process_update_result(path):
def _check_some(paths, delay):
results = {}
for path in paths:
results[path] = _process_update_result(path)
relative_path = fileutils.get_relative_project_path(path)
results[relative_path] = _process_update_result(path)
time.sleep(delay)
return results
def _check_all(delay):
results = {}
for path, dirs, files in os.walk(args.path):
for path, dirs, files in os.walk(fileutils.EXTERNAL_PATH):
dirs.sort(key=lambda d: d.lower())
if fileutils.METADATA_FILENAME in files:
# Skip sub directories.
dirs[:] = []
results[path] = _process_update_result(path)
time.sleep(delay)
relative_path = fileutils.get_relative_project_path(path)
results[relative_path] = _process_update_result(path)
time.sleep(delay)
return results
......@@ -204,7 +206,7 @@ def _do_update(args):
git_utils.push(full_path, args.remote_name)
if args.branch_and_commit:
git_utils.checkout(full_path, 'aosp/master')
git_utils.checkout(full_path, args.remote_name + '/master')
def parse_args():
......@@ -226,7 +228,7 @@ def parse_args():
'--json_output',
help='Path of a json file to write result to.')
check_parser.add_argument(
'--all',
'--all', action='store_true',
help='If set, check updates for all supported projects.')
check_parser.add_argument(
'--delay', default=0, type=int,
......
......@@ -21,6 +21,7 @@ external_updater_notifier \
googletest
"""
from datetime import timedelta, datetime
import argparse
import json
import os
......@@ -28,6 +29,7 @@ import re
import subprocess
import time
import git_utils
def parse_args():
"""Parses commandline arguments."""
......@@ -48,6 +50,9 @@ def parse_args():
parser.add_argument(
'paths', nargs='*',
help='Paths of the project.')
parser.add_argument(
'--all', action='store_true',
help='Checks all projects.')
return parser.parse_args()
......@@ -73,6 +78,22 @@ def _send_email(proj, latest_ver, recipient, upgrade_log):
input=msg, encoding='ascii')
NOTIFIED_TIME_KEY_NAME = 'latest_notified_time'
def _should_notify(latest_ver, proj_history):
if latest_ver in proj_history:
# Processed this version before.
return False
timestamp = proj_history.get(NOTIFIED_TIME_KEY_NAME, 0)
time_diff = datetime.today() - datetime.fromtimestamp(timestamp)
if git_utils.is_commit(latest_ver) and time_diff <= timedelta(days=30):
return False
return True
def _process_results(args, history, results):
for proj, res in results.items():
if 'latest' not in res:
......@@ -82,11 +103,12 @@ def _process_results(args, history, results):
if latest_ver == current_ver:
continue
proj_history = history.setdefault(proj, {})
if latest_ver not in proj_history:
if _should_notify(latest_ver, proj_history):
upgrade_log = _upgrade(proj) if args.generate_change else ""
try:
_send_email(proj, latest_ver, args.recipients, upgrade_log)
proj_history[latest_ver] = int(time.time())
proj_history[NOTIFIED_TIME_KEY_NAME] = int(time.time())
except subprocess.CalledProcessError as err:
msg = """Failed to send email for {} ({}).
stdout: {}
......@@ -112,7 +134,7 @@ def send_notification(args):
_process_results(args, history, results)
with open(args.history, 'w') as f:
json.dump(history, f, sort_keys=True)
json.dump(history, f, sort_keys=True, indent=4)
def _upgrade(proj):
......@@ -136,11 +158,15 @@ def _upgrade(proj):
def _check_updates(args):
subprocess.run(['out/soong/host/linux-x86/bin/external_updater',
'check',
'--json_output', RESULT_FILE_PATH,
'--delay', '0'] + args.paths,
cwd=os.environ['ANDROID_BUILD_TOP'])
params = ['out/soong/host/linux-x86/bin/external_updater',
'check', '--json_output', RESULT_FILE_PATH,
'--delay', '30']
if args.all:
params.append('--all')
else:
params += args.paths
subprocess.run(params, cwd=os.environ['ANDROID_BUILD_TOP'])
def main():
......
......@@ -80,10 +80,9 @@ def _match_and_get_version(prefix, suffix, version):
except ValueError:
return []
if version_prefix != prefix or version_suffix != suffix:
return []
right_format = (version_prefix == prefix and version_suffix == suffix)
return [int(v) for v in version.split('.')]
return [right_format] + [int(v) for v in version.split('.')]
def get_latest_version(current_version, version_list):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment