Run phantomjs fetcher if phantomjs is installed.
961631
def phantomjs(ctx, phantomjs_path, port, auto_restart, args):
    
    args = args or ctx.default_map and ctx.default_map.get('args', [])

    import subprocess
    g = ctx.obj
    _quit = []
    phantomjs_fetcher = os.path.join(
        os.path.dirname(pyspider.__file__), 'fetcher/phantomjs_fetcher.js')
    cmd = [phantomjs_path,
           # this may cause memory leak: https://github.com/ariya/phantomjs/issues/12903
           #'--load-images=false',
           '--ssl-protocol=any',
           '--disk-cache=true'] + list(args or []) + [phantomjs_fetcher, str(port)]

    try:
        _phantomjs = subprocess.Popen(cmd)
    except OSError:
        logging.warning('phantomjs not found, continue running without it.')
        return None

    def quit(*args, **kwargs):
        _quit.append(1)
        _phantomjs.kill()
        _phantomjs.wait()
        logging.info('phantomjs exited.')

    if not g.get('phantomjs_proxy'):
        g['phantomjs_proxy'] = '127.0.0.1:%s' % port

    phantomjs = utils.ObjectDict(port=port, quit=quit)
    g.instances.append(phantomjs)
    if g.get('testing_mode'):
        return phantomjs

    while True:
        _phantomjs.wait()
        if _quit or not auto_restart:
            break
        _phantomjs = subprocess.Popen(cmd)
157361
def local_run():
  """"""
  server_software = os.environ.get('SERVER_SOFTWARE')
  if server_software is None:
    return True
  if 'remote_api' in server_software:
    return False
  if server_software.startswith(('Development', 'testutil')):
    return True
  return False
1191975
function execute(args){
    var options = optionator.parse(args);

    if(options.help){
        console.log(optionator.generateHelp());
    }
    else if(options.version){
        console.log("v" + require("../package.json").version);
    }
    else{
        printResults(loadPerf(options));
    }
}
405078
function findExecutable(opt_exe) {
  var exe = opt_exe || io.findInPath(PHANTOMJS_EXE, true);
  if (!exe) {
    throw Error(
        'The PhantomJS executable could not be found on the current PATH. ' +
        'Please download the latest version from ' +
        'http://phantomjs.org/download.html and ensure it can be found on ' +
        'your PATH. For more information, see ' +
        'https://github.com/ariya/phantomjs/wiki');
  }
  if (!fs.existsSync(exe)) {
    throw Error('File does not exist: ' + exe);
  }
  return exe;
}
1030146
function (options, callbackFn) {
            var Webpage = require('./webpage'),
                Phantom = require('./phantom'),
                self = this,
                streamPosition = 0,

//            //pass proxy to callbackFn
//            callbackFn.call(self, self.proxy);

            //parses a line from phantoms event stream
                parseResponse = function (response) {
                    var parsedEvent;

                    self.options.debug && console.log('buffer :%s'.grey, response);

                    try {
                        parsedEvent = JSON.parse(response);
                    }
                    catch (exception) {
                        console.error(exception.toString().red.bold);
                        console.error('attempted to parse %s', response);
                        return;
                    }

                    var args = parsedEvent.args;
                    args.unshift(parsedEvent.type);

                    self.options.debug && console.log('emitting %s event on %s'.grey, parsedEvent.type, parsedEvent.source);

                    switch (parsedEvent.source) {
                        //phantomJs server module started and is listening or failed
                        case 'phantom' :
                            self.proxy.phantom.emit.apply(self.proxy.phantom, args);
                            break;
                        case 'page' :
                            self.proxy.page.emit.apply(self.proxy.page, args);
                            break;
                        case 'server' :
                            self.proxy.phantom.emit.apply(self.proxy.phantom, args);
                            break;
                        default :
                            throw new Error('unexpected eventsource:' + parsedEvent.source);

                    }

                };

            var spawnNewProcess = function () {
                var spawn = require('child_process').spawn,
                    serverPath = __dirname + '/' + require('path').normalize('./server/index.js');

                var args = translateOptions2Arguments(options);
                args.proxy.unshift(serverPath, JSON.stringify(options));
                var processArgs = args.phantom.concat(args.proxy);

                //spawn new process
                var phantomjs = spawn(options.phantomjsPath,
                    processArgs,
                    {
                        detached:false,
                        stdio:
                            [
                                process.stdin,
                                process.stdout,
                                process.stderr
                            ]
                    });

                //  phantomjs.unref && phantomjs.unref();
            };

            var ensureServerRunning = function () {
                pingServer(options, function (result) {
                    self.options.debug && console.log('pinged server and got back %s', result);

                    if (result) {
                        self.options.debug && console.log('server already running... proxy value %s', JSON.stringify(self.proxy));
                        callbackFn(self.proxy);

                    }
                    else {
                        self.options.debug && console.log('creating a new server, waiting for servercreated event on %s', self.proxy.phantom);

                        self.proxy.phantom.on('serverCreated', function (result) {
                            self.options.debug && console.log('server created callback fired with value:%s'.yellow.bold, result);
                            callbackFn(self.proxy);
                        });

                        spawnNewProcess();
                    }
                });
            };

            //socket io implementation - credit to node-phantom
            var socketio = require('socket.io');
            var http = require('http');
            this.server = http.createServer(function (request, response) {
                response.writeHead(200, {"Content-Type":"text/html"});
                response.end('<html><head><script src="/socket.io/socket.io.js" type="text/javascript"></script><script type="text/javascript">\n\
                    window.onload=function(){\n\
                    var socket = new io.connect("http://" + window.location.hostname);\n\
                    window.socket = socket;\n\
                    };\n\
                    </script></head><body></body></html>');
            }).listen();

            options.clientPort = this.server.address().port;
            var io = socketio.listen(this.server, {'log level':1});

            io.sockets.on('connection', function (socket) {
                options.debug && console.log('connection'.green);
                socket.on('res', function (response) {
                    var data = JSON.stringify(response);
                    options.debug && console.log('response: %s'.green, data);
                    parseResponse(data);
                });
            });

            //create proxy object
            self.proxy = {
                page:new Webpage(options),
                phantom:new Phantom(options),
                end:function (endCallback) {
                    self.end(function () {
                        endCallback&&endCallback(true);
                    });
                }
            };

            ensureServerRunning();
        }
