예제 #1
0
  /**
   * Construct a {@link SubProcessHeavy SubProcessHeavy} instance which when executed will fulfill
   * the given action agenda.
   *
   * <p>
   *
   * @param agenda The agenda to be accomplished by the action.
   * @param outFile The file to which all STDOUT output is redirected.
   * @param errFile The file to which all STDERR output is redirected.
   * @return The SubProcess which will fulfill the agenda.
   * @throws PipelineException If unable to prepare a SubProcess due to illegal, missing or
   *     imcompatable information in the action agenda or a general failure of the prep method code.
   */
  public SubProcessHeavy prep(ActionAgenda agenda, File outFile, File errFile)
      throws PipelineException {
    NodeID nodeID = agenda.getNodeID();

    /* sanity checks */
    String opname = null;
    File source = null;
    File preRender = null;
    File postRender = null;
    File preFrame = null;
    File postFrame = null;
    {
      {
        FileSeq fseq = agenda.getPrimaryTarget();
        if (!fseq.hasFrameNumbers())
          throw new PipelineException(
              "The HfsComposite Action requires that the output images have frame numbers.");
      }

      /* generate the filename of the Houdini scene to load */
      {
        String sname = (String) getSingleParamValue("HoudiniScene");
        if (sname != null) {
          FileSeq fseq = agenda.getPrimarySource(sname);
          if (fseq == null)
            throw new PipelineException(
                "Somehow the Houdini Scene node ("
                    + sname
                    + ") was not one of the source "
                    + "nodes!");

          String suffix = fseq.getFilePattern().getSuffix();
          if (!fseq.isSingle() || (suffix == null) || !suffix.equals("hip"))
            throw new PipelineException(
                "The HfsComposite Action requires that the source node specified by the "
                    + "Houdini Scene parameter ("
                    + sname
                    + ") must have a single Houdini scene "
                    + "file (.hip) as its primary file sequence!");

          NodeID snodeID = new NodeID(nodeID, sname);
          source =
              new File(PackageInfo.sProdDir, snodeID.getWorkingParent() + "/" + fseq.getFile(0));
        } else {
          throw new PipelineException(
              "The HfsComposite Action requires the Houdini Scene parameter to be set!");
        }
      }

      /* the full name of the geometry output operator */
      {
        String name = (String) getSingleParamValue("OutputOperator");
        if ((name == null) || (name.length() == 0))
          throw new PipelineException(
              "The HfsComposite Action requires a valid Output Operator name!");

        opname = ("/out/" + name);
      }

      /* command script files */
      {
        String sname = (String) getSingleParamValue("PreRenderScript");
        if (sname != null) {
          FileSeq fseq = agenda.getPrimarySource(sname);
          if (fseq == null)
            throw new PipelineException(
                "Somehow the Pre Render Script node ("
                    + sname
                    + ") was not one of the "
                    + "source nodes!");

          String suffix = fseq.getFilePattern().getSuffix();
          if (!fseq.isSingle() || (suffix == null) || !(suffix.equals("cmd")))
            throw new PipelineException(
                "The HfsComposite Action requires that the source node specified by the Pre "
                    + "Render Script parameter ("
                    + sname
                    + ") must have a single command script "
                    + "(.cmd) as its primary file sequence!");

          NodeID snodeID = new NodeID(nodeID, sname);
          preRender =
              new File(PackageInfo.sProdDir, snodeID.getWorkingParent() + "/" + fseq.getFile(0));
        }
      }

      {
        String sname = (String) getSingleParamValue("PostRenderScript");
        if (sname != null) {
          FileSeq fseq = agenda.getPrimarySource(sname);
          if (fseq == null)
            throw new PipelineException(
                "Somehow the Post Render Script node ("
                    + sname
                    + ") was not one of the "
                    + "source nodes!");

          String suffix = fseq.getFilePattern().getSuffix();
          if (!fseq.isSingle() || (suffix == null) || !(suffix.equals("cmd")))
            throw new PipelineException(
                "The HfsComposite Action requires that the source node specified by the "
                    + "Post Render Script parameter ("
                    + sname
                    + ") must have a single command "
                    + "script (.cmd) as its primary file sequence!");

          NodeID snodeID = new NodeID(nodeID, sname);
          postRender =
              new File(PackageInfo.sProdDir, snodeID.getWorkingParent() + "/" + fseq.getFile(0));
        }
      }

      {
        String sname = (String) getSingleParamValue("PreFrameScript");
        if (sname != null) {
          FileSeq fseq = agenda.getPrimarySource(sname);
          if (fseq == null)
            throw new PipelineException(
                "Somehow the Pre Frame Script node ("
                    + sname
                    + ") was not one of the "
                    + "source nodes!");

          String suffix = fseq.getFilePattern().getSuffix();
          if (!fseq.isSingle() || (suffix == null) || !(suffix.equals("cmd")))
            throw new PipelineException(
                "The HfsComposite Action requires that the source node specified by the Pre "
                    + "Frame Script parameter ("
                    + sname
                    + ") must have a single command script "
                    + "(.cmd) as its primary file sequence!");

          NodeID snodeID = new NodeID(nodeID, sname);
          preFrame =
              new File(PackageInfo.sProdDir, snodeID.getWorkingParent() + "/" + fseq.getFile(0));
        }
      }

      {
        String sname = (String) getSingleParamValue("PostFrameScript");
        if (sname != null) {
          FileSeq fseq = agenda.getPrimarySource(sname);
          if (fseq == null)
            throw new PipelineException(
                "Somehow the Post Frame Script node ("
                    + sname
                    + ") was not one of the "
                    + "source nodes!");

          String suffix = fseq.getFilePattern().getSuffix();
          if (!fseq.isSingle() || (suffix == null) || !(suffix.equals("cmd")))
            throw new PipelineException(
                "The HfsComposite Action requires that the source node specified by the "
                    + "Post Frame Script parameter ("
                    + sname
                    + ") must have a single command "
                    + "script (.cmd) as its primary file sequence!");

          NodeID snodeID = new NodeID(nodeID, sname);
          postFrame =
              new File(PackageInfo.sProdDir, snodeID.getWorkingParent() + "/" + fseq.getFile(0));
        }
      }
    }

    /* create the temporary Houdini command script */
    File hscript = createTemp(agenda, 0644, "cmd");
    try {
      FileWriter out = new FileWriter(hscript);

      FileSeq fseq =
          new FileSeq(
              PackageInfo.sProdDir.getPath() + nodeID.getWorkingParent(),
              agenda.getPrimaryTarget());
      if (fseq.hasFrameNumbers()) {
        FilePattern fpat = fseq.getFilePattern();
        FrameRange frange = fseq.getFrameRange();
        out.write(
            "opparm "
                + opname
                + " trange on\n"
                + "opparm "
                + opname
                + " f1 "
                + frange.getStart()
                + "\n"
                + "opparm "
                + opname
                + " f2 "
                + frange.getEnd()
                + "\n"
                + "opparm "
                + opname
                + " f3 "
                + frange.getBy()
                + "\n"
                + "opparm "
                + opname
                + " copoutput '"
                + fpat.getPrefix()
                + ".$F");

        if (fpat.getPadding() > 1) out.write(String.valueOf(fpat.getPadding()));

        out.write("." + fpat.getSuffix() + "'\n");
      } else {
        out.write("opparm " + opname + " trange off\n" + "opparm " + opname + " " + fseq + "\n");
      }

      if (preRender != null) out.write("opparm " + opname + " prerender '" + preRender + "'\n");

      if (postRender != null) out.write("opparm " + opname + " postrender '" + postRender + "'\n");

      if (preFrame != null) out.write("opparm " + opname + " preframe '" + preFrame + "'\n");

      if (postFrame != null) out.write("opparm " + opname + " postframe '" + postFrame + "'\n");

      out.write("opparm -c " + opname + " execute\n");

      out.close();
    } catch (IOException ex) {
      throw new PipelineException(
          "Unable to write temporary script file ("
              + hscript
              + ") for Job "
              + "("
              + agenda.getJobID()
              + ")!\n"
              + ex.getMessage());
    }

    /* create the wrapper shell script */
    File script = createTemp(agenda, 0755, "bash");
    try {
      FileWriter out = new FileWriter(script);
      out.write("#!/bin/bash\n\n" + "cat " + hscript + " | hscript -v " + source);
      out.close();
    } catch (IOException ex) {
      throw new PipelineException(
          "Unable to write temporary script file ("
              + script
              + ") for Job "
              + "("
              + agenda.getJobID()
              + ")!\n"
              + ex.getMessage());
    }

    try {
      return new SubProcessHeavy(
          agenda.getNodeID().getAuthor(),
          getName() + "-" + agenda.getJobID(),
          script.getPath(),
          new ArrayList<String>(),
          agenda.getEnvironment(),
          agenda.getWorkingDir(),
          outFile,
          errFile);
    } catch (Exception ex) {
      throw new PipelineException(
          "Unable to generate the SubProcess to perform this Action!\n" + ex.getMessage());
    }
  }
