Changeset 33978


Ignore:
Timestamp:
2020-02-26T19:57:05+13:00 (4 years ago)
Author:
ak19
Message:

Opens all geoJSON maps in new tabs instead of waiting for user to have processed each one in turn

Location:
other-projects/maori-lang-detection/src/org/greenstone/atea
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • other-projects/maori-lang-detection/src/org/greenstone/atea/CountryCodeCountsMapData.java

    r33959 r33978  
    656656    }
    657657
     658    public static void openFirefox() {
     659    // https://www.cyberciti.biz/faq/howto-run-firefox-from-the-command-line/
     660    String[] cmdArgs = {
     661        "firefox",
     662        "-P",
     663        "screenshot", //profile //"-profileManager=\"screenshot\"",
     664        //"--browser",
     665        "--devtools"
     666    };
     667   
     668    SafeProcess proc = new SafeProcess(cmdArgs);
     669    int retVal = proc.runProcess();
     670
     671    if(retVal != 0) {
     672        logger.info("Process out: " + proc.getStdOutput());
     673        logger.info("Process err: " + proc.getStdError());
     674        logger.info("Screenshot process returned with: " + retVal);
     675    }
     676    proc = null;
     677
     678    /*
     679    String[] tab_cmdArgs = {
     680        "firefox",
     681        "-new-tab",
     682        "-jsconsole"
     683    };
     684    proc = new SafeProcess(tab_cmdArgs);
     685    retVal = proc.runProcess();
     686    */
     687    }
     688
     689    public String getGeoJSONMapScreenshotCommand(File outputFolder, String fileNamePrefix) {
     690    // return the firefox :screenshot WEB CONSOLE command
     691    // Only works from Firefox version 62 onwards
     692    // https://developer.mozilla.org/en-US/docs/Tools/Taking_screenshots
     693
     694    String mapURL = this.getAsMapURL();
     695
     696    File outputFile = new File(outputFolder + File.separator + fileNamePrefix+".png");
     697    String outputFilePath = Utility.getFilePath(outputFile);
     698   
     699
     700    // Run in web console:
     701    // :screenshot --selector ".map" --file --filename "<outputPath/outputImageFile.ext>"
     702    // https://developer.mozilla.org/en-US/docs/Tools/Browser_Console
     703    String webConsoleCommand = ":screenshot --selector \".map\" --file --filename \"" + outputFilePath + "\""; 
     704    System.out.println("Run in Firefox web console's command line:");
     705    System.out.println(webConsoleCommand);
     706   
     707    // Launch firefox in a new tab
     708    // https://askubuntu.com/questions/57163/how-to-open-an-url-from-command-line-to-firefox-and-switch-to-tab
     709    //https://developer.mozilla.org/en-US/docs/Mozilla/Command_Line_Options
     710    String[] cmdArgs = {
     711        "firefox",
     712        //"-P",
     713        //"screenshot", // which does --profileManager "screenshot"
     714        //"--devtools", //"-jsconsole" opens browser console instead of web console
     715        "-new-tab",
     716        mapURL
     717    };
     718   
     719
     720    System.err.println();
     721    SafeProcess proc = new SafeProcess(cmdArgs);   
     722
     723    int retVal = proc.runProcess();
     724
     725    if(retVal != 0) {
     726        logger.info("Process out: " + proc.getStdOutput());
     727        logger.info("Process err: " + proc.getStdError());
     728        logger.info("Screenshot process returned with: " + retVal);
     729    }
     730
     731    return webConsoleCommand;
     732    }
     733
    658734    public String geoJsonMapScreenshot(File outputFolder, String fileNamePrefix) {
    659735    // https://stackoverflow.com/questions/49606051/how-to-take-a-screenshot-in-firefox-headless-selenium-in-java
  • other-projects/maori-lang-detection/src/org/greenstone/atea/SummaryTool.java

    r33940 r33978  
    356356     */
    357357    public static void main(String args[]) {
    358     SafeProcess.DEBUG = 1;
    359    
     358    int oldDebugMode = SafeProcess.DEBUG;
     359    SafeProcess.DEBUG = 0;
     360
    360361    if(args.length >= 2) {
    361362        printUsage();
     
    417418        // that GEOJSON_MAP_TOOL_URL takes as input to produce a map.
    418419
     420        ///CountryCodeCountsMapData.openFirefox();
     421       
    419422        for(int i = 1; i < tableFileNames.length; i++) { // empty element at 0
    420423            String tablefilename = tableFileNames[i] + ".json"; // filenames have no suffix
     
    453456            // to confirm if the JSON in the provided json file parses/is valid JSON.
    454457
     458            /*
    455459            String[] cmdArgs = {"python", "-mjson.tool", geoJsonFilename};
    456460            SafeProcess p = new SafeProcess(cmdArgs);
     
    465469            continue;
    466470            }
    467 
     471            */
    468472           
    469473            /*boolean uriEncoded = true;
     
    472476            */
    473477           
    474             logger.info("Data URL string: " + mapData.getAsMapURL());
     478            //logger.info("Data URL string: " + mapData.getAsMapURL());
    475479            logger.info("");
    476             mapData.geoJsonMapScreenshot(outFolder, tablefilename);
     480            //mapData.geoJsonMapScreenshot(outFolder, tablefilename);
     481            mapData.getGeoJSONMapScreenshotCommand(outFolder, tablefilename);
    477482            logger.info("---");
    478483
    479484            // TODO: Remove break. For debugging: breaks after first table -> map conversion.
    480             break;
     485            //break;
    481486        }
    482487       
     
    486491    } catch(Exception e) {
    487492        logger.error(e.getMessage(), e);
    488     }
     493    } finally {
     494        SafeProcess.DEBUG = oldDebugMode;
     495    }   
    489496    }
    490497}
Note: See TracChangeset for help on using the changeset viewer.