forked from GoogleChrome/chromium-dashboard
-
Notifications
You must be signed in to change notification settings - Fork 0
/
models.py
1689 lines (1407 loc) · 65.1 KB
/
models.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
from __future__ import division
from __future__ import print_function
# -*- coding: utf-8 -*-
# Copyright 2020 Google Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License")
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import collections
import datetime
import json
import logging
import re
import time
from google.appengine.ext import db
# from google.appengine.ext.db import djangoforms
from google.appengine.api import mail
import ramcache
from google.appengine.api import urlfetch
from google.appengine.api import users
import cloud_tasks_helpers
import common
import settings
import util
import hack_components
import hack_wf_components
#from django.forms import ModelForm
from collections import OrderedDict
from django import forms
# import google.appengine.ext.django as django
SIMPLE_TYPES = (int, long, float, bool, dict, basestring, list)
WEBCOMPONENTS = 1
MISC = 2
SECURITY = 3
MULTIMEDIA = 4
DOM = 5
FILE = 6
OFFLINE = 7
DEVICE = 8
COMMUNICATION = 9
JAVASCRIPT = 10
NETWORKING = 11
INPUT = 12
PERFORMANCE = 13
GRAPHICS = 14
CSS = 15
HOUDINI = 16
SERVICEWORKER = 17
WEBRTC = 18
LAYERED = 19
WEBASSEMBLY = 20
CAPABILITIES = 21
FEATURE_CATEGORIES = {
CSS: 'CSS',
WEBCOMPONENTS: 'Web Components',
MISC: 'Miscellaneous',
SECURITY: 'Security',
MULTIMEDIA: 'Multimedia',
DOM: 'DOM',
FILE: 'File APIs',
OFFLINE: 'Offline / Storage',
DEVICE: 'Device',
COMMUNICATION: 'Realtime / Communication',
JAVASCRIPT: 'JavaScript',
NETWORKING: 'Network / Connectivity',
INPUT: 'User input',
PERFORMANCE: 'Performance',
GRAPHICS: 'Graphics',
HOUDINI: 'Houdini',
SERVICEWORKER: 'Service Worker',
WEBRTC: 'Web RTC',
LAYERED: 'Layered APIs',
WEBASSEMBLY: 'WebAssembly',
CAPABILITIES: 'Capabilities (Fugu)'
}
FEATURE_TYPE_INCUBATE_ID = 0
FEATURE_TYPE_EXISTING_ID = 1
FEATURE_TYPE_CODE_CHANGE_ID = 2
FEATURE_TYPE_DEPRECATION_ID = 3
FEATURE_TYPES = {
FEATURE_TYPE_INCUBATE_ID: 'New feature incubation',
FEATURE_TYPE_EXISTING_ID: 'Existing feature implementation',
FEATURE_TYPE_CODE_CHANGE_ID: 'Web developer facing change to existing code',
FEATURE_TYPE_DEPRECATION_ID: 'Feature deprecation',
}
# Intent stages and mapping from stage to stage name.
INTENT_NONE = 0
INTENT_INCUBATE = 7 # Start incubating
INTENT_IMPLEMENT = 1 # Start prototyping
INTENT_EXPERIMENT = 2 # Dev trials
INTENT_IMPLEMENT_SHIP = 4 # Eval readiness to ship
INTENT_EXTEND_TRIAL = 3 # Origin trials
INTENT_SHIP = 5 # Prepare to ship
INTENT_REMOVED = 6
INTENT_SHIPPED = 8
INTENT_PARKED = 9
INTENT_STAGES = collections.OrderedDict([
(INTENT_NONE, 'None'),
(INTENT_INCUBATE, 'Start incubating'),
(INTENT_IMPLEMENT, 'Start prototyping'),
(INTENT_EXPERIMENT, 'Dev trials'),
(INTENT_IMPLEMENT_SHIP, 'Evaluate readiness to ship'),
(INTENT_EXTEND_TRIAL, 'Origin Trial'),
(INTENT_SHIP, 'Prepare to ship'),
(INTENT_REMOVED, 'Removed'),
(INTENT_SHIPPED, 'Shipped'),
(INTENT_PARKED, 'Parked'),
])
NO_ACTIVE_DEV = 1
PROPOSED = 2
IN_DEVELOPMENT = 3
BEHIND_A_FLAG = 4
ENABLED_BY_DEFAULT = 5
DEPRECATED = 6
REMOVED = 7
ORIGIN_TRIAL = 8
INTERVENTION = 9
ON_HOLD = 10
NO_LONGER_PURSUING = 1000 # insure bottom of list
RELEASE_IMPL_STATES = {
BEHIND_A_FLAG, ENABLED_BY_DEFAULT,
DEPRECATED, REMOVED, ORIGIN_TRIAL, INTERVENTION,
}
# Ordered dictionary, make sure the order of this dictionary matches that of
# the sorted list above!
IMPLEMENTATION_STATUS = OrderedDict()
IMPLEMENTATION_STATUS[NO_ACTIVE_DEV] = 'No active development'
IMPLEMENTATION_STATUS[PROPOSED] = 'Proposed'
IMPLEMENTATION_STATUS[IN_DEVELOPMENT] = 'In development'
IMPLEMENTATION_STATUS[BEHIND_A_FLAG] = 'In developer trial (Behind a flag)'
IMPLEMENTATION_STATUS[ENABLED_BY_DEFAULT] = 'Enabled by default'
IMPLEMENTATION_STATUS[DEPRECATED] = 'Deprecated'
IMPLEMENTATION_STATUS[REMOVED] = 'Removed'
IMPLEMENTATION_STATUS[ORIGIN_TRIAL] = 'Origin trial'
IMPLEMENTATION_STATUS[INTERVENTION] = 'Browser Intervention'
IMPLEMENTATION_STATUS[ON_HOLD] = 'On hold'
IMPLEMENTATION_STATUS[NO_LONGER_PURSUING] = 'No longer pursuing'
MAJOR_NEW_API = 1
MAJOR_MINOR_NEW_API = 2
SUBSTANTIVE_CHANGES = 3
MINOR_EXISTING_CHANGES = 4
EXTREMELY_SMALL_CHANGE = 5
# Status for security and privacy reviews.
REVIEW_PENDING = 1
REVIEW_ISSUES_OPEN = 2
REVIEW_ISSUES_ADDRESSED = 3
REVIEW_NA = 4
REVIEW_STATUS_CHOICES = {
REVIEW_PENDING: 'Pending',
REVIEW_ISSUES_OPEN: 'Issues open',
REVIEW_ISSUES_ADDRESSED: 'Issues addressed',
REVIEW_NA: 'Not applicable',
}
FOOTPRINT_CHOICES = {
MAJOR_NEW_API: ('A major new independent API (e.g. adding many '
'independent concepts with many methods/properties/objects)'),
MAJOR_MINOR_NEW_API: ('Major changes to an existing API OR a minor new '
'independent API (e.g. adding many new '
'methods/properties or introducing new concepts to '
'augment an existing API)'),
SUBSTANTIVE_CHANGES: ('Substantive changes to an existing API (e.g. small '
'number of new methods/properties)'),
MINOR_EXISTING_CHANGES: (
'Minor changes to an existing API (e.g. adding a new keyword/allowed '
'argument to a property/method)'),
EXTREMELY_SMALL_CHANGE: ('Extremely small tweaks to an existing API (e.g. '
'how existing keywords/arguments are interpreted)'),
}
MAINSTREAM_NEWS = 1
WARRANTS_ARTICLE = 2
IN_LARGER_ARTICLE = 3
SMALL_NUM_DEVS = 4
SUPER_SMALL = 5
# Signals from other implementations in an intent-to-ship
SHIPPED = 1
IN_DEV = 2
PUBLIC_SUPPORT = 3
MIXED_SIGNALS = 4 # Deprecated
NO_PUBLIC_SIGNALS = 5
PUBLIC_SKEPTICISM = 6 # Deprecated
OPPOSED = 7
NEUTRAL = 8
SIGNALS_NA = 9
GECKO_UNDER_CONSIDERATION = 10
GECKO_IMPORTANT = 11
GECKO_WORTH_PROTOTYPING = 12
GECKO_NONHARMFUL = 13
GECKO_DEFER = 14
GECKO_HARMFUL = 15
VENDOR_VIEWS_COMMON = {
SHIPPED: 'Shipped/Shipping',
IN_DEV: 'In development',
PUBLIC_SUPPORT: 'Positive',
NO_PUBLIC_SIGNALS: 'No signal',
OPPOSED: 'Negative',
NEUTRAL: 'Neutral',
SIGNALS_NA: 'N/A',
}
VENDOR_VIEWS_GECKO = VENDOR_VIEWS_COMMON.copy()
VENDOR_VIEWS_GECKO.update({
GECKO_UNDER_CONSIDERATION: 'Under consideration',
GECKO_IMPORTANT: 'Important',
GECKO_WORTH_PROTOTYPING: 'Worth prototyping',
GECKO_NONHARMFUL: 'Non-harmful',
GECKO_DEFER: 'Defer',
GECKO_HARMFUL: 'Harmful',
})
# These vendors have no "custom" views values yet.
VENDOR_VIEWS_EDGE = VENDOR_VIEWS_COMMON
VENDOR_VIEWS_WEBKIT = VENDOR_VIEWS_COMMON
VENDOR_VIEWS = {}
VENDOR_VIEWS.update(VENDOR_VIEWS_GECKO)
VENDOR_VIEWS.update(VENDOR_VIEWS_EDGE)
VENDOR_VIEWS.update(VENDOR_VIEWS_WEBKIT)
DEFACTO_STD = 1
ESTABLISHED_STD = 2
WORKING_DRAFT = 3
EDITORS_DRAFT = 4
PUBLIC_DISCUSSION = 5
NO_STD_OR_DISCUSSION = 6
STANDARDIZATION = {
DEFACTO_STD: 'De-facto standard',
ESTABLISHED_STD: 'Established standard',
WORKING_DRAFT: 'Working draft or equivalent',
EDITORS_DRAFT: "Editor's draft",
PUBLIC_DISCUSSION: 'Public discussion',
NO_STD_OR_DISCUSSION: 'No public standards discussion',
}
DEV_STRONG_POSITIVE = 1
DEV_POSITIVE = 2
DEV_MIXED_SIGNALS = 3
DEV_NO_SIGNALS = 4
DEV_NEGATIVE = 5
DEV_STRONG_NEGATIVE = 6
WEB_DEV_VIEWS = {
DEV_STRONG_POSITIVE: 'Strongly positive',
DEV_POSITIVE: 'Positive',
DEV_MIXED_SIGNALS: 'Mixed signals',
DEV_NO_SIGNALS: 'No signals',
DEV_NEGATIVE: 'Negative',
DEV_STRONG_NEGATIVE: 'Strongly negative',
}
PROPERTY_NAMES_TO_ENUM_DICTS = {
'category': FEATURE_CATEGORIES,
'intent_stage': INTENT_STAGES,
'impl_status_chrome': IMPLEMENTATION_STATUS,
'security_review_status': REVIEW_STATUS_CHOICES,
'privacy_review_status': REVIEW_STATUS_CHOICES,
'standardization': STANDARDIZATION,
'ff_views': VENDOR_VIEWS,
'ie_views': VENDOR_VIEWS,
'safari_views': VENDOR_VIEWS,
'web_dev_views': WEB_DEV_VIEWS,
}
def convert_enum_int_to_string(property_name, value):
"""If the property is an enum, return human-readable string, else value."""
if type(value) != int:
return value
enum_dict = PROPERTY_NAMES_TO_ENUM_DICTS.get(property_name, {})
converted_value = enum_dict.get(value, value)
return converted_value
def del_none(d):
"""
Delete dict keys with None values, and empty lists, recursively.
"""
for key, value in d.items():
if value is None or (isinstance(value, list) and len(value) == 0):
del d[key]
elif isinstance(value, dict):
del_none(value)
return d
class DictModel(db.Model):
# def to_dict(self):
# return dict([(p, unicode(getattr(self, p))) for p in self.properties()])
def format_for_template(self):
d = self.to_dict()
d['id'] = self.key().id()
return d
def to_dict(self):
output = {}
for key, prop in self.properties().iteritems():
value = getattr(self, key)
if value is None or isinstance(value, SIMPLE_TYPES):
output[key] = value
elif isinstance(value, datetime.date):
# Convert date/datetime to ms-since-epoch ("new Date()").
#ms = time.mktime(value.utctimetuple())
#ms += getattr(value, 'microseconds', 0) / 1000
#output[key] = int(ms)
output[key] = unicode(value)
elif isinstance(value, db.GeoPt):
output[key] = {'lat': value.lat, 'lon': value.lon}
elif isinstance(value, db.Model):
output[key] = to_dict(value)
elif isinstance(value, users.User):
output[key] = value.email()
else:
raise ValueError('cannot encode ' + repr(prop))
return output
class BlinkComponent(DictModel):
DEFAULT_COMPONENT = 'Blink'
COMPONENTS_URL = 'https://blinkcomponents-b48b5.firebaseapp.com'
COMPONENTS_ENDPOINT = '%s/blinkcomponents' % COMPONENTS_URL
WF_CONTENT_ENDPOINT = '%s/wfcomponents' % COMPONENTS_URL
name = db.StringProperty(required=True, default=DEFAULT_COMPONENT)
created = db.DateTimeProperty(auto_now_add=True)
updated = db.DateTimeProperty(auto_now=True)
@property
def subscribers(self):
return FeatureOwner.all().filter('blink_components = ', self.key()).order('name').fetch(None)
@property
def owners(self):
return FeatureOwner.all().filter('primary_blink_components = ', self.key()).order('name').fetch(None)
@classmethod
def fetch_all_components(self, update_cache=False):
"""Returns the list of blink components from live endpoint if unavailable in the cache."""
key = 'blinkcomponents'
components = ramcache.get(key)
if components is None or update_cache:
components = []
url = self.COMPONENTS_ENDPOINT + '?cache-buster=%s' % time.time()
result = urlfetch.fetch(url, deadline=60)
if result.status_code == 200:
components = sorted(json.loads(result.content))
ramcache.set(key, components)
else:
logging.error('Fetching blink components returned: %s' % result.status_code)
if not components:
components = sorted(hack_components.HACK_BLINK_COMPONENTS)
logging.info('using hard-coded blink components')
return components
@classmethod
def fetch_wf_content_for_components(self, update_cache=False):
"""Returns the /web content that use each blink component."""
key = 'wfcomponents'
components = ramcache.get(key)
if components is None or update_cache:
components = {}
url = self.WF_CONTENT_ENDPOINT + '?cache-buster=%s' % time.time()
try:
result = urlfetch.fetch(url, deadline=50)
if result.status_code == 200:
components = json.loads(result.content)
ramcache.set(key, components)
else:
logging.error('Fetching /web blink components content returned: %s' % result.status_code)
except urlfetch.DeadlineExceededError:
logging.info('deadline exceeded when fetching %r', url)
if not components:
components = hack_wf_components.HACK_WF_COMPONENTS
logging.info('using hard-coded WF components')
return components
@classmethod
def update_db(self):
"""Updates the db with new Blink components from the json endpoint"""
self.fetch_wf_content_for_components(update_cache=True) # store /web content in cache
new_components = self.fetch_all_components(update_cache=True)
existing_comps = self.all().fetch(None)
for name in new_components:
if not len([x.name for x in existing_comps if x.name == name]):
logging.info('Adding new BlinkComponent: ' + name)
c = BlinkComponent(name=name)
c.put()
@classmethod
def get_by_name(self, component_name):
"""Fetch blink component with given name."""
q = self.all()
q.filter('name =', component_name)
component = q.fetch(1)
if not component:
logging.error('%s is an unknown BlinkComponent.' % (component_name))
return None
return component[0]
# UMA metrics.
class StableInstance(DictModel):
created = db.DateTimeProperty(auto_now_add=True)
updated = db.DateTimeProperty(auto_now=True)
property_name = db.StringProperty(required=True)
bucket_id = db.IntegerProperty(required=True)
date = db.DateProperty(verbose_name='When the data was fetched',
required=True)
#hits = db.IntegerProperty(required=True)
#total_pages = db.IntegerProperty()
day_percentage = db.FloatProperty()
rolling_percentage = db.FloatProperty()
class AnimatedProperty(StableInstance):
pass
class FeatureObserver(StableInstance):
pass
# Feature dashboard.
class Feature(DictModel):
"""Container for a feature."""
DEFAULT_CACHE_KEY = 'features'
@classmethod
def _first_of_milestone(self, feature_list, milestone, start=0):
for i in xrange(start, len(feature_list)):
f = feature_list[i]
if (str(f['shipped_milestone']) == str(milestone) or
f['impl_status_chrome'] == str(milestone)):
return i
elif (f['shipped_milestone'] == None and
str(f['shipped_android_milestone']) == str(milestone)):
return i
return -1
@classmethod
def _first_of_milestone_v2(self, feature_list, milestone, start=0):
for i in xrange(start, len(feature_list)):
f = feature_list[i]
desktop_milestone = f['browsers']['chrome'].get('desktop', None)
android_milestone = f['browsers']['chrome'].get('android', None)
status = f['browsers']['chrome']['status'].get('text', None)
if (str(desktop_milestone) == str(milestone) or status == str(milestone)):
return i
elif (desktop_milestone == None and str(android_milestone) == str(milestone)):
return i
return -1
@classmethod
def _annotate_first_of_milestones(self, feature_list, version=None):
try:
omaha_data = util.get_omaha_data()
win_versions = omaha_data[0]['versions']
# Find the latest canary major version from the list of windows versions.
canary_versions = [x for x in win_versions if x.get('channel') and x.get('channel').startswith('canary')]
LATEST_VERSION = int(canary_versions[0].get('version').split('.')[0])
milestones = range(1, LATEST_VERSION + 1)
milestones.reverse()
versions = [
IMPLEMENTATION_STATUS[PROPOSED],
IMPLEMENTATION_STATUS[IN_DEVELOPMENT],
IMPLEMENTATION_STATUS[DEPRECATED],
]
versions.extend(milestones)
versions.append(IMPLEMENTATION_STATUS[NO_ACTIVE_DEV])
versions.append(IMPLEMENTATION_STATUS[NO_LONGER_PURSUING])
first_of_milestone_func = Feature._first_of_milestone
if version == 2:
first_of_milestone_func = Feature._first_of_milestone_v2
last_good_idx = 0
for i, ver in enumerate(versions):
idx = first_of_milestone_func(feature_list, ver, start=last_good_idx)
if idx != -1:
feature_list[idx]['first_of_milestone'] = True
last_good_idx = idx
except Exception as e:
logging.error(e)
def migrate_views(self):
"""Migrate obsolete values for views on first edit."""
if self.ff_views == MIXED_SIGNALS:
self.ff_views = NO_PUBLIC_SIGNALS
if self.ff_views == PUBLIC_SKEPTICISM:
self.ff_views = OPPOSED
if self.ie_views == MIXED_SIGNALS:
self.ie_views = NO_PUBLIC_SIGNALS
if self.ie_views == PUBLIC_SKEPTICISM:
self.ie_views = OPPOSED
if self.safari_views == MIXED_SIGNALS:
self.safari_views = NO_PUBLIC_SIGNALS
if self.safari_views == PUBLIC_SKEPTICISM:
self.safari_views = OPPOSED
def format_for_template(self, version=None):
self.migrate_views()
d = self.to_dict()
is_released = self.impl_status_chrome in RELEASE_IMPL_STATES
d['is_released'] = is_released
if version == 2:
if self.is_saved():
d['id'] = self.key().id()
else:
d['id'] = None
d['category'] = FEATURE_CATEGORIES[self.category]
if self.feature_type is not None:
d['feature_type'] = FEATURE_TYPES[self.feature_type]
d['feature_type_int'] = self.feature_type
if self.intent_stage is not None:
d['intent_stage'] = INTENT_STAGES[self.intent_stage]
d['intent_stage_int'] = self.intent_stage
d['created'] = {
'by': d.pop('created_by', None),
'when': d.pop('created', None),
}
d['updated'] = {
'by': d.pop('updated_by', None),
'when': d.pop('updated', None),
}
d['standards'] = {
'spec': d.pop('spec_link', None),
'status': {
'text': STANDARDIZATION[self.standardization],
'val': d.pop('standardization', None),
},
}
d['tag_review_status'] = REVIEW_STATUS_CHOICES[self.tag_review_status]
d['security_review_status'] = REVIEW_STATUS_CHOICES[
self.security_review_status]
d['privacy_review_status'] = REVIEW_STATUS_CHOICES[
self.privacy_review_status]
d['resources'] = {
'samples': d.pop('sample_links', []),
'docs': d.pop('doc_links', []),
}
d['tags'] = d.pop('search_tags', [])
d['browsers'] = {
'chrome': {
'bug': d.pop('bug_url', None),
'blink_components': d.pop('blink_components', []),
'devrel': d.pop('devrel', []),
'owners': d.pop('owner', []),
'origintrial': self.impl_status_chrome == ORIGIN_TRIAL,
'intervention': self.impl_status_chrome == INTERVENTION,
'prefixed': d.pop('prefixed', False),
'flag': self.impl_status_chrome == BEHIND_A_FLAG,
'status': {
'text': IMPLEMENTATION_STATUS[self.impl_status_chrome],
'val': d.pop('impl_status_chrome', None)
},
'desktop': d.pop('shipped_milestone', None),
'android': d.pop('shipped_android_milestone', None),
'webview': d.pop('shipped_webview_milestone', None),
'ios': d.pop('shipped_ios_milestone', None),
},
'ff': {
'view': {
'text': VENDOR_VIEWS[self.ff_views],
'val': d.pop('ff_views', None),
'url': d.pop('ff_views_link', None),
'notes': d.pop('ff_views_notes', None),
}
},
'edge': {
'view': {
'text': VENDOR_VIEWS[self.ie_views],
'val': d.pop('ie_views', None),
'url': d.pop('ie_views_link', None),
'notes': d.pop('ie_views_notes', None),
}
},
'safari': {
'view': {
'text': VENDOR_VIEWS[self.safari_views],
'val': d.pop('safari_views', None),
'url': d.pop('safari_views_link', None),
'notes': d.pop('safari_views_notes', None),
}
},
'webdev': {
'view': {
'text': WEB_DEV_VIEWS[self.web_dev_views],
'val': d.pop('web_dev_views', None),
'url': d.pop('web_dev_views_link', None),
'notes': d.pop('web_dev_views_notes', None),
}
}
}
if is_released and self.shipped_milestone:
d['browsers']['chrome']['status']['milestone_str'] = self.shipped_milestone
elif is_released and self.shipped_android_milestone:
d['browsers']['chrome']['status']['milestone_str'] = self.shipped_android_milestone
else:
d['browsers']['chrome']['status']['milestone_str'] = d['browsers']['chrome']['status']['text']
del d['created']
del_none(d) # Further prune response by removing null/[] values.
else:
if self.is_saved():
d['id'] = self.key().id()
else:
d['id'] = None
d['category'] = FEATURE_CATEGORIES[self.category]
if self.feature_type is not None:
d['feature_type'] = FEATURE_TYPES[self.feature_type]
d['feature_type_int'] = self.feature_type
if self.intent_stage is not None:
d['intent_stage'] = INTENT_STAGES[self.intent_stage]
d['intent_stage_int'] = self.intent_stage
d['impl_status_chrome'] = IMPLEMENTATION_STATUS[self.impl_status_chrome]
d['tag_review_status'] = REVIEW_STATUS_CHOICES[self.tag_review_status]
d['security_review_status'] = REVIEW_STATUS_CHOICES[
self.security_review_status]
d['privacy_review_status'] = REVIEW_STATUS_CHOICES[
self.privacy_review_status]
d['meta'] = {
'origintrial': self.impl_status_chrome == ORIGIN_TRIAL,
'intervention': self.impl_status_chrome == INTERVENTION,
'needsflag': self.impl_status_chrome == BEHIND_A_FLAG,
}
if is_released and self.shipped_milestone:
d['meta']['milestone_str'] = self.shipped_milestone
elif is_released and self.shipped_android_milestone:
d['meta']['milestone_str'] = self.shipped_android_milestone
else:
d['meta']['milestone_str'] = d['impl_status_chrome']
d['ff_views'] = {'value': self.ff_views,
'text': VENDOR_VIEWS[self.ff_views]}
d['ie_views'] = {'value': self.ie_views,
'text': VENDOR_VIEWS[self.ie_views]}
d['safari_views'] = {'value': self.safari_views,
'text': VENDOR_VIEWS[self.safari_views]}
d['standardization'] = {'value': self.standardization,
'text': STANDARDIZATION[self.standardization]}
d['web_dev_views'] = {'value': self.web_dev_views,
'text': WEB_DEV_VIEWS[self.web_dev_views]}
return d
def format_for_edit(self):
self.migrate_views()
d = self.to_dict()
#d['id'] = self.key().id
d['owner'] = ', '.join(self.owner)
d['explainer_links'] = '\r\n'.join(self.explainer_links)
d['spec_mentors'] = ', '.join(self.spec_mentors)
d['doc_links'] = '\r\n'.join(self.doc_links)
d['sample_links'] = '\r\n'.join(self.sample_links)
d['search_tags'] = ', '.join(self.search_tags)
d['blink_components'] = self.blink_components[0] #TODO: support more than one component.
d['devrel'] = ', '.join(self.devrel)
d['i2e_lgtms'] = ', '.join(self.i2e_lgtms)
d['i2s_lgtms'] = ', '.join(self.i2s_lgtms)
return d
@classmethod
def get_all(self, limit=None, order='-updated', filterby=None,
update_cache=False):
KEY = '%s|%s|%s' % (Feature.DEFAULT_CACHE_KEY, order, limit)
# TODO(ericbidelman): Support more than one filter.
if filterby is not None:
s = ('%s%s' % (filterby[0], filterby[1])).replace(' ', '')
KEY += '|%s' % s
feature_list = ramcache.get(KEY)
if feature_list is None or update_cache:
query = Feature.all().order(order) #.order('name')
query.filter('deleted =', False)
# TODO(ericbidelman): Support more than one filter.
if filterby:
query.filter(filterby[0], filterby[1])
features = query.fetch(limit)
feature_list = [f.format_for_template() for f in features]
ramcache.set(KEY, feature_list)
return feature_list
@classmethod
def get_all_with_statuses(self, statuses, update_cache=False):
if not statuses:
return []
KEY = '%s|%s' % (Feature.DEFAULT_CACHE_KEY, sorted(statuses))
feature_list = ramcache.get(KEY)
if feature_list is None or update_cache:
# There's no way to do an OR in a single datastore query, and there's a
# very good chance that the self.get_all() results will already be in
# ramcache, so use an array comprehension to grab the features we
# want from the array of everything.
feature_list = [feature for feature in self.get_all(update_cache=update_cache)
if feature['impl_status_chrome'] in statuses]
ramcache.set(KEY, feature_list)
return feature_list
@classmethod
def get_feature(self, feature_id, update_cache=False):
KEY = '%s|%s' % (Feature.DEFAULT_CACHE_KEY, feature_id)
feature = ramcache.get(KEY)
if feature is None or update_cache:
unformatted_feature = Feature.get_by_id(feature_id)
if unformatted_feature:
if unformatted_feature.deleted:
return None
feature = unformatted_feature.format_for_template()
feature['updated_display'] = unformatted_feature.updated.strftime("%Y-%m-%d")
feature['new_crbug_url'] = unformatted_feature.new_crbug_url()
ramcache.set(KEY, feature)
return feature
@classmethod
def get_chronological(
self, limit=None, update_cache=False, version=None, show_unlisted=False):
cache_key = '%s|%s|%s|%s' % (Feature.DEFAULT_CACHE_KEY,
'cronorder', limit, version)
feature_list = ramcache.get(cache_key)
logging.info('getting chronological feature list')
# On cache miss, do a db query.
if not feature_list or update_cache:
logging.info('recompyting chronological feature list')
# Features that are in-dev or proposed.
q = Feature.all()
q.order('impl_status_chrome')
q.order('name')
q.filter('impl_status_chrome IN', (PROPOSED, IN_DEVELOPMENT))
pre_release = q.fetch(None)
# Shipping features. Exclude features that do not have a desktop
# shipping milestone.
q = Feature.all()
q.order('-shipped_milestone')
q.order('name')
q.filter('shipped_milestone !=', None)
shipping_features = q.fetch(None)
# Features with an android shipping milestone but no desktop milestone.
q = Feature.all()
q.order('-shipped_android_milestone')
q.order('name')
q.filter('shipped_milestone =', None)
android_only_shipping_features = q.fetch(None)
# Features with no active development.
q = Feature.all()
q.order('name')
q.filter('impl_status_chrome =', NO_ACTIVE_DEV)
no_active = q.fetch(None)
# No longer pursuing features.
q = Feature.all()
q.order('name')
q.filter('impl_status_chrome =', NO_LONGER_PURSUING)
no_longer_pursuing_features = q.fetch(None)
shipping_features.extend(android_only_shipping_features)
shipping_features = [f for f in shipping_features if (IN_DEVELOPMENT < f.impl_status_chrome < NO_LONGER_PURSUING)]
def getSortingMilestone(feature):
feature._sort_by_milestone = (feature.shipped_milestone or
feature.shipped_android_milestone)
return feature
# Sort the feature list on either Android shipping milestone or desktop
# shipping milestone, depending on which is specified. If a desktop
# milestone is defined, that will take default.
shipping_features = map(getSortingMilestone, shipping_features)
# First sort by name, then sort by feature milestone (latest first).
shipping_features.sort(key=lambda f: f.name, reverse=False)
shipping_features.sort(key=lambda f: f._sort_by_milestone, reverse=True)
# Constructor the proper ordering.
all_features = []
all_features.extend(pre_release)
all_features.extend(shipping_features)
all_features.extend(no_active)
all_features.extend(no_longer_pursuing_features)
all_features = [f for f in all_features if not f.deleted]
feature_list = [f.format_for_template(version) for f in all_features]
self._annotate_first_of_milestones(feature_list, version=version)
ramcache.set(cache_key, feature_list)
allowed_feature_list = [
f for f in feature_list
if show_unlisted or not f['unlisted']]
return allowed_feature_list
@classmethod
def get_shipping_samples(self, limit=None, update_cache=False):
cache_key = '%s|%s|%s' % (Feature.DEFAULT_CACHE_KEY, 'samples', limit)
feature_list = ramcache.get(cache_key)
if feature_list is None or update_cache:
# Get all shipping features. Ordered by shipping milestone (latest first).
q = Feature.all()
q.filter('impl_status_chrome IN', [ENABLED_BY_DEFAULT, ORIGIN_TRIAL, INTERVENTION])
q.order('-impl_status_chrome')
q.order('-shipped_milestone')
q.order('name')
features = q.fetch(None)
# Get non-shipping features (sans removed or deprecated ones) and
# append to bottom of list.
q = Feature.all()
q.filter('impl_status_chrome <', ENABLED_BY_DEFAULT)
q.order('-impl_status_chrome')
q.order('-shipped_milestone')
q.order('name')
others = q.fetch(None)
features.extend(others)
# Filter out features without sample links.
feature_list = [f.format_for_template() for f in features
if len(f.sample_links) and not f.deleted]
ramcache.set(cache_key, feature_list)
return feature_list
def crbug_number(self):
if not self.bug_url:
return
m = re.search(r'[\/|?id=]([0-9]+)$', self.bug_url)
if m:
return m.group(1)
def new_crbug_url(self):
url = 'https://bugs.chromium.org/p/chromium/issues/entry'
params = ['components=' + self.blink_components[0] or BlinkComponent.DEFAULT_COMPONENT]
crbug_number = self.crbug_number()
if crbug_number and self.impl_status_chrome in (
NO_ACTIVE_DEV,
PROPOSED,
IN_DEVELOPMENT,
BEHIND_A_FLAG,
ORIGIN_TRIAL,
INTERVENTION):
params.append('blocking=' + crbug_number)
if self.owner:
params.append('cc=' + ','.join(self.owner))
return url + '?' + '&'.join(params)
def __init__(self, *args, **kwargs):
super(Feature, self).__init__(*args, **kwargs)
# Stash existing values when entity is created so we can diff property
# values later in put() to know what's changed. https://stackoverflow.com/a/41344898
for prop_name, prop in self.properties().iteritems():
old_val = getattr(self, prop_name, None)
setattr(self, '_old_' + prop_name, old_val)
def __notify_feature_subscribers_of_changes(self, is_update):
"""Async notifies subscribers of new features and property changes to features by
posting to a task queue."""
# Diff values to see what properties have changed.
changed_props = []
for prop_name, prop in self.properties().iteritems():
new_val = getattr(self, prop_name, None)
old_val = getattr(self, '_old_' + prop_name, None)
if new_val != old_val:
new_val = convert_enum_int_to_string(prop_name, new_val)
old_val = convert_enum_int_to_string(prop_name, old_val)
changed_props.append({
'prop_name': prop_name, 'old_val': old_val, 'new_val': new_val})
params = {
'changes': changed_props,
'is_update': is_update,
'feature': self.format_for_template(version=2)
}
# Create task to email subscribers.
cloud_tasks_helpers.enqueue_task('/tasks/email-subscribers', params)
def put(self, notify=True, **kwargs):
is_update = self.is_saved()
key = super(Feature, self).put(**kwargs)
if notify:
self.__notify_feature_subscribers_of_changes(is_update)
# Invalidate ramcache for the individual feature view.
cache_key = '%s|%s' % (Feature.DEFAULT_CACHE_KEY, self.key().id())
ramcache.delete(cache_key)
return key
# Metadata.
created = db.DateTimeProperty(auto_now_add=True)
updated = db.DateTimeProperty(auto_now=True)
updated_by = db.UserProperty(auto_current_user=True)
created_by = db.UserProperty(auto_current_user_add=True)
intent_template_use_count = db.IntegerProperty(default = 0)
# General info.
category = db.IntegerProperty(required=True)
name = db.StringProperty(required=True)
feature_type = db.IntegerProperty(default=FEATURE_TYPE_INCUBATE_ID)
intent_stage = db.IntegerProperty(default=0)
summary = db.StringProperty(required=True, multiline=True)
origin_trial_feedback_url = db.LinkProperty()
unlisted = db.BooleanProperty(default=False)
# TODO(jrobbins): Add an entry_state enum to track app-specific lifecycle
# info for a feature entry as distinct from process-specific stage.
deleted = db.BooleanProperty(default=False)
motivation = db.StringProperty(multiline=True)
# Tracability to intent discussion threads
intent_to_implement_url = db.LinkProperty()
intent_to_ship_url = db.LinkProperty()
ready_for_trial_url = db.LinkProperty()
intent_to_experiment_url = db.LinkProperty()
i2e_lgtms = db.ListProperty(db.Email) # Currently, only one is needed.
i2s_lgtms = db.ListProperty(db.Email)
# Chromium details.