1080883
function startPhantom (specPath, cfg, cb) {
        var args = [specPath];
        if (cfg.verbose) {
            args.push("--verbose"); // custom, to be handled by spec runner
        }
        if (cfg.debug) {
            args.push("--debug"); // custom, to be handled by spec runner
        }
        if (cfg.color) {
            args.push("--color"); // custom, to be handled by spec runner
        }
        args.push("--xunitName=" + cfg.xunitName);
        var phantomProcess = grunt.util.spawn({
            cmd : 'phantomjs',
            args : args
        }, cb);

        phantomProcess.stdout.pipe(process.stdout);
        phantomProcess.stderr.pipe(process.stderr);
        return phantomProcess;
    }
1356458
function getPhantomExitCb (specId, allSpecs, cfg, done) {
        var spawnCb = function (error, result, code) {
            if (error) {
                ok = false;
                if (cfg.debug) {
                    console.log("PhantomJS exited with code "  + code);
                }
            }
            var nextSpecId = specId + 1;
            if (nextSpecId == allSpecs.length) { // last spec
                done(ok);
            } else {
                startSpec (nextSpecId, allSpecs, cfg, done);
            }
        };
        return spawnCb;
    }
1297176
def run(self):
        """"""
        _check_directory(self.directory)

        with DirectoryContextManager(self.directory):
            process = subprocess.Popen(self.arguments, shell=self._shell, env=self.env)

            _, _ = process.communicate()

        returncode = process.returncode

        if returncode != 0 and not self._ignore_errors:
            raise CommandError(
                '"{0}" failed (err code {1})'.format(self.__repr__(), returncode)
            )
941693
def run_parser_plugins(self, url_data, pagetype):
        """"""
        run_plugins(self.parser_plugins, url_data, stop_after_match=True, pagetype=pagetype)
708814
def check_if_exists(self):
        """"""
        if self.req is None:
            return False
        try:
            self.satisfied_by = pkg_resources.get_distribution(self.req)
        except pkg_resources.DistributionNotFound:
            return False
        except pkg_resources.VersionConflict:
            self.conflicts_with = pkg_resources.get_distribution(self.req.project_name)
        return True
210918
def _are_requirejs_deps_loaded(browser, deps):
    

    # This is a little complicated
    #
    # We're going to use `execute_async_script` to give control to
    # the browser.  The browser indicates that it wants to return
    # control to us by calling `callback`, which is the last item
    # in the global `arguments` array.
    #
    # We install a RequireJS module with the dependencies we want
    # to ensure are loaded.  When our module loads, we return
    # control to the test suite.
    script = dedent(u"""
        // Retrieve the callback function used to return control to the test suite
        var callback = arguments[arguments.length - 1];

        // If RequireJS isn't defined, then return immediately
        if (!window.require) {{
            callback("RequireJS not defined");
        }}

        // Otherwise, install a RequireJS module that depends on the modules
        // we're waiting for.
        else {{

            // Catch errors reported by RequireJS
            requirejs.onError = callback;

            // Install our module
            require({deps}, function() {{
                callback('Success');
            }});
        }}
    """).format(deps=json.dumps(list(deps)))

    # Set a timeout to ensure we get control back
    browser.set_script_timeout(30)

    # Give control to the browser
    # `result` will be the argument passed to the callback function
    try:
        result = browser.execute_async_script(script)
        return result == 'Success'

    except TimeoutException:
        return False