예제 #2
0
  /** Add the UI components for the given file sequence to the panel. */
  private void addFileSeqPanel(FileSeq fseq) {
    boolean isPresentInWorking = false;
    if ((pStatus != null) && pStatus.hasLightDetails()) {
      NodeDetailsLight details = pStatus.getLightDetails();
      NodeMod mod = details.getWorkingVersion();
      if (mod != null) {
        if (mod.getPrimarySequence().equals(fseq)) isPresentInWorking = true;
        else {
          for (FileSeq sfseq : mod.getSecondarySequences()) {
            if (sfseq.equals(fseq)) {
              isPresentInWorking = true;
              break;
            }
          }
        }
      }
    }

    /* collate the row information */
    ArrayList<VersionID> vids = new ArrayList<VersionID>();
    ArrayList<FileSeq> singles = new ArrayList<FileSeq>();
    TreeSet<FileSeq> enabled = new TreeSet<FileSeq>();
    TreeMap<FileSeq, FileState> fstates = new TreeMap<FileSeq, FileState>();
    TreeMap<FileSeq, NativeFileInfo> finfos = new TreeMap<FileSeq, NativeFileInfo>();
    TreeMap<FileSeq, QueueState> qstates = new TreeMap<FileSeq, QueueState>();
    TreeMap<FileSeq, Boolean[]> novel = new TreeMap<FileSeq, Boolean[]>();
    {
      TreeMap<FileSeq, Integer> wsingles = new TreeMap<FileSeq, Integer>();
      if ((pStatus != null) && pStatus.hasLightDetails()) {
        if (isPresentInWorking) {
          if (pStatus.hasHeavyDetails()) {
            NodeDetailsHeavy details = pStatus.getHeavyDetails();

            FileState[] fs = details.getFileStates(fseq);
            QueueState[] qs = details.getQueueStates();
            NativeFileInfo[] infos = details.getFileInfos(fseq);
            if ((fs != null) && (qs != null) && (infos != null)) {
              int wk;
              for (wk = 0; wk < fs.length; wk++) {
                FileSeq sfseq = new FileSeq(fseq, wk);
                wsingles.put(sfseq, wk);

                fstates.put(sfseq, fs[wk]);
                finfos.put(sfseq, infos[wk]);
                qstates.put(sfseq, qs[wk]);

                if (fs[wk] != FileState.CheckedIn) enabled.add(sfseq);
              }
            }
          } else {
            NodeDetailsLight details = pStatus.getLightDetails();

            int wk;
            for (wk = 0; wk < fseq.numFrames(); wk++) {
              FileSeq sfseq = new FileSeq(fseq, wk);
              wsingles.put(sfseq, wk);

              if (details.getVersionState() == VersionState.CheckedIn) {
                fstates.put(sfseq, FileState.CheckedIn);
                qstates.put(sfseq, QueueState.Undefined);
              } else {
                enabled.add(sfseq);
              }
            }
          }
        }

        {
          vids.addAll(pNovelty.keySet());
          Collections.reverse(vids);

          int idx = 0;
          for (VersionID vid : vids) {
            TreeMap<FileSeq, boolean[]> table = pNovelty.get(vid);
            for (FileSeq nfseq : table.keySet()) {
              if (fseq.similarTo(nfseq)) {
                boolean[] flags = table.get(nfseq);

                int wk;
                for (wk = 0; wk < flags.length; wk++) {
                  FileSeq sfseq = new FileSeq(nfseq, wk);
                  if (!wsingles.containsKey(sfseq)) wsingles.put(sfseq, null);

                  Boolean[] rflags = novel.get(sfseq);
                  if (rflags == null) {
                    rflags = new Boolean[pNovelty.size()];
                    novel.put(sfseq, rflags);
                  }

                  rflags[idx] = new Boolean(flags[wk]);
                }

                break;
              }
            }

            idx++;
          }
        }
      }

      TreeMap<Integer, FileSeq> order = new TreeMap<Integer, FileSeq>();
      for (FileSeq sfseq : wsingles.keySet()) {
        int frame = -1;
        if (sfseq.hasFrameNumbers()) frame = sfseq.getFrameRange().getStart();

        order.put(frame, sfseq);
      }

      singles.addAll(order.values());
    }

    /* add the panel */
    {
      JFileSeqPanel panel =
          new JFileSeqPanel(
              this,
              pManagerPanel,
              pStatus,
              pPrivilegeDetails,
              fseq,
              vids,
              pOffline,
              singles,
              fstates,
              finfos,
              qstates,
              enabled,
              novel,
              pIsListLayout);

      if (pIsListLayout) pFileSeqsBox.add(panel);
      else pFileSeqsTab.addTab(fseq.getFilePattern().toString(), sTabIcon, panel);

      pFileSeqPanels.put(fseq, panel);
    }
  }