You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@cordova.apache.org by nicola <gi...@git.apache.org> on 2014/08/01 20:00:43 UTC

[GitHub] cordova-firefoxos pull request: Discover b2g ports

GitHub user nicola opened a pull request:

    https://github.com/apache/cordova-firefoxos/pull/20

    Discover b2g ports

    This should be an helper library that should contain functions to find the port of an existing b2g simulator (Firefox OS simulator) and eventually functions to start a new simulator listening on a specific port, so that `cordova run` and `cordova emulate` can finally work.
    
    The idea is about running `cordova emulate`
    - you first scan listening ports to find existing b2g, connect in case they are found, or a specific port or version is specified (implemented for OS X and Linux)
    - if no ports is found you then start a new simulator (coming soon)
    
    The way I scan ports is straight forward, lsof or netstat in localhost and I find b2g processes.

You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/nicola/cordova-firefoxos b2g-ports

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/cordova-firefoxos/pull/20.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #20
    
----
commit 3225d64a25ff301dc5b1eef82228eb1e7a15fe86
Author: nicolagreco <no...@gmail.com>
Date:   2014-08-01T17:55:15Z

    discover b2g ports

----


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] cordova-firefoxos pull request: Discover b2g ports

Posted by nicola <gi...@git.apache.org>.
Github user nicola commented on a diff in the pull request:

    https://github.com/apache/cordova-firefoxos/pull/20#discussion_r15710411
  
    --- Diff: bin/lib/b2g.js ---
    @@ -0,0 +1,74 @@
    +#!/usr/bin/env node
    +
    +/*
    +Licensed to the Apache Software Foundation (ASF) under one
    +or more contributor license agreements. See the NOTICE file
    +distributed with this work for additional information
    +regarding copyright ownership. The ASF licenses this file
    +to you under the Apache License, Version 2.0 (the
    +"License"); you may not use this file except in compliance
    +with the License. You may obtain a copy of the License at
    +
    +http://www.apache.org/licenses/LICENSE-2.0
    +
    +Unless required by applicable law or agreed to in writing,
    +software distributed under the License is distributed on an
    +"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    +KIND, either express or implied. See the License for the
    +specific language governing permissions and limitations
    +under the License.
    +*/
    +
    +var	exec = require('shelljs').exec,
    +    args  = process.argv,
    +    os = process.platform,
    +    B2G_BIN_OSX = 'b2g/B2G.app/Contents/MacOS/b2g-bin',
    +	FX_PROFILES_OSX = 'Library/Application Support/Firefox/Profiles/',
    +	B2G_BIN_LINUX = 'b2g/b2g-bin',
    +	FX_PROFILES_LINUX = '.mozilla/firefox/',
    +	NETSTAT_CMD = 'netstat -lnptu',
    +	LSOF_CMD = 'lsof -i -n -P -sTCP:LISTEN';
    +
    +exports.discoverPorts = function (callback) {
    +	
    +	var ports = [];
    + 
    +	if (os == 'darwin') {
    +		var output = exec(LSOF_CMD, {silent: true}).output;
    +		var regex = /^b2g[-bin]?.*[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+:([0-9]*)/;
    +		var lines = output.split('\n');
    +		for (var line=0; line < lines.length; line++) {
    +			var matches = regex.exec(lines[line]);
    +			
    +			if (matches && +matches[1] != 2828)
    +				ports.push(+matches[1])
    +		}
    + 
    +	} else
    +	if (os == 'linux') {
    +		var output = exec(NETSTAT_CMD, {silent: true}).output;
    +		var regex = /tcp.*[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+:([0-9]+).*LISTEN.*\/b2g[-bin]?/
    +		var lines = output.split('\n');
    +		for (var line=0; line < lines.length; line++) {
    --- End diff --
    
    Thanks for your comments, going back to you in a sec


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] cordova-firefoxos pull request: Discover b2g ports

Posted by jsoref <gi...@git.apache.org>.
Github user jsoref commented on a diff in the pull request:

    https://github.com/apache/cordova-firefoxos/pull/20#discussion_r15709986
  
    --- Diff: bin/lib/b2g.js ---
    @@ -0,0 +1,74 @@
    +#!/usr/bin/env node
    +
    +/*
    +Licensed to the Apache Software Foundation (ASF) under one
    +or more contributor license agreements. See the NOTICE file
    +distributed with this work for additional information
    +regarding copyright ownership. The ASF licenses this file
    +to you under the Apache License, Version 2.0 (the
    +"License"); you may not use this file except in compliance
    +with the License. You may obtain a copy of the License at
    +
    +http://www.apache.org/licenses/LICENSE-2.0
    +
    +Unless required by applicable law or agreed to in writing,
    +software distributed under the License is distributed on an
    +"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    +KIND, either express or implied. See the License for the
    +specific language governing permissions and limitations
    +under the License.
    +*/
    +
    +var	exec = require('shelljs').exec,
    +    args  = process.argv,
    +    os = process.platform,
    +    B2G_BIN_OSX = 'b2g/B2G.app/Contents/MacOS/b2g-bin',
    +	FX_PROFILES_OSX = 'Library/Application Support/Firefox/Profiles/',
    +	B2G_BIN_LINUX = 'b2g/b2g-bin',
    +	FX_PROFILES_LINUX = '.mozilla/firefox/',
    +	NETSTAT_CMD = 'netstat -lnptu',
    +	LSOF_CMD = 'lsof -i -n -P -sTCP:LISTEN';
    +
    +exports.discoverPorts = function (callback) {
    +	
    +	var ports = [];
    + 
    +	if (os == 'darwin') {
    +		var output = exec(LSOF_CMD, {silent: true}).output;
    +		var regex = /^b2g[-bin]?.*[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+:([0-9]*)/;
    +		var lines = output.split('\n');
    +		for (var line=0; line < lines.length; line++) {
    +			var matches = regex.exec(lines[line]);
    +			
    +			if (matches && +matches[1] != 2828)
    +				ports.push(+matches[1])
    +		}
    + 
    +	} else
    +	if (os == 'linux') {
    +		var output = exec(NETSTAT_CMD, {silent: true}).output;
    +		var regex = /tcp.*[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+:([0-9]+).*LISTEN.*\/b2g[-bin]?/
    +		var lines = output.split('\n');
    +		for (var line=0; line < lines.length; line++) {
    +			var matches = regex.exec(lines[line]);
    +			
    +			if (matches && +matches[1] != 2828)
    +				ports.push(+matches[1])
    +		}
    + 
    +	} else {
    +		return callback(new Error("OS not supported for running"))
    +	}
    + 
    +	callback(null, ports)
    + 
    +}
    +
    +if (require.main === module) {
    +    (function() {
    +        exports.discoverPorts(function(err, ports){
    +        	if (err) return console.log(err)
    --- End diff --
    
    don't use tabs.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] cordova-firefoxos pull request: Discover b2g ports

Posted by nicola <gi...@git.apache.org>.
Github user nicola commented on the pull request:

    https://github.com/apache/cordova-firefoxos/pull/20#issuecomment-53481359
  
    I packaged that into https://github.com/nicola/moz-discover-ports


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] cordova-firefoxos pull request: Discover b2g ports

Posted by nicola <gi...@git.apache.org>.
Github user nicola commented on the pull request:

    https://github.com/apache/cordova-firefoxos/pull/20#issuecomment-50915757
  
    Sorry for the redundancy in code. I could compress that all, but I was expecting two different behaviors on two different machines. Keep me posted.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] cordova-firefoxos pull request: Discover b2g ports

Posted by nicola <gi...@git.apache.org>.
Github user nicola commented on the pull request:

    https://github.com/apache/cordova-firefoxos/pull/20#issuecomment-50933496
  
    Updated


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] cordova-firefoxos pull request: Discover b2g ports

Posted by jsoref <gi...@git.apache.org>.
Github user jsoref commented on a diff in the pull request:

    https://github.com/apache/cordova-firefoxos/pull/20#discussion_r15709999
  
    --- Diff: bin/lib/b2g.js ---
    @@ -0,0 +1,74 @@
    +#!/usr/bin/env node
    +
    +/*
    +Licensed to the Apache Software Foundation (ASF) under one
    +or more contributor license agreements. See the NOTICE file
    +distributed with this work for additional information
    +regarding copyright ownership. The ASF licenses this file
    +to you under the Apache License, Version 2.0 (the
    +"License"); you may not use this file except in compliance
    +with the License. You may obtain a copy of the License at
    +
    +http://www.apache.org/licenses/LICENSE-2.0
    +
    +Unless required by applicable law or agreed to in writing,
    +software distributed under the License is distributed on an
    +"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    +KIND, either express or implied. See the License for the
    +specific language governing permissions and limitations
    +under the License.
    +*/
    +
    +var	exec = require('shelljs').exec,
    +    args  = process.argv,
    +    os = process.platform,
    +    B2G_BIN_OSX = 'b2g/B2G.app/Contents/MacOS/b2g-bin',
    +	FX_PROFILES_OSX = 'Library/Application Support/Firefox/Profiles/',
    +	B2G_BIN_LINUX = 'b2g/b2g-bin',
    +	FX_PROFILES_LINUX = '.mozilla/firefox/',
    +	NETSTAT_CMD = 'netstat -lnptu',
    +	LSOF_CMD = 'lsof -i -n -P -sTCP:LISTEN';
    +
    +exports.discoverPorts = function (callback) {
    +	
    +	var ports = [];
    + 
    +	if (os == 'darwin') {
    +		var output = exec(LSOF_CMD, {silent: true}).output;
    +		var regex = /^b2g[-bin]?.*[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+:([0-9]*)/;
    +		var lines = output.split('\n');
    +		for (var line=0; line < lines.length; line++) {
    +			var matches = regex.exec(lines[line]);
    +			
    +			if (matches && +matches[1] != 2828)
    +				ports.push(+matches[1])
    +		}
    + 
    +	} else
    +	if (os == 'linux') {
    +		var output = exec(NETSTAT_CMD, {silent: true}).output;
    +		var regex = /tcp.*[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+:([0-9]+).*LISTEN.*\/b2g[-bin]?/
    +		var lines = output.split('\n');
    +		for (var line=0; line < lines.length; line++) {
    +			var matches = regex.exec(lines[line]);
    +			
    +			if (matches && +matches[1] != 2828)
    +				ports.push(+matches[1])
    +		}
    + 
    +	} else {
    +		return callback(new Error("OS not supported for running"))
    +	}
    + 
    +	callback(null, ports)
    + 
    +}
    +
    +if (require.main === module) {
    +    (function() {
    +        exports.discoverPorts(function(err, ports){
    +        	if (err) return console.log(err)
    +        	console.log("Running FirefoxOS simulators (B2G) on ports", ports)
    +        });
    +    })();
    +}
    --- End diff --
    
    do include a newline at EOF


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] cordova-firefoxos pull request: Discover b2g ports

Posted by nicola <gi...@git.apache.org>.
Github user nicola commented on the pull request:

    https://github.com/apache/cordova-firefoxos/pull/20#issuecomment-53481813
  
    This is outdated, I will write a new PR with using the new little libraries I made


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] cordova-firefoxos pull request: Discover b2g ports

Posted by jsoref <gi...@git.apache.org>.
Github user jsoref commented on a diff in the pull request:

    https://github.com/apache/cordova-firefoxos/pull/20#discussion_r15710033
  
    --- Diff: bin/lib/b2g.js ---
    @@ -0,0 +1,74 @@
    +#!/usr/bin/env node
    +
    +/*
    +Licensed to the Apache Software Foundation (ASF) under one
    +or more contributor license agreements. See the NOTICE file
    +distributed with this work for additional information
    +regarding copyright ownership. The ASF licenses this file
    +to you under the Apache License, Version 2.0 (the
    +"License"); you may not use this file except in compliance
    +with the License. You may obtain a copy of the License at
    +
    +http://www.apache.org/licenses/LICENSE-2.0
    +
    +Unless required by applicable law or agreed to in writing,
    +software distributed under the License is distributed on an
    +"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    +KIND, either express or implied. See the License for the
    +specific language governing permissions and limitations
    +under the License.
    +*/
    +
    +var	exec = require('shelljs').exec,
    +    args  = process.argv,
    +    os = process.platform,
    +    B2G_BIN_OSX = 'b2g/B2G.app/Contents/MacOS/b2g-bin',
    +	FX_PROFILES_OSX = 'Library/Application Support/Firefox/Profiles/',
    +	B2G_BIN_LINUX = 'b2g/b2g-bin',
    +	FX_PROFILES_LINUX = '.mozilla/firefox/',
    +	NETSTAT_CMD = 'netstat -lnptu',
    +	LSOF_CMD = 'lsof -i -n -P -sTCP:LISTEN';
    +
    +exports.discoverPorts = function (callback) {
    +	
    +	var ports = [];
    + 
    +	if (os == 'darwin') {
    +		var output = exec(LSOF_CMD, {silent: true}).output;
    +		var regex = /^b2g[-bin]?.*[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+:([0-9]*)/;
    +		var lines = output.split('\n');
    +		for (var line=0; line < lines.length; line++) {
    +			var matches = regex.exec(lines[line]);
    +			
    +			if (matches && +matches[1] != 2828)
    +				ports.push(+matches[1])
    +		}
    + 
    +	} else
    +	if (os == 'linux') {
    +		var output = exec(NETSTAT_CMD, {silent: true}).output;
    +		var regex = /tcp.*[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+:([0-9]+).*LISTEN.*\/b2g[-bin]?/
    +		var lines = output.split('\n');
    +		for (var line=0; line < lines.length; line++) {
    --- End diff --
    
    personally, I'd favor lines.forEach(function(line) {...});


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] cordova-firefoxos pull request: Discover b2g ports

Posted by nicola <gi...@git.apache.org>.
Github user nicola closed the pull request at:

    https://github.com/apache/cordova-firefoxos/pull/20


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---