示例#1
0
  @Internal("file.copy")
  public static LogicalVector fileCopy(
      @Current Context context,
      StringVector fromFiles,
      String to,
      boolean overwrite,
      final boolean recursive)
      throws FileSystemException {
    LogicalArrayVector.Builder result = new LogicalArrayVector.Builder();
    FileObject toFile = context.resolveFile(to);
    for (String from : fromFiles) {
      try {
        toFile.copyFrom(
            context.resolveFile(from),
            new FileSelector() {

              @Override
              public boolean traverseDescendents(FileSelectInfo fileInfo) throws Exception {
                return true;
              }

              @Override
              public boolean includeFile(FileSelectInfo fileInfo) throws Exception {
                return recursive;
              }
            });
        result.add(true);
      } catch (FileSystemException e) {
        result.add(false);
      }
    }
    return result.build();
  }
示例#2
0
  @Internal("Sys.setenv")
  public static LogicalVector setEnvironment(
      @Current Context context, StringVector names, StringVector values) {

    Map<String, String> map = context.getSession().getSystemEnvironment();

    LogicalArrayVector.Builder result = new LogicalArrayVector.Builder();
    for (int i = 0; i != names.length(); ++i) {
      map.put(names.getElementAsString(i), values.getElementAsString(i));
      result.add(true);
    }
    return result.build();
  }
示例#3
0
  @Internal
  public static LogicalVector capabilities() {

    LogicalArrayVector.Builder result = new LogicalArrayVector.Builder();
    StringVector.Builder names = new StringVector.Builder();

    for (String capability : Capabilities.NAMES) {
      names.add(capability);
      result.add(false);
    }
    result.setAttribute(Symbols.NAMES, names.build());
    return result.build();
  }
示例#4
0
  /**
   * Utility function to extract information about files on the user's file systems.
   *
   * @param context current call Context
   * @param paths the list of files for which to return information
   * @return list column-oriented table of file information
   * @throws FileSystemException
   */
  @Internal("file.info")
  public static ListVector fileInfo(@Current Context context, StringVector paths)
      throws FileSystemException {

    DoubleArrayVector.Builder size = new DoubleArrayVector.Builder();
    LogicalArrayVector.Builder isdir = new LogicalArrayVector.Builder();
    IntArrayVector.Builder mode =
        (IntArrayVector.Builder)
            new IntArrayVector.Builder()
                .setAttribute(Symbols.CLASS, StringVector.valueOf("octmode"));
    DoubleArrayVector.Builder mtime = new DoubleArrayVector.Builder();
    StringVector.Builder exe = new StringVector.Builder();

    for (String path : paths) {
      if (StringVector.isNA(path)) {
        throw new EvalException("invalid filename argument");
      }
      FileObject file = context.resolveFile(path);
      if (file.exists()) {
        if (file.getType() == FileType.FILE) {
          size.add((int) file.getContent().getSize());
        } else {
          size.add(0);
        }
        isdir.add(file.getType() == FileType.FOLDER);
        mode.add(mode(file));
        try {
          mtime.add(file.getContent().getLastModifiedTime());
        } catch (Exception e) {
          mtime.add(0);
        }
        exe.add(file.getName().getBaseName().endsWith(".exe") ? "yes" : "no");
      } else {
        size.addNA();
        isdir.addNA();
        mode.addNA();
        mtime.addNA();
        exe.addNA();
      }
    }

    return ListVector.newNamedBuilder()
        .add("size", size)
        .add("isdir", isdir)
        .add("mode", mode)
        .add("mtime", mtime)
        .add("ctime", mtime)
        .add("atime", mtime)
        .add("exe", exe)
        .build();
  }