def show_57_dev_whatsnew(version): version = version[:-2] try: version = Version(version) except ValueError: return False return version >= Version('57.0')
def clean(self): cleaned_data = super(SnippetAdminForm, self).clean() version_upper_bound = cleaned_data['client_option_version_upper_bound'] version_lower_bound = cleaned_data['client_option_version_lower_bound'] if (version_upper_bound == 'older_than_current_release' and version_lower_bound == 'current_release'): raise forms.ValidationError( "It doesn't make sense to combine those two Firefox version filters" ) if 'any' not in [version_lower_bound, version_upper_bound]: if Version(version_upper_bound) < Version(version_lower_bound): raise forms.ValidationError( 'Firefox version upper bound must be bigger than lower bound.' ) profileage_lower_bound = int( cleaned_data.get('client_option_profileage_lower_bound', -1)) profileage_upper_bound = int( cleaned_data.get('client_option_profileage_upper_bound', -1)) cleaned_data[ 'client_option_profileage_lower_bound'] = profileage_lower_bound cleaned_data[ 'client_option_profileage_upper_bound'] = profileage_upper_bound if ((profileage_lower_bound > -1 and profileage_upper_bound > -1 and profileage_upper_bound <= profileage_lower_bound)): raise forms.ValidationError( 'Profile age upper bound must be bigger than lower bound.') if not any([ cleaned_data['on_release'], cleaned_data['on_beta'], cleaned_data['on_aurora'], cleaned_data['on_nightly'] ]): raise forms.ValidationError( 'Select at least one channel to publish this snippet on.') if ((cleaned_data['on_startpage_5'] and any([ cleaned_data['on_startpage_4'], cleaned_data['on_startpage_3'], cleaned_data['on_startpage_2'], cleaned_data['on_startpage_1'] ]))): raise forms.ValidationError('Activity Stream cannot be combined ' 'with Startpage Versions 1-4.') if not any([ cleaned_data['on_startpage_4'], cleaned_data['on_startpage_3'], cleaned_data['on_startpage_2'], cleaned_data['on_startpage_1'], cleaned_data['on_startpage_5'] ]): raise forms.ValidationError( 'Select at least one Startpage to publish this snippet on.') return cleaned_data
def show_56_cliqz_firstrun(locale, version, funnelcake): try: version = Version(version) except ValueError: version = 0 return locale == 'de' and version >= Version('56.0') and funnelcake in [ '120', '121', '122' ]
def test_product_view_min_version(self): """Should not include versions below minimum.""" pview = ProductView() pview.kwargs = {"slug": "firefox"} with patch.dict(pview.minimum_versions, {"firefox": Version("4.2")}): self.assertListEqual(pview.get_queryset(), [self.pvs[5], self.pvs[4], self.pvs[3]]) with patch.dict(pview.minimum_versions, {"firefox": Version("22.0")}): self.assertListEqual(pview.get_queryset(), [self.pvs[5]])
def show_firefox_lite_whatsnew(version): try: version = Version(version) except ValueError: return False if not switch('firefox-lite-whatsnew'): return False return version >= Version('79.0')
def show_40_firstrun(version): if (waffle.switch_is_active('fx40-firstrun')): try: version = Version(version) except ValueError: return False return version >= Version('40.0') else: return False
def test_product_view_min_version(self): """Should not include versions below minimum.""" pview = ProductView() pview.kwargs = {'slug': 'firefox'} with patch.dict(pview.minimum_versions, {'firefox': Version('4.2')}): self.assertListEqual(pview.get_queryset(), [self.pvs[5], self.pvs[4], self.pvs[3]]) with patch.dict(pview.minimum_versions, {'firefox': Version('22.0')}): self.assertListEqual(pview.get_queryset(), [self.pvs[5]])
def hello_screen_sharing(version): try: if re.search('a\d$', version): version = version[:-2] version = Version(version) except ValueError: return False return version >= Version('38.0.5')
def hello_minimal_ftu(version): try: if re.search('a\d$', version): version = version[:-2] version = Version(version) except ValueError: return False return version >= Version('40.0')
def show_61_whatsnew(version, oldversion): try: version = Version(version) if oldversion: oldversion = Version(oldversion) except ValueError: return False v61 = Version('61.0') return version >= v61 and (oldversion < v61 if oldversion else True)
def is_current_or_newer(user_version): """ Return true if the version (X.Y only) is for the latest Firefox or newer. """ latest = Version( product_details.firefox_versions['LATEST_FIREFOX_VERSION']) user = Version(user_version) # similar to the way comparison is done in the Version class, # but only using the major and minor versions. latest_int = int('%d%02d' % (latest.major, latest.minor1)) user_int = int('%d%02d' % (user.major or 0, user.minor1 or 0)) return user_int >= latest_int
def show_56_whatsnew(version, oldversion): try: version = Version(version) if oldversion: oldversion = Version(oldversion) except ValueError: return False v56 = Version('56.0') if oldversion: return version >= v56 and oldversion < v56 else: return version >= v56
def show_57_whatsnew(version, oldversion): try: version = Version(version) if oldversion: oldversion = Version(oldversion) except ValueError: return False v57 = Version('57.0') v58 = Version('58.0') if oldversion: return version >= v57 and version < v58 and oldversion < v57 else: return version == v57
def show_59_whatsnew(version, oldversion): try: version = Version(version) if oldversion: oldversion = Version(oldversion) except ValueError: return False v59 = Version('59.0') v60 = Version('60.0') if oldversion: return version >= v59 and version < v60 and oldversion < v59 else: return version >= v59 and version < v60
def search_url(context, defaults=None, extra=None, feed=False, **kwargs): """Build a search URL with default values unless specified otherwise.""" if feed: search = reverse('search.feed') else: search = reverse('search') if not defaults: defaults = {} data = [] # fallbacks other than None fallbacks = {'version': '--'} if not 'product' in defaults and not 'product' in kwargs: prod = context['request'].default_prod fallbacks['product'] = prod.short fallbacks['version'] = (getattr(prod, 'default_version', None) or Version(input.LATEST_BETAS[prod]).simplified) # get field data from keyword args or defaults for field in ReporterSearchForm.base_fields: val = kwargs.get(field, defaults.get(field, fallbacks.get(field, None))) if val: data.append((field, unicode(val).encode('utf-8'))) # append extra fields if extra: data = dict(data) data.update(extra) return u'%s?%s' % (search, urlencode(data))
def clean(self): cleaned = self.cleaned_data # default date_end to today if (self.cleaned_data.get('date_start') and not self.cleaned_data.get('date_end')): self.cleaned_data['date_end'] = date.today() # Flip start and end if necessary. if (cleaned.get('date_start') and cleaned.get('date_end') and cleaned['date_start'] > cleaned['date_end']): (cleaned['date_start'], cleaned['date_end']) = (cleaned['date_end'], cleaned['date_start']) # Ensure page is a natural number. try: cleaned['page'] = int(cleaned.get('page')) assert cleaned['page'] > 0 except (TypeError, AssertionError): cleaned['page'] = 1 if not cleaned.get('version'): cleaned['version'] = (getattr(FIREFOX, 'default_version', None) or Version(LATEST_BETAS[FIREFOX]).simplified) elif cleaned['version'] == '--': cleaned['version'] = '' return cleaned
def test_version_compare(): """Test version comparison code, for parity with mozilla-central.""" numlist = enumerate(map(lambda v: Version(v), COMPARISONS)) for i, v1 in numlist: for j, v2 in numlist: if i < j: assert v1 < v2, '%s is not less than %s' % (v1, v2) elif i > j: assert v1 > v2, '%s is not greater than %s' % (v1, v2) else: eq_(v1, v2) equal_vers = map(lambda v: Version(v), EQUALITY) for v1 in equal_vers: for v2 in equal_vers: eq_(v1, v2)
def products_block(context, products, product): latest_versions = dict((prod.short, Version(v).simplified) for prod, v in LATEST_BETAS.items()) version_choices = {} for prod in VERSION_CHOICES: version_choices = json.dumps( dict((prod.short, [map(unicode, v) for v in VERSION_CHOICES[prod]]) for prod in VERSION_CHOICES)) return new_context(**locals())
def test_simplify_version(): """Make sure version simplification works.""" versions = { '4.0b1': '4.0b1', '3.6': '3.6', '3.6.4b1': '3.6.4b1', '3.6.4build1': '3.6.4', '3.6.4build17': '3.6.4', } for v in versions: ver = Version(v) eq_(ver.simplified, versions[v])
class ProductView(LangFilesMixin, ListView): template_name = "security/product-advisories.html" context_object_name = "product_versions" allow_empty = False minimum_versions = { "firefox": Version("4.0"), "thunderbird": Version("6.0"), "seamonkey": Version("2.3"), } def get_queryset(self): product_slug = self.kwargs.get("slug") versions = Product.objects.filter(product_slug=product_slug) min_version = self.minimum_versions.get(product_slug) if min_version: versions = [vers for vers in versions if vers.version >= min_version] return sorted(versions, reverse=True) def get_context_data(self, **kwargs): cxt = super().get_context_data(**kwargs) cxt["product_name"] = cxt["product_versions"][0].product return cxt
class ProductView(ListView): template_name = 'security/product-advisories.html' context_object_name = 'product_versions' allow_empty = False minimum_versions = { 'firefox': Version('4.0'), 'thunderbird': Version('6.0'), 'seamonkey': Version('2.3'), } @method_decorator(cache_control_expires(0.5)) @method_decorator(last_modified(latest_advisory)) def dispatch(self, request, *args, **kwargs): return super(ProductView, self).dispatch(request, *args, **kwargs) def get_queryset(self): product_slug = self.kwargs.get('slug') versions = Product.objects.filter(product_slug=product_slug) min_version = self.minimum_versions.get(product_slug) if min_version: versions = [vers for vers in versions if vers.version >= min_version] return sorted(versions, reverse=True)
def whatsnew_redirect(request, fake_version): """ Redirect visitors based on their user-agent. - Up-to-date Firefox users see the whatsnew page. - Other Firefox users go to the update page. - Non Firefox users go to the new page. """ user_agent = request.META.get('HTTP_USER_AGENT', '') if not 'Firefox' in user_agent: url = reverse('firefox.new') return HttpResponsePermanentRedirect( url) # TODO : Where to redirect bug 757206 user_version = "0" ua_regexp = r"Firefox/(%s)" % version_re match = re.search(ua_regexp, user_agent) if match: user_version = match.group(1) current_version = product_details.firefox_versions[ 'LATEST_FIREFOX_VERSION'] if Version(user_version) < Version(current_version): url = reverse('firefox.update') return HttpResponsePermanentRedirect(url) locales_with_video = { 'en-US': 'american', 'en-GB': 'british', 'de': 'german_final', 'it': 'italian_final', 'ja': 'japanese_final', 'es-AR': 'spanish_final', 'es-CL': 'spanish_final', 'es-ES': 'spanish_final', 'es-MX': 'spanish_final', } return l10n_utils.render(request, 'firefox/whatsnew.html', {'locales_with_video': locales_with_video})
def wrapped(request, *args, **kwargs): # Validate User-Agent request header. ua = request.META.get('HTTP_USER_AGENT', None) parsed = ua_parse(ua) if not parsed: # Unknown UA. if request.method == 'GET': return http.HttpResponseRedirect(reverse('feedback.download')) else: return http.HttpResponseBadRequest( _('User-Agent request header must be set.')) if not settings.ENFORCE_USER_AGENT: return f(request, ua=ua, *args, **kwargs) this_ver = Version(parsed['version']) ref_ver = Version(input.LATEST_RELEASE[parsed['browser']]) # Check for outdated release. if this_ver < ref_ver: return http.HttpResponseRedirect(reverse('feedback.download')) # If we made it here, it's a valid version. return f(request, ua=ua, *args, **kwargs)
def product_is_obsolete(prod_name, version): """ Return true if the product major version is not latest. :param prod_name: e.g. "firefox" :param version: e.g. "33.0.2" :return: boolean """ if prod_name == 'seamonkey': # latest right now is 2.30. Should be good enough for a while. return Version(version) < Version('2.30') major_vers = int(version.split('.')[0]) if prod_name == 'firefox': # we've got info in product-details latest_version = product_details.firefox_versions[ 'LATEST_FIREFOX_VERSION'] latest_major_vers = int(latest_version.split('.')[0]) return major_vers < latest_major_vers if prod_name == 'firefox-esr': # we've got info in product-details latest_version = product_details.firefox_versions['FIREFOX_ESR'] latest_major_vers = int(latest_version.split('.')[0]) return major_vers < latest_major_vers if prod_name == 'thunderbird': # we've got info in product-details latest_version = product_details.thunderbird_versions[ 'LATEST_THUNDERBIRD_VERSION'] latest_major_vers = int(latest_version.split('.')[0]) return major_vers < latest_major_vers # everything else is obsolete return True
class ProductView(LangFilesMixin, ListView): template_name = 'security/product-advisories.html' context_object_name = 'product_versions' allow_empty = False minimum_versions = { 'firefox': Version('4.0'), 'thunderbird': Version('6.0'), 'seamonkey': Version('2.3'), } def get_queryset(self): product_slug = self.kwargs.get('slug') versions = Product.objects.filter(product_slug=product_slug) min_version = self.minimum_versions.get(product_slug) if min_version: versions = [ vers for vers in versions if vers.version >= min_version ] return sorted(versions, reverse=True) def get_context_data(self, **kwargs): cxt = super(ProductView, self).get_context_data(**kwargs) cxt['product_name'] = cxt['product_versions'][0].product return cxt
def ua_parse(ua): """ Simple user agent string parser for Firefox and friends. returns { browser: .FIREFOX or .MOBILE, version: '3.6b4' or similar, platform: one of ('mac', 'win', 'android', 'maemo', 'linux', 'other'), locale: locale code matching locale_details, else None } or None if detection failed. """ if not ua: return None # Detect browser detected = {} for browser in BROWSERS: match = re.match(browser[1], ua) if match: try: version = Version(match.group(2)) except: # Unable to parse version? No dice. return None detected = { 'browser': browser[0], 'version': str(version), } break # Browser not recognized? Bail. if not detected: return None # Detect Platform platform = PLATFORM_OTHER.short for pattern in PLATFORM_PATTERNS: if ua.find(pattern[0]) >= 0: platform = pattern[1] break detected['platform'] = platform return detected
def _get_results(request, meta=[], client=None): form = ReporterSearchForm(request.GET) if form.is_valid(): data = form.cleaned_data query = data.get('q', '') product = data.get('product') or FIREFOX.short version = data.get('version') search_opts = _get_results_opts(request, data, product, meta) c = client or Client() opinions = c.query(query, **search_opts) metas = c.meta else: opinions = [] product = request.default_prod query = '' version = Version(LATEST_BETAS[product]).simplified metas = {} product = PRODUCTS.get(product, FIREFOX) return (opinions, form, product, version, metas)
def _get_results(request, meta=[], client=None): form = ReporterSearchForm(request.GET) if form.is_valid(): data = form.cleaned_data query = data.get('q', '') product = data.get('product') or request.default_prod.short version = data.get('version') search_opts = _get_results_opts(request, data, product, meta) type_filter = search_opts['type'] if 'type' in search_opts else None c = client or Client() opinions = c.query(query, **search_opts) metas = c.meta else: opinions = [] type_filter = None product = request.default_prod query = '' version = (getattr(product, 'default_version', None) or Version(LATEST_BETAS[product]).simplified) metas = {} product = PRODUCTS.get(product, FIREFOX) return (opinions, form, product, version, metas, type_filter)
def dashboard(request): prod = request.default_prod version = (getattr(prod, 'default_version', None) or Version(LATEST_BETAS[prod]).simplified) search_form = ReporterSearchForm() # Frequent terms term_params = { 'product': prod.id, 'version': version, } # # opinions queryset for demographics latest_opinions = Opinion.objects.browse(**term_params) # # Sites clusters # sites = SiteSummary.objects.filter(version__exact=version).filter( # positive__exact=None).filter( # platform__exact=None)[:settings.TRENDS_COUNT] # sites = SiteSummary.objects.all() # Get the desktop site's absolute URL for use in the settings tab desktop_site = Site.objects.get(id=settings.DESKTOP_SITE_ID) try: c = Client() search_opts = dict(product=prod.short, version=version) c.query('', meta=('type', 'locale', 'manufacturer', 'device', 'day_sentiment'), **search_opts) metas = c.meta daily = c.meta.get('day_sentiment', {}) chart_data = dict(series=[ dict(name=_('Praise'), data=daily['praise']), dict(name=_('Issues'), data=daily['issue']), dict(name=_('Ideas'), data=daily['idea']), ]) total = c.total_found except SearchError: metas = {} total = latest_opinions.count() chart_data = None data = { 'opinions': latest_opinions.all()[:settings.MESSAGES_COUNT], 'opinion_count': total, 'product': prod, 'products': PROD_CHOICES, 'sent': get_sentiment(metas.get('type', [])), 'locales': metas.get('locale'), 'platforms': metas.get('platform'), 'devices': metas.get('device'), 'manufacturers': metas.get('manufacturer'), # 'sites': sites, 'version': version, 'versions': VERSION_CHOICES[prod], 'chart_data_json': json.dumps(chart_data), 'defaults': get_defaults(search_form), 'search_form': search_form, 'desktop_url': 'http://' + desktop_site.domain, } if not request.mobile_site: template = 'dashboard/beta.html' else: template = 'dashboard/mobile/beta.html' return jingo.render(request, template, data)
def clean(self): cleaned_data = super(SnippetAdminForm, self).clean() if any([ cleaned_data['on_startpage_4'], cleaned_data['on_startpage_3'], cleaned_data['on_startpage_2'], cleaned_data['on_startpage_1'] ]): validate_xml_variables(cleaned_data['data']) version_upper_bound = cleaned_data.get( 'client_option_version_upper_bound', 'any') version_lower_bound = cleaned_data.get( 'client_option_version_lower_bound', 'any') if (version_upper_bound == 'older_than_current_release' and version_lower_bound == 'current_release'): raise forms.ValidationError( "It doesn't make sense to combine those two Firefox version filters" ) if 'any' not in [version_lower_bound, version_upper_bound]: if Version(version_upper_bound) < Version(version_lower_bound): raise forms.ValidationError( 'Firefox version upper bound must be bigger than lower bound.' ) profileage_lower_bound = int( cleaned_data.get('client_option_profileage_lower_bound', -1)) profileage_upper_bound = int( cleaned_data.get('client_option_profileage_upper_bound', -1)) cleaned_data[ 'client_option_profileage_lower_bound'] = profileage_lower_bound cleaned_data[ 'client_option_profileage_upper_bound'] = profileage_upper_bound if ((profileage_lower_bound > -1 and profileage_upper_bound > -1 and profileage_upper_bound <= profileage_lower_bound)): raise forms.ValidationError( 'Profile age upper bound must be bigger than lower bound.') sessionage_lower_bound = int( cleaned_data.get('client_option_sessionage_lower_bound', -1)) sessionage_upper_bound = int( cleaned_data.get('client_option_sessionage_upper_bound', -1)) cleaned_data[ 'client_option_sessionage_lower_bound'] = sessionage_lower_bound cleaned_data[ 'client_option_sessionage_upper_bound'] = sessionage_upper_bound if ((sessionage_lower_bound > -1 and sessionage_upper_bound > -1 and sessionage_upper_bound <= sessionage_lower_bound)): raise forms.ValidationError( 'Profile age upper bound must be bigger than lower bound.') bookmarks_count_lower_bound = int( cleaned_data.get('client_option_bookmarks_count_lower_bound', -1)) bookmarks_count_upper_bound = int( cleaned_data.get('client_option_bookmarks_count_upper_bound', -1)) cleaned_data[ 'client_option_bookmarks_count_lower_bound'] = bookmarks_count_lower_bound cleaned_data[ 'client_option_bookmarks_count_upper_bound'] = bookmarks_count_upper_bound if ((bookmarks_count_lower_bound > -1 and bookmarks_count_upper_bound > -1 and bookmarks_count_upper_bound <= bookmarks_count_lower_bound)): raise forms.ValidationError('Bookmarks count upper bound must be ' 'bigger than lower bound.') if not any([ cleaned_data['on_release'], cleaned_data['on_beta'], cleaned_data['on_aurora'], cleaned_data['on_nightly'], cleaned_data['on_esr'] ]): raise forms.ValidationError( 'Select at least one channel to publish this snippet on.') if ((cleaned_data.get('on_startpage_5') and any([ cleaned_data['on_startpage_4'], cleaned_data['on_startpage_3'], cleaned_data['on_startpage_2'], cleaned_data['on_startpage_1'] ]))): raise forms.ValidationError('Activity Stream cannot be combined ' 'with Startpage Versions 1-4.') if not any([ cleaned_data.get('on_startpage_4'), cleaned_data.get('on_startpage_3'), cleaned_data.get('on_startpage_2'), cleaned_data.get('on_startpage_1'), cleaned_data.get('on_startpage_5') ]): raise forms.ValidationError( 'Select at least one Startpage to publish this snippet on.') if ((cleaned_data.get('client_option_addon_name') and cleaned_data.get('client_option_addon_check_type') == 'any')): raise forms.ValidationError( 'Select an add-on check or remove add-on name.') if ((not cleaned_data.get('client_option_addon_name') and cleaned_data.get('client_option_addon_check_type', 'any') != 'any')): raise forms.ValidationError( 'Type add-on name to check or remove add-on check.') self._publish_permission_check(cleaned_data) return cleaned_data