-Поиск по дневнику

Поиск сообщений в rss_planet_mozilla

 -Подписка по e-mail

 

 -Постоянные читатели

 -Статистика

Статистика LiveInternet.ru: показано количество хитов и посетителей
Создан: 19.06.2007
Записей:
Комментариев:
Написано: 7

Planet Mozilla





Planet Mozilla - https://planet.mozilla.org/


Добавить любой RSS - источник (включая журнал LiveJournal) в свою ленту друзей вы можете на странице синдикации.

Исходная информация - http://planet.mozilla.org/.
Данный дневник сформирован из открытого RSS-источника по адресу http://planet.mozilla.org/rss20.xml, и дополняется в соответствии с дополнением данного источника. Он может не соответствовать содержимому оригинальной страницы. Трансляция создана автоматически по запросу читателей этой RSS ленты.
По всем вопросам о работе данного сервиса обращаться со страницы контактной информации.

[Обновить трансляцию]

The Rust Programming Language Blog: Announcing Rust 1.26

Четверг, 10 Мая 2018 г. 03:00 + в цитатник

The Rust team is happy to announce a new version of Rust, 1.26.0. Rust is a systems programming language focused on safety, speed, and concurrency.

If you have a previous version of Rust installed via rustup, getting Rust 1.26.0 is as easy as:

$ rustup update stable

If you don’t have it already, you can get rustup from the appropriate page on our website, and check out the detailed release notes for 1.26.0 on GitHub.

What’s in 1.26.0 stable

The past few releases have had a steady stream of relatively minor additions. We’ve been working on a lot of stuff, however, and it’s all starting to land in stable. 1.26 is possibly the most feature-packed release since Rust 1.0. Let’s dig in!

“The Rust Programming Language” Second Edition

For almost 18 months, Carol, Steve, and others have been working on a complete re-write of “The Rust Programming Language.” We’ve learned a lot about how people learn Rust since the first book was written, and this version is an improvement in every way.

We’ve shipped the draft of the second edition on the website for a while now, but with a disclaimer that it was a work in progress. At this point, the book is undergoing some final, minor copy-edits, and being prepared for print. As such, with this release, we are recommending the second edition over the first. You can read it on doc.rust-lang.org or locally via rustup doc --book.

Speaking of print, you can pre-order a dead tree version of the book from NoStarch Press. The contents are identical, but you get a nice physical book to put on a shelf, or a beautifully typeset PDF. Proceeds are going to charity.

impl Trait

At long last, impl Trait is here! This feature has been highly desired for quite a while, and provides a feature known as “existential types.” It’s simpler than that sounds, however. The core of it is this idea:

fn foo() -> impl Trait {
    // ...
}

This type signature says “foo is a function that takes no arguments but returns a type that implements the Trait trait.” That is, we’re not going to tell you what the return type of foo actually is, only that it implements a particular trait. You may wonder how this differs from a trait object:

fn foo() -> Box<Trait> {
    // ...
}

While it’s true that you could have written this code today, it’s not ideal in all situations. Let’s say we have a Trait trait that is implemented for both i32 and f32:

trait Trait {
    fn method(&self);
}

impl Trait for i32 {
    // implementation goes here
}

impl Trait for f32 {
    // implementation goes here
}

Consider this function:

fn foo() -> ? {
    5
}

We want to fill in the return type with something. Previously, only the trait object version was possible:

fn foo() -> Box<Trait> {
    Box::new(5) as Box<Trait>
}

But this introduces a Box, which means allocation. We’re not actually returning some kind of dynamic data here either, so the dynamic dispatch of the trait object hurts too. So instead, as of Rust 1.26, you can write this:

fn foo() -> impl Trait {
    5
}

This doesn’t create a trait object, it’s like we had written -> i32, but instead, we’re only mentioning the part about Trait. We get static dispatch, but we can hide the real type like this.

Why is this useful? One good use is closures. Remember that closures in Rust all have a unique, un-writable type, yet implement the Fn trait. This means that if your function returns a closure, you can do this:

// before
fn foo() -> Box<Fn(i32) -> i32> {
    Box::new(|x| x + 1)
}

// after
fn foo() -> impl Fn(i32) -> i32 {
    |x| x + 1
}

No boxing, no dynamic dispatch. A related scenario happens when returning iterators. Not only do iterators often include closures, but since they nest, you get quite deeply nested types. For example:

fn foo() {
    vec![1, 2, 3]
        .into_iter()
        .map(|x| x + 1)
        .filter(|x| x % 2 == 0)
}

when compiled, gives this error:

error[E0308]: mismatched types
 --> src/main.rs:5:5
  |
5 | /     vec![1, 2, 3]
6 | |         .into_iter()
7 | |         .map(|x| x + 1)
8 | |         .filter(|x| x % 2 == 0)
  | |_______________________________^ expected (), found struct `std::iter::Filter`
  |
  = note: expected type `()`
             found type `std::iter::Filter, [closure@src/main.rs:7:14: 7:23]>, [closure@src/main.rs:8:17: 8:31]>`

That’s a huge ‘found type’. Each adapter in the chain adds a new type. Additionally, we have that closure in there. Previously, we’d have had to use a trait object here, but now we can simply do

fn foo() -> impl Iterator<Item = i32> {
    vec![1, 2, 3]
        .into_iter()
        .map(|x| x + 1)
        .filter(|x| x % 2 == 0)
}

and be done with it. Working with futures is very similar.

It’s important to note that sometimes trait objects are still what you need. You can only use impl Trait if your function returns a single type; if you want to return multiple, you need dynamic dispatch. For example:

fn foo(x: i32) -> Box<Iterator<Item = i32>> {
    let iter = vec![1, 2, 3]
        .into_iter()
        .map(|x| x + 1);

    if x % 2 == 0 {
        Box::new(iter.filter(|x| x % 2 == 0))
    } else {
        Box::new(iter)
    }
}

Here, we may return a filtered iterator, or maybe not. There’s two different types that can be returned, and so we must use a trait object.

Oh, and one last thing: to make the syntax a bit more symmetrical, you can use impl Trait in argument position too. That is:

// before
fn foo<T: Trait>(x: T) {

// after
fn foo(x: impl Trait) {

which can look a bit nicer for short signatures.

Side note for you type theorists out there: this isn’t an existential, still a universal. In other words, impl Trait is universal in an input position, but existential in an output position.

Nicer match bindings

Have you ever had a reference to an Option, and tried to use match? For example, code like this:

fn hello(arg: &Option<String>) {
    match arg {
        Some(name) => println!("Hello {}!", name),
        None => println!("I don't know who you are."),
    }
}

If you tried to compile this in Rust 1.25, you’d get this error:

error[E0658]: non-reference pattern used to match a reference (see issue #42640)
 --> src/main.rs:6:9
  |
6 |         Some(name) => println!("Hello {}!", name),
  |         ^^^^^^^^^^ help: consider using a reference: `&Some(name)`

error[E0658]: non-reference pattern used to match a reference (see issue #42640)
 --> src/main.rs:7:9
  |
7 |         None => println!("I don't know who you are."),
  |         ^^^^ help: consider using a reference: `&None`

Okay, sure. Let’s modify the code:

fn hello(arg: &Option<String>) {
    match arg {
        &Some(name) => println!("Hello {}!", name),
        &None => println!("I don't know who you are."),
    }
}

We added the &s the compiler complained about. Let’s try to compile again:

error[E0507]: cannot move out of borrowed content
 --> src/main.rs:6:9
  |
6 |         &Some(name) => println!("Hello {}!", name),
  |         ^^^^^^----^
  |         |     |
  |         |     hint: to prevent move, use `ref name` or `ref mut name`
  |         cannot move out of borrowed content

Okay, sure. Let’s make the compiler happy again by taking its advice:

fn hello(arg: &Option<String>) {
    match arg {
        &Some(ref name) => println!("Hello {}!", name),
        &None => println!("I don't know who you are."),
    }
}

This will finally compile. We had to add two &s, and a ref. But more importantly, none of this was really helpful to us as programmers. Sure, we forgot a & at first, but does that matter? We had to add ref to get a reference to the inside of the option, but we couldn’t do anything but get a reference, as we can’t move out of a &T.

So, as of Rust 1.26, the initial code, without the &s and ref, will just compile and do exactly what you’d expect. In short, the compiler will automatically reference or de-reference in match statements. So when we say

    match arg {
        Some(name) => println!("Hello {}!", name),

the compiler automatically references the Some, and since we’re borrowing, name is bound as ref name automatically as well. If we were mutating:

fn hello(arg: &mut Option<String>) {
    match arg {
        Some(name) => name.push_str(", world"),
        None => (),
    }
}

the compiler will automatically borrow by mutable reference, and name will be bound as ref mut too.

We think this will remove a significant papercut for new and old Rustaceans alike. The compiler will just do the right thing more often without the need for boilerplate.

main can return a Result

Speaking of papercuts, since Rust uses the Result type for returning errors, and ? to make handling them easy, a common pain-point of new Rustaceans is to try and use ? in main:

use std::fs::File;

fn main() {
    let f = File::open("bar.txt")?;
}

This will give an error like “error[E0277]: the ? operator can only be used in a function that returns Result”. This leads to a pattern where many people write code that looks like this:

fn run(config: Config) -> Result<(), Box<Error>> {
    // --snip--
}

fn main() {
    // --snip--

    if let Err(e) = run(config) {
        println!("Application error: {}", e);

        process::exit(1);
    }
}

Our run function has all of the real logic, and main calls run, only checking to see if there was an error and exiting. We need to make this second function because main can’t return a Result, but we’d like to use ? in that logic.

In Rust 1.26, you can now declare main that returns Result:

use std::fs::File;

fn main() -> Result<(), std::io::Error> {
    let f = File::open("bar.txt")?;

    Ok(())
}

This now works just fine! If main returns an error, this will exit with an error code, and print out a debug representation of the error.

Inclusive ranges with ..=

Since well before Rust 1.0, you’ve been able to create exclusive ranges with .. like this:

for i in 1..3 {
    println!("i: {}", i);
}

This will print i: 1 and then i: 2. In Rust 1.26, you can now create an inclusive range, like this:

for i in 1..=3 {
    println!("i: {}", i);
}

This will print i: 1 and then i: 2 like before, but also i: 3; the three is included in the range. Inclusive ranges are especially useful if you want to iterate over every possible value in a range. For example, this is a surprising Rust program:

fn takes_u8(x: u8) {
    // ...
}

fn main() {
    for i in 0..256 {
        println!("i: {}", i);
        takes_u8(i);
    }
}

What does this program do? The answer: nothing. The warning we get when compiling has a hint:

warning: literal out of range for u8
 --> src/main.rs:6:17
  |
6 |     for i in 0..256 {
  |                 ^^^
  |
  = note: #[warn(overflowing_literals)] on by default

That’s right, since i is a u8, this overflows, and is the same as writing for i in 0..0, so the loop executes zero times.

We can do this with inclusive ranges, however:

fn takes_u8(x: u8) {
    // ...
}

fn main() {
    for i in 0..=255 {
        println!("i: {}", i);
        takes_u8(i);
    }
}

This will produce those 256 lines of output you might have been expecting.

Basic slice patterns

Another long-awaited feature is “slice patterns.” These let you match on slices similar to how you match on other data types. For example:

let arr = [1, 2, 3];

match arr {
    [1, _, _] => "starts with one",
    [a, b, c] => "starts with something else",
}

In this case, we know arr has a length of three, and so we need three entries inside the []s. We can also match when we don’t know the length:

fn foo(s: &[u8]) {
    match s {
        [a, b] => (),
        [a, b, c] => (),
        _ => (),
    }
}

Here, we don’t know how long s is, so we can write the first two arms, each with different lengths. This also means we need a _ term, since we aren’t covering every possible length, nor could we!

Speed improvements

We continue to work on the speed of the compiler. We discovered that deeply nesting types was non-linear in some cases, and a fix was implemented. We’re seeing up to a 12% reduction in compile times from this change, but many other smaller fixes landed as well. More to come in the future!

128 bit integers

Finally, a very simple feature: Rust now has 128 bit integers!

let x: i128 = 0;
let y: u128 = 0;

These are twice the size of u64, and so can hold more values. More specifically,

  • u128: 0 - 340,282,366,920,938,463,463,374,607,431,768,211,455
  • i128: -170,141,183,460,469,231,731,687,303,715,884,105,728 - 170,141,183,460,469,231,731,687,303,715,884,105,727

Whew!

See the detailed release notes for more.

Library stabilizations

We stabilized fs::read_to_string, a convenience over File::open and io::Read::read_to_string for easily reading an entire file into memory at once:

use std::fs;
use std::net::SocketAddr;

let foo: SocketAddr = fs::read_to_string("address.txt")?.parse()?;

You can now format numbers as hexadecimal with Debug formatting:

assert!(format!("{:02x?}", b"Foo\0") == "[46, 6f, 6f, 00]")

Trailing commas are now supported by all macros in the standard library.

See the detailed release notes for more.

Cargo features

Cargo didn’t receive many big new features this release but rather saw a steady stream of stability and performance improvements. Cargo should now resolve lock files even faster, backtrack more intelligently, and require manual cargo update invocations less. Cargo’s binary now also shares the same version as rustc.

See the detailed release notes for more.

Contributors to 1.26.0

Many people came together to create Rust 1.26. We couldn’t have done it without all of you.

Thanks!

https://blog.rust-lang.org/2018/05/10/Rust-1.26.html


Michael Kaply: An Enterprising Future

Четверг, 10 Мая 2018 г. 02:34 + в цитатник

Firefox 60 was released today with support for enterprise policies, including Windows Group Policy. If you’ve followed me or my blog for any length of time, you know that advocating for Firefox in the enterprise has been something that I’ve been doing a very long time.

My first post about Firefox in the enterprise was published on March 15, 2007 and was about Firefox 2.

The first version of the CCK Wizard was released on May 11, 2006 and was for Firefox 1.5

So, to say that I’m happy about this particular release would be an understatement. I’m absolutely ecstatic that Mozilla decided that adding support for enterprise features was important.

But I have to admit something; over the years in my zeal to get enterprise support into Firefox, I’ve encouraged just about every method possible to get customizations into Firefox. As a result, I know there are many installations of Firefox that use methods that are definitely not recommended anymore, especially now that we have real policy support. So, I want to take a moment to encourage everyone:

Please investigate using the new policy manager to replace any method you’ve used in the past, including the distribution directory, AutoConfig and CCK2. If you find things that you are not able to do with the policy engine, please let us know. There’s a possibility that some of these methods might not work in the future, so we’d like to find out now what we need to do to make things working.

If you find bugs or have feature requests, please report them on Github or in Bugzilla.

A couple other notes that might be useful:

  1. Updates to the policy code and additional policies are being allowed on the ESR. You will not be stuck with the existing implementation until the next major ESR. As we implement policies, they will be uplifted into the next minor ESR update.
  2. We are continuing to update the policy code to bring it as close as we can to CCK2 functionality.
  3. We are working on better support for macOS and Linux. We are investigating Managed Preferences on macOS and we are looking into reading the policies.json file from a different location on Linux (etc/opt/firefox).
  4. MSI is on our radar, but we’re not making any commitments at this time.

So now, let’s address the elephant in the room – CCK2.

First off, to support Firefox 60, I released a new version of the CCK2 yesterday. It’s not perfect, but it fixes some of the major issues (bookmarks and error popups). You should get automatically updated to this release. You’ll need repackage your configurations to get these fixes.

But what about the future?

CCK2 uses AutoConfig as the underlying technology to customize Firefox. We currently have plans to sandbox AutoConfig on Rapid Release starting with Firefox 62. This will mean the CCK2 will definitely not work with Rapid Release starting with Firefox 62.

On the ESR, I plan to keep CCK2 working, but I will not be implementing any new features except as they relate to making it easier to migrate to the policy manager. One example of that is providing the ability to remove all bookmarks added by CCK2. Once Firefox 52 is out of support, I will probably migrate CCK2 to use the policy manager internally. To enable that, we are investigating allow policies to be specified via AutoConfig as JSON files.

I always knew there would come a time when the CCK2 would not work anymore. My biggest concern was that there wouldn’t be a replacement. But I’m confident with the policy management support that we’ve implemented that we can make things even better.

I appreciate the support and encouragement folks have given me over the years with regards to the CCK2. I’m glad that the work that I’ve done will live on in the new policy manager on Firefox.

One final note. You will start to see a lot of my older blog posts disappear. This because I don’t want to recommend people use those methods anymore. The official place to get documentation and support is support.mozilla.org.

https://mike.kaply.com/2018/05/09/an-enterprising-future/


K Lars Lohn: Things Gateway - Monitoring Solar Panels

Четверг, 10 Мая 2018 г. 01:12 + в цитатник

I was scanning my network recently and noticed a device that I did not recognize.  It wasn't a rogue, it turned out to be the Enphase Energy controller for my solar panels.  We had them installed years ago and I had forgotten that they connected to the local network.  They feed data back to a cloud service called Enlighten that allows an owner to track their own panels and compare with their neighbors.  I never signed up for the service as I've always been suspicious and mistrusting of cloud services that connect to things in my home.

I probed the local solar panel controller to see what ports it had active and found a Web server.  Jumping over to a browser, I hit that web server and found some rudimentary data about my panels: current generation, lifetime generation, number of microinverters, number of microinverters online, software version numbers, etc.  This was all on the home page of the Web server.

Since I wrote the Virtual Weather Station to demonstrate how easy it is to wrap a Web resource as a Web Thing and integrate it into my Things Gateway, I saw an opportunity.  If I were to scrape this Web page, I could make a Web thing very easily.  I had it running less than an hour later.  It was amazingly simple.

I knew that I'd have to scrape the Web page and Python has a beautiful tool to do that: Beautiful Soup.  I read up on the package, explored it a bit with some sample data and then wrote the code that would scrape the home page from the local Enphase Web server.

The Web page itself is very simple, a set of nested tables with tags around the data I wanted.  To get Beautiful Soup to fetch my target data, I just had to count the number of tables and the number of elements.

I selected current generation, lifetime generation, number of microinverters, number of microinverters online to be the properties for my Solar Panel Web Thing:
    lifetime_generation = WoTThing.wot_property(
name='lifetime_generation',
initial_value=0.0,
description='Total lifetime generation in KWh',
value_source_fn=get_enphase_data,
units='KWh'
)
generating_now = WoTThing.wot_property(
name='generating_now',
initial_value=0.0,
description='currently generating in KWh',
units='KW'
)
microinverter_total = WoTThing.wot_property(
name='microinverter_total',
initial_value=0,
description='the number of microinverters installed'
)
microinverters_online = WoTThing.wot_property(
name='microinverters_online',
initial_value=0,
description='the number of microinverters online',
)
Modifying the asynchronous fetch data from my Virtual Weather Station, I came up with this code that polls the Enphase Web server for the data that I chose to make up my Web Thing:

    async def get_enphase_data(self):
async with aiohttp.ClientSession() as session:
async with async_timeout.timeout(config.seconds_for_timeout):
async with session.get(config.target_url) as response:
enphase_home_page_raw = await response.text()
enphase_page = BeautifulSoup(enphase_home_page_raw, 'html.parser')
# this is stupidly fragile - we're assuming this page format never
# changes from fetch to fetch - observation has shown this to be ok
# but don't know if that will hold over Enphase software updates.
td_elements = enphase_page.find_all('table')[2].find_all('td')
self.lifetime_generation = self._scale_based_on_units(
td_elements[self._LIFETIME_GENERATION].contents[0]
)
self.generating_now = self._scale_based_on_units(
td_elements[self._CURRENTLY_GENERATING].contents[0]
)
self.microinverter_total = td_elements[self._MICROINVERTER_TOTAL].contents[0]
self.microinverters_online = td_elements[self._MICROINVERTERS_ONLINE].contents[0]
(see the entire source code in the enphase_solar.py source file in the pywot/demo directory)

To run this Web Thing on your own instance of the Things Gateway, you'll need to do the following first:
        
$ sudo pip3 install configman
$ sudo pip3 install bs4
$ sudo pip3 install webthing
$ git clone https://github.com/twobraids/pywot.git
$ cd pywot
$ export PYTHONPATH=$PYTHONPATH:$PWD
$ cd demo

Locate your Enphase Energy Web server on your local network.  I used the program Fing on my Android phone to scan my local WiFi network.

Start the Enphase Solar Web Thing like this:
        
$ ./enphase_solar.py --enphase_address=YOUR_LOCAL_ENPHASE_IP_ADDRESS

The program will start logging what it is doing. First you'll see all the settable parameters and their current values.  Then it'll log about setting up properties and starting servers.  Finally, it will start logging new values that it has found, by default, every five minutes.  You can change that with the --seconds_between_polling command line switch.

Then go over to your Things Gateway and press the "+" button, add the Enphase Solar Panels Thing by pressing "Save" then "Done".  Clicking the "Splat" and you'll see the current stats of your solar panels.
Now you're ready to add some rules to the Gateway to notify you of events that happen to your solar panels.  Though, I suppose turning on lights to notify yourself that your solar panels are producing a lot of power may be counterproductive.

In the next edition of this series, I hope to show how to get a Web Thing to send text messages.   You could create a rule that notified you via text if one of your microinverters on your solar panels fail.  The opportunities are endless...

Thanks to my neighbors Susan & Todd for allowing me to photograph their solar panels - they're much more photogenic than mine.

http://www.twobraids.com/2018/05/things-gateway-monitoring-solar-panels.html


Mozilla Localization (L10N): L10N Report: May Edition

Четверг, 10 Мая 2018 г. 00:55 + в цитатник

Please note some of the information provided in this report may be subject to change as we are sometimes sharing information about projects that are still in early stages and are not final yet.

Welcome!

New localizers

  • Kumar Ritu Raj just finished localizing and testing Focus Android v5 in Angika language (which is going to launch soon!) and he is doing BCA from TP College, BNMU, Bihar, India. Welcome and congratulations!
  • Common Voice: Jimi of Danish and Dimitris of Greek, thank you for taking the lead in your respective language.

Are you a locale leader and want us to include new members in our upcoming reports? Contact us!

New community/locales added

  • We recently added several locales to Pontoon: Arpitan (frp), Canadian English (en-CA), Cornish (kw), Iloko (ilo). If you speak any of these languages and want to help, take a look at Pontoon or get in touch.

New content and projects

What’s new or coming up in Firefox desktop

Activity Stream

Activity Stream has become an integral part of Firefox, officially replacing the existing New Tab and soon integrating code for displaying snippets and onboarding content. For this reason, we’re working on moving translations to mozilla-central.

Currently, Activity Stream is managed as a stand-alone project in Pontoon, and store its translations in a GitHub repository. Once this meta bug is fixed, Activity Stream’s strings will be exposed as part of the Firefox project.

While this makes the relation between Activity Stream and Firefox more obvious for localizers, it will also allow to make some improvements in the future, like reducing the lag between translations landing in repositories and actually being available for testing in Firefox.

Release schedule

There are some changes in the release schedule for the Summer, with the Nightly cycle for 63 lasting 10 weeks instead of 8, and the effects of this change rippling to the end of year.

Does this impact you as a localizer? Luckily, not really, thanks to cross-channel. Just don’t forget to keep an eye on the deadlines in Pontoon for the Firefox project, and you’ll be all set.

If you’re curious, you can always check the official Release Calendar.

Fluent migrations

We were waiting for the 61 Nightly cycle to end before resuming migrations. The first bug on the schedule for 62 landed on Tuesday and migrated almost 30 strings used in Privacy related permission dialogs (camera, location, pop-ups, etc.), with a second one already in review (over 20 strings, used in JavaScript across subdialogs in Preferences).

Shield studies

Shield studies are A/B tests, deployed to a specific portion of Firefox users, designed to test features or changes and analyze their impact.

So far, these studies have been targeting only English users (with one exception), and didn’t require localization. This week we started localizing our first study: it’s an extension that will be enabled initially only for Nightly, and for a limited number of locales (4) that have a significant population on the Nightly channel. We will also expose the opt-out preference for Shield studies, together with the about:studies page, to all languages in Firefox in the coming days.

If you’re interested in Shield studies, you can find more details in this wiki page.

What’s new or coming up in mobile

There’s been quite a few things going on in mobile world recently, as you’ve probably noticed.

We’ve recently exposed strings for the upcoming release of Firefox iOS v12, that aims to launch around June 12th. The tentative deadline for localizing and testing is May 23rd. Screenshots are updated twice a week.

Firefox for Amazon Fire TV is shipping an update very soon, probably some time next week. We’ll be getting updated screenshots for testing very soon, stay tuned!

Same for Focus Android v5 that is coming up, and will feature three new locales: Angika (anp), Cornish (kw) and Pur'epecha (tsz). Congrats to the localizers involved in this effort!

Firefox for Android is updating to v60 as we speak, and is being progressively rolled out to users.

What’s new or coming up in web projects

Common Voice was launched on May 2nd in 29 languages. Thanks to many communities’ active participation to get to the finish line, especially with quite a bit of last minute changes. More languages will be added as they reach the completion criteria.

The team has been continually impressed with the thoroughness of communities around the globe down to the wire, to test, to identify issues, and they have not stopped just because the product or their language is launched. The bugs keep coming, not just for translation but for site stability and UX issues. Here is one example.

Currently, only the website is localizable. The next step is to start recording voices in new languages. To that end, we need sentences for people to read in these new languages. The Common Voice team is participating the Mozilla’s Global Sprint to help collect and review new sentences for people to read. Only after that, the team will start collecting voice data in a new language.

What’s new or coming up in Foundation projects

On the advocacy and fundraising side, we’ve had an opportunity to respond to the Clear History feature announced by Facebook during the F8 conference, but the team is mostly focusing on the long term strategy on how to move the conversation to the broader data and privacy topic.

What’s new or coming up in Pontoon

We’re happy to announce that Vishal Sharma and Pramit Singhi will be joining us for the Google Summer of Code project this year! They will help us improve the path to first contribution, including the homepage redesign and guiding new users to submitting their first translation. That should help us grow l10n communities.

Pontoon now runs compare-locales checks when you submit a translation – the same library that is used during the Firefox build process. That allows Pontoon to prevent you from submitting translations that can break Firefox. Read more about the updates we made to the way quality checks work.

Pontoon now allows you to translate strings across all projects in a single translation interface, which helps you work on all untranslated strings in one go, or review all pending suggestions submitted by your team contributors. We also changed the way search works by bringing it closer to the default behaviour of search engines.

More relevant communications for Engagement projects

https://irccloud.mozilla.com/file/Amhzza0T/Schermata%202018-05-09%20alle%2012.28.53.png

We realized that several communications we send to the dev.l10n.web mailing list concern only a small subset of locales, and are meant to be ignored by the vast majority of people. In order to keep the signal-to-noise ratio low, we are changing the way we communicate project updates like snippets and newsletters. From now on, we will try to rely as much as possible on Pontoon built-in notification system, allowing us to send notifications only to existing contributors in the target locales. This way, communications in dev.l10n.web should be more relevant for everyone.

This also means people contributing to Engagement projects won’t get notification directly in their inbox, but using the Pontoon Tools add-on from Michal Stanke will get you almost real-time notifications in your browser. If you’re usually contributing to those projects, please keep an eye on Pontoon notifications if you don’t want to miss schedule, deadline or context about new content.

Events

If you’re planning to meet your fellow teammates this year, or planning an event with other locales, make sure to check our plans for l10n meetups in 2018 and the process to organize meetups. We can’t wait to see the meetup ideas you may have!

  • Want to showcase an event coming up that your community is participating in? Reach out to any l10n-driver and we’ll include that (see links to emails at the bottom of this report)

Localization impact by the numbers

Snippets

  • In Q1, 78 localized snippets generated 2,131,516,000 impressions (for real!!).
  • Of the 78 snippets, 26 snippets had links that generated 125,000 clicks (whoa!!).

Friends of the Lion

Image by Elio Qoshi

 

  • Felix, also known as Djfe, leads the way in filing the number of issues for Common Voice project. Reported problems include translations, functionality testing and UI designs. Thank you for your active participation as a localizer and as a Mozillian!

Know someone in your l10n community who’s been doing a great job and should appear here? Contact on of the l10n-drivers and we’ll make sure they get a shout-out (see list at the bottom)!

Useful Links

Questions? Want to get involved?

Did you enjoy reading this report? Let us know how we can improve by reaching out to any one of the l10n-drivers listed above.

https://blog.mozilla.org/l10n/2018/05/09/l10n-report-may-edition/


Air Mozilla: The Joy of Coding - Episode 138

Среда, 09 Мая 2018 г. 20:00 + в цитатник

The Joy of Coding - Episode 138 mconley livehacks on real Firefox bugs while thinking aloud.

https://air.mozilla.org/the-joy-of-coding-episode-138/


Air Mozilla: Weekly SUMO Community Meeting, 09 May 2018

Среда, 09 Мая 2018 г. 19:00 + в цитатник

Hacks.Mozilla.Org: Firefox 60 – Modules and More

Среда, 09 Мая 2018 г. 18:04 + в цитатник

Firefox 60 is here, and the Quantum lineage continues apace. The parallel processing prowess of Quantum CSS is now available on Firefox for Android, and work continues on WebRender, which modernizes the whole idea of what it means to draw a web page. But we’re not just spreading the love on internals. Firefox 60 boasts a number of web platform and developer-facing improvements as well. Here are a few highlights:

ES Modules are Here!

A Code Cartoon of a module tree

Modular code isn’t just a good idea, it’s the law it’s a great idea! Being able to separate functional units of software allows for cleaner re-use of individual modules and easier inclusion of third-party code. Many languages have support for modules, and if you’re familiar with Node.JS, they’ve been available in some form with the CommonJS require API, but a standardized syntax was created as part of ES2015 (ES6).

Although the syntax for ES modules was standardized, it was left as an exercise for browsers to understand and retrieve the modules. This took a bit of extra time, but now that the browser loading behavior is standardized, support has started rolling out, and this release brings that support to Spidermonkey, Firefox’s JavaScript engine. You can check out the docs on MDN, and of course don’t miss Lin Clark’s breakdown of ES modules either!

Keep Your Cookies to Yourself

Firefox 60 supports the Same-Site attribute when setting cookies. When set, the browser will not send cookies along with a cross-origin request to the issuing server, e.g. during fetch or loading an image. This helps mitigate against common silent forms of Cross-Origin Request Forgery. There is a “lax” mode that does the above, as well as a strict mode that, in addition to the lax behavior, will also not send cookies with an in-bound navigation. This helps prevent a malicious site deep-linking to a page where unintentional behavior could occur when cookies are included.

Read more on the Mozilla Security Blog.

Web Authentication API

It’s been known for a while now that in many contexts, a well-known username (like an email address) and a user-generated password are not sufficiently secure for authentication. This has led to the rise of Multi-Factor Authentication, usually 2-factor authentication, in which in addition to a password, users must also provide information from an additional source. Many sites will send an SMS message with a code to a mobile device, and some also accept tokens generated by a code-generator app or purpose-built hardware “key”. This whole exchange has required the user to copy numbers from a screen into a text field, or at minimum the hardware key has had to simulate key presses.

The Web Authentication API (WebAuthn for short) seeks to eliminate the clunkier aspects of this process by letting a multi-factor authentication device or app communicate directly with a requesting site. The particulars of making this work securely are a bit too complex to cover in this post, but you can learn more about WebAuthn on MDN or here on the Hacks Blog.

A Stroke of Style

The (as-of-yet non-standard) text-stroke property defines a solid fixed-width stroke centered along the path of the characters of text. It allows for effects that aren’t achievable with text-shadow alone. A wide stroke will occlude portions of the characters because by default, the stroke is drawn over top of the font glyph. This can be a bit ugly. To fix this, browsers are borrowing paint-order property from the SVG standard. When properly set, browsers will draw the stroke underneath the text glyphs. For example:

Check out the demo on Glitch

It’s super nifty- but don’t forget that it’s not yet a standard, and you should always check that text is legible without stroke effects applied! You can read more on MDN and check out the compatibility matrix there.

ESR / Group Policy

Firefox 60 is the next version of Firefox to be designated an “Extended Support Release”, or ESR. ESR releases are intended for system administrators who deploy and maintain desktop environments in large organizations. They receive security and stability updates in sync with the latest Release versions of Firefox, and each ESR release’s support overlaps with the next one. This overlap period allows a large organization to certify and deploy new ESR versions before leaving the support window for the prior release.

Firefox 60 ships along with the first incarnation of a new Policy Engine that allows organizational adminstrators to configure Firefox for all their users en masse. On Windows, this is accomplished using Windows Group Policy, and via a configuration file on other platforms. It’s not a feature that most Firefox users will ever need, but if your job is managing thousands of installations of Firefox, we hope you’ll find this a welcome addition.

Would You Like to Know More?

As always, the full list of developer-facing changes is on MDN, and you can find the release notes here.

Keep on rocking the free web!

https://hacks.mozilla.org/2018/05/firefox-60-modules-and-more/


The Firefox Frontier: Firefox Quantum: Fast for Business, Better for IT

Среда, 09 Мая 2018 г. 16:54 + в цитатник

Fast, lightweight, secure and easily configurable, Firefox Quantum for Enterprise should be your go-to for business browsing. Browsers are key to how everyone in your company works, but how often … Read more

The post Firefox Quantum: Fast for Business, Better for IT appeared first on The Firefox Frontier.

https://blog.mozilla.org/firefox/firefox-quantum-for-business/


The Mozilla Blog: Firefox gets down to Business, and it’s Personal

Среда, 09 Мая 2018 г. 16:04 + в цитатник

Right now everybody’s talking about the right way to make the products that we love meet our individual needs AND respect our privacy.

At Mozilla, striking this balance has been our bread and butter for more than two decades. With today’s release of Firefox, we’re bringing you more features and tools that allow you to personalize your browser without sacrificing your privacy.

Here’s what’s coming out in today’s Firefox Release:

Enterprise IT pros can customize Firefox Quantum for the office

It’s not uncommon for people to use many different browsers, one they personally use at home and another at the office. Similar to how you set up your own Firefox browser with your personal preferences, Firefox Quantum for Enterprise can now be customized by your employer to optimize for performance on the job and meet the specific needs of your workplace.

Today’s release has a new feature to support IT professionals who want to customize the browser for their employees. IT professionals can now configure Firefox for their organization, either using Group Policy on Windows, or a JSON file that works across the Mac, Linux, and Windows operating systems. Here’s a look at how it works:

Easily configure Firefox with Windows Group Policy

IT professionals can choose to deploy either the standard Rapid Release (RR) of Firefox or the Extended Support Release (ESR). The standard Rapid Release auto-updates with performance improvements and new features roughly every six weeks, while the Extended Support Release usually receives these features in one big upgrade per year. Both Rapid Release and Extended Support Release receive critical security updates as soon as possible. With today’s release, the Extended Support Release of Firefox is now version 60.

IT professionals eager to use to Firefox Quantum in their organization can visit this site for access. IT professionals curious about why the new Firefox is great for for organizational use can learn more in this blog post about Firefox Quantum for Enterprise.

WebAuthn Provides Extra Layer of Security

Almost every online transaction we make, from paying bills to buying movie tickets, needs a password to access our personal online accounts securely. Today, Firefox is the first browser to support a new security standard, Web Authentication (WebAuthn).

With Firefox, WebAuthn allows people to use a single device like a YubiKey to log into their online accounts without typing a password, or as secondary authentication after entering a password. Only websites that have adopted WebAuthn will recognize your YubiKey and allow you access. Essentially, WebAuthn is a set of anti-phishing rules that uses a sophisticated level of authenticators and cryptography to protect user accounts. It supports various authenticators, such as physical security keys today, and in the future mobile phones, or biometric mechanisms such as face recognition or fingerprints. When your YubiKey is plugged in, the website will read it and automatically log you into your accounts. Web developers and product managers interested in learning more about WebAuthn can read about it on our Hacks Blog.

New Tab Experience Gets Personal Treatment, plus Pocket sponsored stories

The New Tab Experience was one of the features we rolled out with Firefox Quantum last year. We launched it as a visual snapshot of the top sites you’ve visited, recent history and bookmarks, and recommendations from Pocket. And from what we’ve heard from our users, it gets them faster to the sites they visit and check frequently.

Today, when you click on the New Tab, you’ll see a wider layout which includes Search, Top Sites, Recommendations by Pocket and Highlights. “Top Sites” is one of our most requested features so we increased the “Top Sites” menu from six to eight icons and increased the size of the “Highlights” icons.

As part of our exploration into new models that can support high quality content on the web, users in the US may now see an occasional sponsored story within Pocket’s recommendation section on New Tab. It’s part of our focus to deliver personalization, without sacrificing user privacy. What’s unique is that all the recommendations happen on your computer, meaning neither Mozilla, Pocket, nor sponsors receive a copy of your browsing history. You can learn more about how the process works here.

Firefox for Android gets faster with a new CSS engine

One of the elements which made the launch of our new Firefox Quantum browser successful was the addition of our new CSS engine, Stylo. It’s written in Rust, a systems programming language sponsored by Mozilla. Today, we’re shipping Firefox for Android with Stylo, giving it a Firefox Quantum boost. It takes better advantage of mobile devices with multiple cores that are optimized for low power consumption, which is perfect for anyone on the go.

Plus, Firefox Quantum Extension Challenge Winners revealed

Last year, we introduced the new WebExtensions API when we launched our new Firefox Quantum browser so you could continue to personalize your browser in the Quantum era. In March, we launched a contest asking consumers and developers for more fun and useful extensions to use with the new API. We had more than 100+ entries in our Firefox Quantum Extensions Challenge, which have also been added to our Add-ons library. Today, we’re happy to announce the winners, Envify for Best Dynamic Theme, Session Sync for Best Tab Manager/Organizer, and Worldwide Radio for Best Games & Entertainment. To learn more about the winners, visit our Firefox Frontier blog.

Check out and download the latest version of Firefox Quantum for the desktop and Android.

 

The post Firefox gets down to Business, and it’s Personal appeared first on The Mozilla Blog.

https://blog.mozilla.org/blog/2018/05/09/firefox-gets-down-to-business-and-its-personal/


The Mozilla Blog: Mozilla Fights for Net Neutrality this May (and Always)

Среда, 09 Мая 2018 г. 16:00 + в цитатник

Mozilla is continuing to fight for net neutrality — in the courts, alongside Americans, on Twitter and, today, by joining the Red Alert protest.

The Red Alert protest raises awareness about net neutrality’s importance, and the means for keeping it intact: In mid-May, the Senate will vote on a Congressional Review Act (CRA) resolution to overturn the FCC’s net neutrality repeal. We’re partnering with organizations like Consumer Reports, the Electronic Frontier Foundation, and Reddit to encourage Americans to call Congress in support of net neutrality.

Says Ashley Boyd, Mozilla’s VP of Advocacy:

“Policymakers need to listen to their constituents: The majority of Americans are in favor of strong net neutrality rules. Mozilla’s latest public opinion poll reveals that outside of Washington, D.C., net neutrality isn’t a partisan issue. 91% of Americans believe consumers should be able to freely and quickly access their preferred content on the internet.”

 

Says Denelle Dixon, Mozilla COO:

“We are proud to be a leader in the fight for net neutrality both through our legal challenge in Mozilla v. FCC and through our deep work in education and advocacy for an open, equal, accessible internet. Today, Mozilla joins many other companies and civil society organizations to take another stand for net neutrality, as we try to protect against erosion into a discriminatory internet, with ultimately a far worse experience for any users and businesses who don’t pay more for special treatment.”

“Mozilla will always fight for net neutrality because it is fundamental for free speech, competition, and innovation online. Net neutrality is a core characteristic of the internet as we know it, and crucial for the economy and everyday lives. It is imperative that all internet traffic be treated equally, without discrimination against content or type of traffic — that’s how the internet was built and what has made it one of the greatest inventions of all time.”

 

To get involved: Call your members of Congress and express your support for net neutrality.


Last month, Mozilla published results from a nationwide poll that reveals where Americans stand on net neutrality. The survey reinforces what grassroots action has already demonstrated: Americans support equal access.

Mozilla and Ipsos conducted this public opinion poll in February of 2018, surveying 1,007 American adults from across 50 states. Among our key findings:

  • Outside of Washington, D.C., net neutrality isn’t a partisan issue. Americans from red and blue states alike agree that equal access to the internet is a right: 79% of Colorado residents, 81% of Arizona residents, and 80% of North Carolina residents

 

  • 91% of Americans believe consumers should be able to freely and quickly access their preferred content on the internet. Only 9% of Americans think ISPs should be able to offer fast lanes with quicker load times. Support for net neutrality is growing: When Mozilla and Ipsos asked this same question in 2017, 86% of Americans believed the former.

 

  • 78% of Americans believe equal access to the internet is a right. This opinion is most common among younger Americans (84% of adults under the age of 35).

 

  • 76% of Americans believe internet service providers (ISPs) should treat all consumer data the same, and not speed up or slow down specific content. This opinion is most common among older Americans (80% of adults ages 55+) and Americans with a college degree (81%).

 

  • 63% of Americans do not think that ISPs will voluntarily look out for consumers’ best interests, compared to 32% who agree with this statement. Faith in ISPs in declining: When Mozilla and Ipsos asked this same question in 2017, 37% of Americans trusted ISPs.

See the full results from our poll here.

The post Mozilla Fights for Net Neutrality this May (and Always) appeared first on The Mozilla Blog.

https://blog.mozilla.org/blog/2018/05/09/mozilla-fights-for-net-neutrality-this-may-and-always/


Air Mozilla: Intro to Participation at the Global Sprint

Вторник, 08 Мая 2018 г. 22:41 + в цитатник

Intro to Participation at the Global Sprint An introduction to finding projects, using communications channels, and working with the collaboration software GitHub at Mozilla's Global Sprint. We discuss "working open" and why...

https://air.mozilla.org/intro-to-participation-at-the-global-sprint/


Mozilla Addons Blog: Firefox Quantum Extensions Challenge Winners

Вторник, 08 Мая 2018 г. 20:21 + в цитатник

The results are in for the Firefox Quantum Extensions Challenge! We were thrilled to see so many creative, helpful, and delightful submission entries.

 

After our judging panel selected finalists from more than 100 submitted entries, the add-ons community voted for each category winner. The winners were announced for the first time  during the livestream broadcast of the Firefox Quantum Extensions Challenge Awards. A recording of the event is available on Air Mozilla.

These extensions bring great functionality and delight to Firefox, so please check them out. Congratulations to the winners!

Best Tab Manager / Tab Organizer

Winner – Session Sync

by Gabriel Ivanica

This extension can edit, save, change, and restore sessions. Sessions can be saved as bookmarks and synced using Firefox Sync.

Well done. Manages sessions in an intuitive way. UX is polished and works extremely well.”

Runner Up – Tip Tab

by William Wng

Navigate the browser tabs with window screenshots.

Best Dynamic Theme

Winner – Envify

by Yoann Lecuyer

Have you ever wanted a quick way to tell if you are in a staging or production environment? This extension will change your Firefox theme every time you switch environments.

Simple but practical idea, particularly for webmasters.”

Runner up – Native Dark

by spikespaz

Replace Firefox’s default themes with adaptive colorization of the title bar, tabs, and URL bar based on the accent color of your current window.

Best Extension for Games & Entertainment

Winner – Worldwide Radio

by Oleksandr

Listen to live radio stations from around the world and create custom playlists.

“This is a really cool radio add-on with radio stations from all over the world. You can favorite stations, search by country and adjust sound. Listening to Indian radio might become my new favorite hobby.”

Runner up – Web Invaders

By Yalini

Space invaders have come to the web and it’s up to you to fight them off!

The post Firefox Quantum Extensions Challenge Winners appeared first on Mozilla Add-ons Blog.

https://blog.mozilla.org/addons/2018/05/08/firefox-quantum-extensions-challenge-winners/


The Firefox Frontier: Firefox Quantum Extensions Challenge Winners Announced!

Вторник, 08 Мая 2018 г. 20:21 + в цитатник

We know many Firefox users love web extensions, and we do, too. Today we’re announcing the winners of our Firefox Quantum Extensions Challenge. Web Extensions are the code innovations that … Read more

The post Firefox Quantum Extensions Challenge Winners Announced! appeared first on The Firefox Frontier.

https://blog.mozilla.org/firefox/great-new-web-extensions/


Air Mozilla: Quantum Extensions Challenge Winners Announcement

Вторник, 08 Мая 2018 г. 20:00 + в цитатник

Quantum Extensions Challenge Winners Announcement Today, we're announcing the winners of the Quantum Extension Challenge.

https://air.mozilla.org/quantum-extensions-challenge-winners-announcement/


The Mozilla Blog: We Asked People How They Feel About Facebook. Here’s What They Said.

Вторник, 08 Мая 2018 г. 18:10 + в цитатник

Facebook has been in the news a lot lately. It started with the announcement that over 87 million Facebook users had their personal information shared with the private firm Cambridge Analytica without their knowledge. Since then, Facebook CEO Mark Zuckerberg has testified twice in front of the US Congress and people all around the world have been talking about Facebook’s data practices. We took this opportunity to survey people on how they felt about Facebook these days. 47,000 people responded to our survey. The data is interesting and open for your exploration.

The top takeaways? Most people (76%) say they are very concerned about the safety of their personal information online. Yet few people (24%) reported making changes to their Facebook accounts following the recent news of privacy concerns around Facebook. The majority of people who responded to our survey (65%) see themselves — rather than companies or the government — as being most responsible for protecting their personal information online. And very few people (only 12%) said they would consider paying for Facebook, even a version of Facebook that doesn’t make money by collecting and selling personal data.


Mozilla believes in making our survey data open and accessible to everyone safely and respectfully, without sharing any personally identifying information. If you would like to go deeper into this survey data, we built this awesome interactive tool for you. Enjoy!


Methodology:
This was not a scientific poll. This was a self-selecting survey targeted mostly at people on the Mozilla Foundation email list, the Pocket newsletter email list, through the Mozilla Twitter channel, through a Medium blog post, and through users sharing with friends and family.

Mozilla makes this data available under a CC BY 4.0 license.

Enjoy this open data? Care about things like privacy, data, the Internet being awesome. Sign up here and we at Mozilla will keep you updated with the latest news and useful information.

 

The post We Asked People How They Feel About Facebook. Here’s What They Said. appeared first on The Mozilla Blog.

https://blog.mozilla.org/blog/2018/05/08/we-asked-people-how-they-feel-about-facebook-heres-what-they-said/


Mozilla Reps Community: Rep of the Month – April 2018

Вторник, 08 Мая 2018 г. 18:09 + в цитатник

Please join us in congratulating David Ross, our Rep of the Month for April 2018!

David is a Mozillian living the UK and active in a lot of different Mozilla projects. In his day job he is building an Open Source Fitness platform. You might have seen him at the past few MozFests in London. Last year he did a great job wrangling the Privacy&Security space.

6e9ef66996c0fc22dd0908e80dc6de47

 

In the past few months David has organized several MozCoffees in London as well as online meetings for the London community. This is part of an effort to re-activate the UK
community he took on. David likes to plan ahead and he already has 7 upcoming activities he is going to participate at, including an event in summer of 2019 (that’s not a typo)! Last but not least he was a nominee for the recent Council election.

Thanks David, keep rocking the Open Web!

Head over to discourse to congratulate him!

https://blog.mozilla.org/mozillareps/2018/05/08/rep-of-the-month-april-2018/


Gervase Markham: In the Navel of the Moon

Вторник, 08 Мая 2018 г. 14:46 + в цитатник

Question: which country’s name translates literally as “In the Navel of the Moon”?

I recently came across this fascinating map which gives the literal translation of every country name. Some are very pedestrian, but some are fascinating. (I’m not sure why it’s on a site dedicated to comparing credit cards, but other places I’ve found it give them the credit. If this is an SEO thing, I’m happy to reward them for producing decent content…) Most appropriately, Canada apparently means “The Village”…

http://feedproxy.google.com/~r/HackingForChrist/~3/kSHcDXNhLyI/


Mozilla Security Blog: Blocking FTP subresource loads within non-FTP documents in Firefox 61

Вторник, 08 Мая 2018 г. 09:13 + в цитатник

Firefox 61 will block subresource loads that rely on the insecure FTP protocol unless the document itself is an FTP document. For example, Firefox will block FTP subresource loads within HTTP(S) pages.

The File Transfer Protocol (FTP) enables file exchange between computers on a network. While this standard protocol is supported by all major browsers and allows convenient file sharing within a network, it’s one of the oldest protocols in use today and has a number of security issues.

The fundamental underlying problem with FTP is that any data transferred will be unencrypted and hence sent across networks in plain text, allowing attackers to steal, spoof and even modify the data transmitted. To date, many malware distribution campaigns rely on compromising FTP servers, downloading malware on an end users device using the FTP protocol. Further, FTP makes HSTS protection somewhat useless, because the automated upgrading from an unencrypted to an encrypted connection that HSTS promises does not apply to FTP.

Following through to our intent to deprecate non-secure HTTP and aligning with Mozilla’s effort to improve adoption of HTTPS Firefox will block subresource loads, like images, scripts and iframes, relying on the insecure FTP protocol. Starting with Firefox 61, loading an FTP subresource within a non-FTP document will be blocked and the following message will be logged to the console:

For the Mozilla Security Team:
Tom Schuster and Christoph Kerschbaumer

 

The post Blocking FTP subresource loads within non-FTP documents in Firefox 61 appeared first on Mozilla Security Blog.

https://blog.mozilla.org/security/2018/05/07/blocking-ftp-subresource-loads-within-non-ftp-documents-in-firefox-61/


K Lars Lohn: Things Gateway - the Virtual Weather Station Code

Понедельник, 07 Мая 2018 г. 22:12 + в цитатник
Today, I'm going to talk about the Python 3 code that I used to create the Virtual Weather Station in my previous post.

The Virtual Weather Station was written using Things Framework, a new communication protocol to connect devices with controllers based on Web technology.  The Things Framework consists of a set libraries and modules written in various languages.  Each library implements a server that offers the Web Thing API on behalf of the device running the server.  The protocol is HTTP, so the server offers a Web interface by embedding a Web Server. That interface contains all the mechanisms to query or control the device and is, therefore, the embodiment of the Web Thing API.

 webthing-python

The webthing Python 3 package is an implementation of the Things Framework.  When creating the code for a physical or virtual device to speak the Web Thing API, this module supplies the required classes and functions.  Like all the webthing libraries in various languages, it creates a server called WebThingServer.  It's really a container for two other servers. It employs an instance of tornado, an asynchronous Web server, as well as a zeroconf, a multi-thread hot Multicast DNS discovery service.

The tornado Web server is the window to the wider world for a device.  It allows the device to report state to the Things Gateway.  The Things Gateway can also manipulate the state of the device through this interface.

The zeroconf server allows the Things Gateway to discover the device's tornado Web server on the local network by announcing its existence via Multicast DNS.   This means that you don't have to know the IP address of the things that you have on your network, the Things Gateway can find them on its own. 

When writing an application with WoTServer class, a collection of Thing objects are passed to the WoTServer.  The WoTServer iterates through the collection and creates the URL-to-handler-method associations required by the tornado Web server.  It accomplishes this with the use of the Thing and Property public classes in cooperation with a set of not-as-public helper classes.  The Thing and Property classes implement the GET and PUT equivalents that the Web Server needs to implement its services.  Therefore, the Thing and Property classes are tightly bound to the Web Server and HTTP.

You may notice that several examples of Things Framework code also refer to Action and Event classes.  The Things Gateway doesn’t currently provide a way to use actions or display events, but those are in the works.  To simplify my examples, I'm going to omit the use of these classes until they are supported within the Things Gateway.

Writing Code with webthing

The webthing-python code tracks a reference implementation written in Javascript.  As such, webthing Python package carries some baggage that is not particularly Pythonic.  It's quite functional, but just doesn't quite fit the idioms and style of Python.  There are some particular standouts:
  • Instances of Property are added at initialization time rather than at class load time.  This means they are difficult to represent using Python's property descriptor system, which seems like it should be a natural fit.
  • The "read/write" versus "read only" aspect of a Property is not specified in the Property but, instead, by the presence or absence of a method passed into the constructor of an entirely different class, Value.
  • The arguments list for the Property constructor have a final catch-all parameter called metadata as a free-form dict instance.  Python already has a native method of handling this situation with the kwargs argument. 
class ExampleDimmableLight(Thing):
def __init__(self):
Thing.__init__('a lamp', 'dimmable light', 'a Web connected lamp')
self.add_property(
Property(
self,
'level',
Value(0.0, lambda l: print('New light level is', l)),
metadata={
'type': 'number',
'description': 'The level of light from 0-100',
'minimum': 0,
'maximum': 100,
}))
(this example is a derivation of the ExampleDimmableLight from the webthing examples)
What would be the ideal interface in Python to represent the concepts of the Things Framework?  Creating my vision of an ideal interface was my goal in making my pywot wrapper around webthing. I addressed the issues above and automated some of the boilerplate asynchronous details. The goal was to simplify the coding to this:
class ExampleDimmableLight(WoTThing):
def __init__(self, config, lamp_hardware):
super(ExampleDimmableLight, self).__init__(
config, 'a lamp', 'dimmableLight', 'a Web connected lamp')

level = WoTThing.wot_property(
name='level',
initial_value=0,
description="lamp brightness level",
value_forwarder=_set_hardware_level,
minimum=0,
maximum=100
)
(See the full pywot ExampleDimmableLight example for more detail)

 How pywot works

I started by creating a class WoTThing that derives from the webthing.Thing class.  This new class has a fancy class method called wot_property that combines the webthing.Property with a Python descriptor.
class WoTThing(Thing, RequiredConfig):
@classmethod
def wot_property(
kls,
*,
name,
initial_value,
description,
value_source_fn=None,
value_forwarder=None,
**kwargs
):
kls.wot_property_functions[name] = partial(
create_wot_property,
name=name,
initial_value=initial_value,
description=description,
value_source_fn=value_source_fn,
value_forwarder=value_forwarder,
**kwargs
)
(see class WoTThing in the pywot code)
The parameters (name, initial_value, description, ...) get saved and used later to instantiate Property objects during initialization time for any derived class.  Each time wot_property is called, the method gathers the parameters required to create a Property and squirrels them away in a partial application of a function (see functools.partial).  That partial function is then stored in a class scoped list called wot_property_functions.  The partial functions stored in that list will be called later during class initialization time where they will create the actual Property instances.
        if value_source_fn is not None:
async def a_property_fetching_coroutine(thing_instance):
while True:
try:
await value_source_fn(thing_instance)
except CancelledError:
logging.debug('cancel detected')
break
except Exception as e:
logging.error('loading data fails: %s', e)
await sleep(thing_instance.config.seconds_between_polling)

a_property_fetching_coroutine.property_name = name
kls.property_fetching_coroutines.append(a_property_fetching_coroutine)
If the Property needs to get values from external hardware or a process (as is the case for any sensor), the wot_property method creates a locally scoped method to poll the underlying controllable device for the value of the Property.  The method is a closure over the programmer supplied value_source_fn.  This  function reads values from that underlying hardware once and need not worry about polling or timing.  The server will later start a asynchronous event loop task to do the polling by periodically call the value_source_fn.
            def get_value_fn(thing_instance):
return thing_instance.properties[name].value.get()

def set_value_fn(thing_instance, new_value):
thing_instance.properties[name].value.notify_of_external_update(new_value)

return property(get_value_fn, set_value_fn)
Finally, the wot_property method creates a property descriptor using the Python property method.  It returns a descriptor for both a setter and a getter for the Property.  This sets up the syntactic sugar of allowing the derived class to refer to the value of the Property or set it as if it were directly a member of the class instance.
        current_observation = self.weather_data['current_observation']
self.temperature = current_observation['temp_f']
self.barometric_pressure = current_observation['pressure_in']
self.wind_speed = current_observation['wind_mph']
in comparison to the method using the webthing API alone.
        current_observation = self.weather_data['current_observation']
self.properties['temperature'].value.notify_of_external_update(
current_observation['temp_f']
)
self.properties['barometric_pressure'].value.notify_of_external_update(
current_observation['pressure_in']
)
self.properties['wind_speed'].value.notify_of_external_update(
current_observation['wind_mph']
)
The combination of wot_property with the module scoped create_wot_property method addresses all of the issues from my standout list above.  It also handles the the boiler plate code for polling the underlying hardware.  This reduces the programmers job to just declaring the Properties of the desired class and providing an asynchronous method to fetch values for the properties.  It significantly simplifies the controllable device code, making it easier to both read and write. 

The Virtual Weather Station uses three properties:
    temperature = WoTThing.wot_property(
name='temperature',
initial_value=0.0,
description='the temperature in °F',
value_source_fn=get_weather_data,
units='°F'
)
barometric_pressure = WoTThing.wot_property(
name='barometric_pressure',
initial_value=30.0,
description='the air pressure in inches',
units='in'
)
wind_speed = WoTThing.wot_property(
name='wind_speed',
initial_value=30.0,
description='the wind speed in mph',
units='mph'
)
Notice that in a webthing version of this code, the description and units would be expressed as members of a dict given to the metadata parameter rather than as direct parameters.  When the Property class is eventually instantiated, those two parameters will be put into their proper places within a metadata dict automatically by the create_wot_property partial functions.
    async def get_weather_data(self):
async with aiohttp.ClientSession() as session:
async with async_timeout.timeout(config.seconds_for_timeout):
async with session.get(config.target_url) as response:
self.weather_data = json.loads(await response.text())
current_observation = self.weather_data['current_observation']
self.temperature = current_observation['temp_f']
self.barometric_pressure = current_observation['pressure_in']
self.wind_speed = current_observation['wind_mph']
The Virtual Weather Station action taken by the automatic asynchronous polling loop is the method called get_weather_data.   It contains the code to call out to Weather Underground to fetch the current conditions.  Once it has its json payload of weather data, it uses standard assignment operators to save the values to the object.  Under the covers, though, those assignments are actually performing the actions required by Property and Value objects.

The pywot package also provides a derived class of the webthing WebThingServer class called WoTServer.  The only extra functionality it adds is the management of the asynchronous polling methods for the Thing properties.  Rather than just use the start/stop methods of the base class, it provides a run method.  This allows the class to control the orderly shutdown of the asynchronous polling tasks and exception handling.


To my eyes, the pywot package makes creating a virtual Web Thing pretty simple.  Though, as I've said many times, "complexity is in the eye of the beholder".  In my next posting, I'm going to talk about more Virtual Web Things that I've created.  If you want to jump ahead without me, see the demo directory of my github repo for this project.

Nota bene: pywot is experimental software to prove a concept.  I've not uploaded it to create an installable package as it is not stable: as the Things Framework evolves, this module will evolve, too.  It has no tests.  Use it at your own risk.



http://www.twobraids.com/2018/05/things-gateway-virtual-weather-station.html


Air Mozilla: Mozilla Weekly Project Meeting, 07 May 2018

Понедельник, 07 Мая 2018 г. 21:00 + в цитатник


Поиск сообщений в rss_planet_mozilla
Страницы: 472 ... 325 324 [323] 322 321 ..
.. 1 Календарь