Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(601)

Side by Side Diff: appengine/findit/util_scripts/crash_queries/delta_test/delta_util.py

Issue 2400283003: [Findit] Add skeleton code for delta test script. (Closed)
Patch Set: Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 # Copyright 2016 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
4
5 """Util functions for git repository processing."""
6
7 import base64
8 import json
9 import logging
10 import os
11 import pickle
12 import re
13 import subprocess
14 import traceback
15 import urllib2
16
17 import dev_appserver
18 dev_appserver.fix_sys_path()
19
20 from common import appengine_util
21
22 # TODO(katesonia): move host to azalea host after migration.
23 _FEEDBACK_URL_TEMPLATE = 'host/crash/fracas-result-feedback?key=%s'
24 GIT_HASH_PATTERN = re.compile(r'^[0-9a-fA-F]{40}$')
25
26
27 def IsGitHash(revision):
28 return GIT_HASH_PATTERN.match(str(revision)) or revision == 'master'
29
30
31 def ParseGitHash(revision):
32 """Gets git hash of a revision."""
33 if IsGitHash(revision):
34 return revision
35
36 try:
37 # Can parse revision like 'HEAD', 'HEAD~3'.
38 return subprocess.check_output(
39 ['git', 'rev-parse', revision]).replace('\n', '')
40 except: # pylint: disable=W
41 logging.error('Fail to parse git hash for %s\nStacktrace:\n%s',
42 revision, traceback.format_exc())
43 return None
44
45
46 def EnsureDirExists(path):
47 directory = os.path.dirname(path)
48 if os.path.exists(directory):
49 return
50
51 os.makedirs(directory)
52
53
54 def FlushResult(result, result_path):
55 logging.info('\nFlushing results to %s', result_path)
56 EnsureDirExists(result_path)
57 with open(result_path, 'wb') as f:
58 pickle.dump(result, f)
59
60
61 def PrintDelta(deltas, crash_num):
62 logging.info(('\n+++++++++++++++++++'
63 ' Delta on %d crashes '
64 '+++++++++++++++++++++'), crash_num)
65
66 if not deltas:
67 logging.info('Two sets of results are the same.')
68 return
69
70 for crash_id, delta in deltas.iteritems():
71 logging.info('Crash: %s', _FEEDBACK_URL_TEMPLATE % crash_id)
72 logging.info(delta.ToString())
73
74
75 def WriteDeltaToCSV(deltas, crash_num, git_hash1, git_hash2, file_path):
76 logging.info('Writing delta diff to %s\n', file_path)
77 EnsureDirExists(file_path)
78
79 def _EncodeStr(string):
80 return string.replace('\"', '\'') if string else ''
81
82 with open(file_path, 'wb') as f:
83 f.write('Delta between githash1 %s and githash2 %s on %d crashes\n' % (
84 git_hash1, git_hash2, crash_num))
85 f.write('project, components, cls, regression_range\n')
86 for crash_id, delta in deltas.iteritems():
87 delta_str_dict = delta.delta_str_dict
88 feedback_url = _FEEDBACK_URL_TEMPLATE % crash_id
89 f.write('%s, "%s", "%s", "%s", "%s"\n' % (
90 feedback_url,
91 _EncodeStr(delta_str_dict.get('project', '')),
92 _EncodeStr(delta_str_dict.get('components', '')),
93 _EncodeStr(delta_str_dict.get('cls', '')),
94 _EncodeStr(delta_str_dict.get('regression_range', ''))
95 ))
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698