Exemplo n.º 1
0
void Kernel::infer(std::vector<std::string> args)
{
    if (args.empty())
    {
        std::cout << getUsageString() << std::flush;
        return;
    }

    if (args.size() == 1)
    {
        if (args[0] == "help" || args[0] == "-h" || args[0] == "--help")
        {
            std::cout << getUsageString() << std::flush;
            return;
        }
    }

    // TODO Allow multiple.
    Paths paths;

    std::size_t threads(4);
    Json::Value jsonReprojection;
    std::string user;
    std::string tmpPath("tmp");
    bool trustHeaders(true);

    std::string output;

    std::size_t a(0);

    while (a < args.size())
    {
        const std::string arg(args[a]);

        if (arg.front() != '-')
        {
            // If this is not an option argument, use it as the path.
            if (paths.empty())
            {
                paths.push_back(arg);
            }
            else
            {
                throw std::runtime_error(
                        "Only one path allowed - found both '" +
                        paths.front() + "' and '" + arg + "'");
            }
        }
        else if (arg == "-a")
        {
            if (++a < args.size())
            {
                tmpPath = args[a];
            }
            else
            {
                throw std::runtime_error("Invalid tmp specification");
            }
        }
        else if (arg == "-o")
        {
            if (++a < args.size())
            {
                output = args[a] + ".entwine-inference";
            }
            else
            {
                throw std::runtime_error("Invalid output specification");
            }
        }
        else if (arg == "-r")
        {
            if (++a < args.size())
            {
                const bool onlyOutput(
                        a + 1 >= args.size() ||
                        args[a + 1].front() == '-');

                if (onlyOutput)
                {
                    jsonReprojection["out"] = args[a];
                }
                else
                {
                    jsonReprojection["in"] = args[a];
                    jsonReprojection["out"] = args[++a];
                }
            }
            else
            {
                throw std::runtime_error("Invalid reprojection argument");
            }
        }
        else if (arg == "-h")
        {
            jsonReprojection["hammer"] = true;
        }
        else if (arg == "-x")
        {
            trustHeaders = false;
        }
        else if (arg == "-t")
        {
            if (++a < args.size())
            {
                threads = Json::UInt64(std::stoul(args[a]));
            }
            else
            {
                throw std::runtime_error("Invalid thread count specification");
            }
        }
        else if (arg == "-u")
        {
            if (++a < args.size())
            {
                user = args[a];
            }
            else
            {
                throw std::runtime_error("Invalid AWS user argument");
            }
        }

        ++a;
    }

    entwine::arbiter::fs::mkdirp(tmpPath);

    std::unique_ptr<Reprojection> reprojection;

    if (jsonReprojection.isMember("out"))
    {
        reprojection.reset(new Reprojection(jsonReprojection));
    }

    Json::Value arbiterConfig;
    arbiterConfig["s3"]["profile"] = user;

    auto arbiter(std::make_shared<entwine::arbiter::Arbiter>(arbiterConfig));

    const auto reprojString(getReprojString(reprojection.get()));
    const auto trustHeadersString(trustHeaders ? "yes" : "no");

    std::cout << "Inferring from: " << paths.front() << std::endl;
    std::cout << "\tTemp path: " << tmpPath << std::endl;
    std::cout << "\tThreads: " << threads << std::endl;
    std::cout << "\tReprojection: " << reprojString << std::endl;
    std::cout << "\tTrust file headers? " << trustHeadersString << std::endl;

    const bool allowDelta(true);
    const bool verbose(true);
    const bool cesiumify(false);

    Inference inference(
            paths,
            reprojection.get(),
            trustHeaders,
            allowDelta,
            tmpPath,
            threads,
            verbose,
            cesiumify,
            arbiter.get());

    inference.go();

    if (output.size())
    {
        std::cout << "Writing details to " << output << "..." << std::endl;
        Json::Value json(inference.toJson());
        arbiter->put(output, json.toStyledString());
    }

    std::cout << "Schema: " << inference.schema() << std::endl;
    std::cout << "Bounds: " << inference.bounds() << std::endl;
    std::cout << "Points: " << commify(inference.numPoints()) << std::endl;

    if (reprojection)
    {
        std::cout << "Reprojection: " << *reprojection << std::endl;
    }

    if (const auto delta = inference.delta())
    {
        std::cout << "Scale:  " << delta->scale() << std::endl;
        std::cout << "Offset: " << delta->offset() << std::endl;
    }
}
Exemplo n.º 2
0
int
main( int argc, char** argv)
{
  fs::path full_path( fs::initial_path<fs::path>() );

  if ( argc > 1 )
    full_path = fs::system_complete( fs::path( argv[1], fs::native ) );
  else
    PrintUsage();

  // specification of hi, low date of studies
  if( argc > 2)
  {
    string s(argv[2]);
    if( s.compare( "--info") == 0 )
    {
      entryCont.infoOnly = true;
    }
    else
    {
      if( argc > 3)
      {
        entryCont.dateFrom = argv[2];
        entryCont.dateTo = argv[3];
      }
      else
        PrintUsage();
    }
  }

  // recursively (through queue) go through all files in subtree
  // of specified directory specified

  try {
    if ( fs::is_directory( full_path ) )
    {
      paths.push( full_path);
    }
    else // must be a file
    {
      entryCont.SolveFile( full_path.string(), "buddy" );
    }

    fs::path currPath;
    while( ! paths.empty() )
    {
      currPath = paths.front();
      SolveDir( currPath);
      paths.pop(); // remove this dir from queue
    }
    
  } catch( std::exception &ex) {
    LOG( ex.what());
  }

  // flush info
  {
    ofstream o("output.txt");
    entryCont.FlushMaps( o);
    o.close();
  }
  
  return 0;
}