48435
def puppeteer(ctx, port, auto_restart, args):
    

    import subprocess
    g = ctx.obj
    _quit = []
    puppeteer_fetcher = os.path.join(
        os.path.dirname(pyspider.__file__), 'fetcher/puppeteer_fetcher.js')
    cmd = ['node', puppeteer_fetcher, str(port)]

    try:
        _puppeteer = subprocess.Popen(cmd)
    except OSError:
        logging.warning('puppeteer not found, continue running without it.')
        return None

    def quit(*args, **kwargs):
        _quit.append(1)
        _puppeteer.kill()
        _puppeteer.wait()
        logging.info('puppeteer exited.')

    if not g.get('puppeteer_proxy'):
        g['puppeteer_proxy'] = '127.0.0.1:%s' % port

    puppeteer = utils.ObjectDict(port=port, quit=quit)
    g.instances.append(puppeteer)
    if g.get('testing_mode'):
        return puppeteer

    while True:
        _puppeteer.wait()
        if _quit or not auto_restart:
            break
        _puppeteer = subprocess.Popen(cmd)
1285401
function tryPhantomjsOnPath() {
  if (getTargetPlatform() != process.platform || getTargetArch() != process.arch) {
    console.log('Building for target platform ' + getTargetPlatform() + '/' + getTargetArch() +
                '. Skipping PATH search')
    return Q.resolve(false)
  }

  return Q.nfcall(which, 'phantomjs')
  .then(function (result) {
    phantomPath = result
    console.log('Considering PhantomJS found at', phantomPath)

    // Horrible hack to avoid problems during global install. We check to see if
    // the file `which` found is our own bin script.
    if (phantomPath.indexOf(path.join('npm', 'phantomjs')) !== -1) {
      console.log('Looks like an `npm install -g` on windows; skipping installed version.')
      return
    }

    var contents = fs.readFileSync(phantomPath, 'utf8')
    if (/NPM_INSTALL_MARKER/.test(contents)) {
      console.log('Looks like an `npm install -g`')

      var phantomLibPath = path.resolve(fs.realpathSync(phantomPath), '../../lib/location')
      return findValidPhantomJsBinary(phantomLibPath)
      .then(function (binaryLocation) {
        if (binaryLocation) {
          writeLocationFile(binaryLocation)
          console.log('PhantomJS linked at', phantomLibPath)
          exit(0)
        }
        console.log('Could not link global install, skipping...')
      })
    } else {
      return checkPhantomjsVersion(phantomPath).then(function (matches) {
        if (matches) {
          writeLocationFile(phantomPath)
          console.log('PhantomJS is already installed on PATH at', phantomPath)
          exit(0)
        }
      })
    }
  }, function () {
    console.log('PhantomJS not found on PATH')
  })
  .fail(function (err) {
    console.error('Error checking path, continuing', err)
    return false
  })
}
166799
def run(self):
        """"""
        for wsock in self.wsocks:
            wsock.run()
        for api in self.apis:
            api.run()
1134603
def _setup_phantomjs(self, capabilities):
        
        phantomjs_driver = self.config.get('Driver', 'phantomjs_driver_path')
        self.logger.debug("Phantom driver path given in properties: %s", phantomjs_driver)
        return webdriver.PhantomJS(executable_path=phantomjs_driver, desired_capabilities=capabilities)
1144687
def fetch(**kwargs):
    '''
    
    '''
    # fetch continues when no controlling terminal is present
    pre = ''
    post = ''
    run_args = {}
    if float(__grains__['osrelease']) >= 10.2:
        post += '--not-running-from-cron'
    else:
        pre += ' env PAGER=cat'
        run_args['python_shell'] = True
    return _wrapper('fetch', pre=pre, post=post, run_args=run_args, **kwargs)
214055
function(context, pkg, isRoot, deps){
		var stealPkg = utils.filter(deps, function(dep){
			return dep && dep.name === "steal";
		})[0];

		if(stealPkg) {
			return crawl.fetchDep(context, pkg, stealPkg, isRoot)
				.then(function(childPkg){
					if(childPkg) {
						return crawl.deps(context, childPkg);
					}
				});
		} else {
			return Promise.resolve();
		}
	}