public File getSequencesDir() {
   File dir =
       new File(
           homeBilder.getPath()
               + File.separator
               + DIR_METADATEN_ROOT
               + File.separator
               + DIR_SEQUENCES);
   dir.mkdirs();
   return dir;
 }
 public String getAlbumName() {
   if (albumName != null) {
     return albumName;
   }
   // from text file "pm_album_name.txt"
   if (homeBilder == null) {
     return "not-found";
   }
   // File Album-name nicht vorhanden
   if (albumName == null) {
     homeFileAlbumName = new File(getMetaRootDir() + File.separator + FILE_ALBUM_NAME);
     if (!homeFileAlbumName.exists()) {
       try {
         homeFileAlbumName.createNewFile();
         PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(homeFileAlbumName)));
         out.println(homeBilder.getName());
         out.close();
         // read it now ...
       } catch (IOException e) {
         albumName = "cannot-create";
         return albumName;
       }
     }
     // File exist. Read it.
     try {
       BufferedReader in = new BufferedReader(new FileReader(homeFileAlbumName));
       while (true) {
         String line = in.readLine().trim();
         if (line.startsWith("#")) {
           continue;
         }
         albumName = line.trim();
         break;
       }
       in.close();
     } catch (IOException e) {
       albumName = "cannot-create";
       return albumName;
     }
   }
   return albumName;
 }
  private File getHomeFile() {

    File home = null;
    java.util.List result = new java.util.ArrayList();
    String value = null;

    // -----------------------------------------------------------------
    // <bilder>
    // -----------------------------------------------------------------
    result = PM_XML_Utils.getElementListe(document, "//" + TAG_HOME + "/" + TAG_BILDER);
    if (result.size() == 1) {
      value = ((Element) result.get(0)).getTextTrim();
      value = PM_Utils.removeLastSeparatorChar(value);
      home = new File(value);
      if (!home.isDirectory()) {
        home = null;
      }
    }
    return home;
  }
Esempio n. 4
0
  /**
   * This does the work of main, but it never calls System.exit, so it is appropriate to be called
   * progrmmatically. Termination of the program with a message to the user is indicated by throwing
   * Daikon.TerminationMessage.
   *
   * @see #main(String[])
   * @see daikon.Daikon.TerminationMessage
   */
  public static void mainHelper(final String[] args)
      throws FileNotFoundException, StreamCorruptedException, OptionalDataException, IOException,
          ClassNotFoundException {
    daikon.LogHelper.setupLogs(daikon.LogHelper.INFO);

    LongOpt[] longopts =
        new LongOpt[] {
          new LongOpt(Daikon.config_option_SWITCH, LongOpt.REQUIRED_ARGUMENT, null, 0),
          new LongOpt(output_SWITCH, LongOpt.REQUIRED_ARGUMENT, null, 0),
          new LongOpt(dir_SWITCH, LongOpt.REQUIRED_ARGUMENT, null, 0),
          new LongOpt(conf_SWITCH, LongOpt.NO_ARGUMENT, null, 0),
          new LongOpt(filter_SWITCH, LongOpt.NO_ARGUMENT, null, 0),
          new LongOpt(Daikon.debugAll_SWITCH, LongOpt.NO_ARGUMENT, null, 0),
          new LongOpt(Daikon.debug_SWITCH, LongOpt.REQUIRED_ARGUMENT, null, 0),
          new LongOpt(Daikon.ppt_regexp_SWITCH, LongOpt.REQUIRED_ARGUMENT, null, 0),
          new LongOpt(Daikon.track_SWITCH, LongOpt.REQUIRED_ARGUMENT, null, 0),
        };
    Getopt g = new Getopt("daikon.tools.InvariantChecker", args, "h", longopts);
    int c;
    while ((c = g.getopt()) != -1) {
      switch (c) {
        case 0:
          // got a long option
          String option_name = longopts[g.getLongind()].getName();
          if (Daikon.help_SWITCH.equals(option_name)) {
            System.out.println(usage);
            throw new Daikon.TerminationMessage();
          } else if (conf_SWITCH.equals(option_name)) {
            doConf = true;
          } else if (filter_SWITCH.equals(option_name)) {
            doFilter = true;
          } else if (dir_SWITCH.equals(option_name)) {
            dir_file = new File(g.getOptarg());
            if (!dir_file.exists() || !dir_file.isDirectory())
              throw new Daikon.TerminationMessage("Error reading the directory " + dir_file);

          } else if (output_SWITCH.equals(option_name)) {
            output_file = new File(g.getOptarg());
            output_stream = new PrintStream(new FileOutputStream(output_file));
          } else if (Daikon.config_option_SWITCH.equals(option_name)) {
            String item = g.getOptarg();
            daikon.config.Configuration.getInstance().apply(item);
            break;
          } else if (Daikon.debugAll_SWITCH.equals(option_name)) {
            Global.debugAll = true;
          } else if (Daikon.debug_SWITCH.equals(option_name)) {
            LogHelper.setLevel(g.getOptarg(), LogHelper.FINE);
          } else if (Daikon.track_SWITCH.equals(option_name)) {
            LogHelper.setLevel("daikon.Debug", LogHelper.FINE);
            String error = Debug.add_track(g.getOptarg());
            if (error != null) {
              throw new Daikon.TerminationMessage(
                  "Error parsing track argument '" + g.getOptarg() + "' - " + error);
            }
          } else {
            throw new RuntimeException("Unknown long option received: " + option_name);
          }
          break;
        case 'h':
          System.out.println(usage);
          throw new Daikon.TerminationMessage();
        case '?':
          break; // getopt() already printed an error
        default:
          System.out.println("getopt() returned " + c);
          break;
      }
    }

    // Loop through each filename specified
    for (int i = g.getOptind(); i < args.length; i++) {

      // Get the file and make sure it exists
      File file = new File(args[i]);
      if (!file.exists()) {
        throw new Error("File " + file + " not found.");
      }

      // These aren't "endsWith()" because there might be a suffix on the end
      // (eg, a date).
      String filename = file.toString();
      if (filename.indexOf(".inv") != -1) {
        if (inv_file != null) {
          throw new Daikon.TerminationMessage("multiple inv files specified", usage);
        }
        inv_file = file;
      } else if (filename.indexOf(".dtrace") != -1) {
        dtrace_files.add(filename);
      } else {
        throw new Error("Unrecognized argument: " + file);
      }
    }
    if (dir_file == null) {
      checkInvariants();
      return;
    }

    // Yoav additions:
    File[] filesInDir = dir_file.listFiles();
    if (filesInDir == null || filesInDir.length == 0)
      throw new Daikon.TerminationMessage("The directory " + dir_file + " is empty", usage);
    ArrayList<File> invariants = new ArrayList<File>();
    for (File f : filesInDir) if (f.toString().indexOf(".inv") != -1) invariants.add(f);
    if (invariants.size() == 0)
      throw new Daikon.TerminationMessage(
          "Did not find any invariant files in the directory " + dir_file, usage);
    ArrayList<File> dtraces = new ArrayList<File>();
    for (File f : filesInDir) if (f.toString().indexOf(".dtrace") != -1) dtraces.add(f);
    if (dtraces.size() == 0)
      throw new Daikon.TerminationMessage(
          "Did not find any dtrace files in the directory " + dir_file, usage);

    System.out.println(
        "Collecting data for invariants files " + invariants + " and dtrace files " + dtraces);

    dtrace_files.clear();
    for (File dtrace : dtraces) {
      dtrace_files.add(dtrace.toString());
    }

    String commaLine = "";
    for (File inFile : invariants) {
      String name = inFile.getName().replace(".inv", "").replace(".gz", "");
      commaLine += "," + name;
    }
    outputComma.add(commaLine);

    commaLine = "";
    for (File inFile : invariants) {
      inv_file = inFile;
      failedInvariants.clear();
      testedInvariants.clear();
      error_cnt = 0;

      output_stream =
          new PrintStream(
              new FileOutputStream(
                  inFile.toString().replace(".inv", "").replace(".gz", "")
                      + ".false-positives.txt"));
      checkInvariants();
      output_stream.close();

      int failedCount = failedInvariants.size();
      int testedCount = testedInvariants.size();
      String percent = toPercentage(failedCount, testedCount);
      commaLine += "," + percent;
    }
    outputComma.add(commaLine);

    System.out.println();
    for (String output : outputComma) System.out.println(output);
  }
  private void setBackup() {
    List result = new ArrayList();

    // -----------------------------------------------------------------
    // <vdr-plugin>
    // -----------------------------------------------------------------
    result = PM_XML_Utils.getElementListe(document, "//" + TAG_BACKUP + "/" + TAG_VDR_PLUGIN);
    if (result.size() == 1) {
      vdrPlugin = true;
      Element elPlugin = (Element) result.get(0);

      vdrPlugHost = PM_XML_Utils.getAttribute(elPlugin, ATTR_VDR_HOST);
      vdrPlugName = PM_XML_Utils.getAttribute(elPlugin, ATTR_VDR_NAME);
      vdrPlugINDEX = PM_XML_Utils.getAttribute(elPlugin, ATTR_VDR_INDEX);
      vdrPlugMPG = PM_XML_Utils.getAttribute(elPlugin, ATTR_VDR_MPG);
      vdrOverscanX = PM_XML_Utils.getAttribute(elPlugin, ATTR_VDR_OV_X);
      vdrOverscanY = PM_XML_Utils.getAttribute(elPlugin, ATTR_VDR_OV_Y);
    }
    // -----------------------------------------------------------------
    // <bilder>
    // -----------------------------------------------------------------
    result = PM_XML_Utils.getElementListe(document, "//" + TAG_BACKUP + "/" + TAG_BILDER_BILDER);
    for (int i = 0; i < result.size(); i++) {
      Element el = (Element) result.get(i);
      BackUp bB =
          new BackUp(
              PM_XML_Utils.getAttribute(el, ATTR_BILDER_NAME),
              homeBilder.getPath(), // from
              PM_XML_Utils.getAttribute(el, ATTR_BILDER_DIR), // TO
              PM_XML_Utils.getAttributeBoolean(el, ATTR_BILDER_MPEG));
      backupBilderList.add(bB);
    }

    // ----------------------------------------------------------------------------------------------
    // <daten>
    // ----------------------------------------------------------------------------------------------
    result = PM_XML_Utils.getElementListe(document, "//" + TAG_BACKUP + "/" + TAG_DATEN);
    for (int i = 0; i < result.size(); i++) {
      Element el = (Element) result.get(i);
      BackUp bB =
          new BackUp(
              PM_XML_Utils.getAttribute(el, ATTR_DATEN_NAME),
              PM_XML_Utils.getAttribute(el, ATTR_DATEN_FROM), // from
              PM_XML_Utils.getAttribute(el, ATTR_DATEN_TO), // TO
              false // no mepeg files
              );
      backupDatenList.add(bB);
    }
    // ----------------------------------------------------------------------------------------------
    // <album>
    // ----------------------------------------------------------------------------------------------
    result = PM_XML_Utils.getElementListe(document, "//" + TAG_BACKUP + "/" + TAG_ALBUM);
    for (int i = 0; i < result.size(); i++) {
      Element el = (Element) result.get(i);
      BackUp bB =
          new BackUp(
              PM_XML_Utils.getAttribute(el, ATTR_ALBUM_NAME),
              homeBilder.getPath(), // from
              PM_XML_Utils.getAttribute(el, ATTR_ALBUM_DIR),
              false // no mpeg files
              );
      backupAlbumList.add(bB);
    }
  }
 public File getMetaRootDir() {
   return new File(homeBilder.getPath() + File.separator + DIR_METADATEN_ROOT);
 }
 public String getPathMetadatenRoot() {
   File directory = new File(homeBilder.getPath() + File.separator + DIR_METADATEN_ROOT);
   return directory.getPath();
 }
  // The private constructor
  private PM_Configuration(String[] args) {

    File fileEinstellungen = null;
    File directoryHomeBilder = null;

    // --------------------------------
    // �bernehmen Start-Parameter
    // --------------------------------
    int c;
    Getopt g = new Getopt("photo-manager", args, "e:b:i:n::d::");
    String arg;
    while ((c = g.getopt()) != -1) {
      switch (c) {
        case 'e':
          arg = g.getOptarg();
          fileEinstellungen = (arg == null) ? null : new File(arg);
          break;
        case 'b':
          arg = g.getOptarg();
          directoryHomeBilder = (arg == null) ? null : new File(arg);
          break;
        case 'n': // batch
          batch = true;
          break;
          // case 'd': // daemon und batch
          // demon = true;
          // batch = true;
          // break;
        case 'i':
          arg = g.getOptarg();
          if (arg != null) {
            importFiles.add(new File(arg));
          }
          break;
      }
    }

    // Jetzt noch die ohne Options.Das sind dann Import-Files
    for (int i = g.getOptind(); i < args.length; i++) {
      importFiles.add(new File(args[i]));
    }

    // --------------------------------------------------------------
    // Reihenfolge:
    // 1. a. -e Parameter auswerten
    // b. nigefu: .photo-manager/pm_einstellungen.xml suchen
    // c. nigefu: Locale prompten und .photo-manager/pm_einstellungen.xml
    // neu anlegen
    // 2. a. -b Parameter auswerten
    // b. nigefu: Eintrag in .photo-manager/pm_einstellungen.xml suchen
    // c. nigefu: prompten (ERROR wenn batch)
    // 3. Wenn in .photo-manager/pm_einstellungen.xml
    // Bilder-Dir nicht eingetragen, dann dort eintragen.
    // (wenn vorhanden, nicht �berschreiben)
    // ------------------------------------------------------------------

    // --------------------------------------------------------------------
    // (1) pm_einstellungen.xml und locale ermitteln
    // --------------------------------------------------------------------
    if (fileEinstellungen != null && fileEinstellungen.isFile()) {
      // (1.a.) -e Parameter vorhanden:
      // open und lesen locale
      xmlFile = fileEinstellungen;
      openDocument(OPEN_READ_ONLY);
      locale = getLocale();
      if (locale == null) {
        locale = (new PM_WindowDialogGetLocale().getLocale());
        setLocale(locale);
        writeDocument();
      }
    } else {
      // (1.b.) -e nicht angegeben
      fileEinstellungen = new File(PM_Utils.getConfigDir() + File.separator + FILE_EINSTELLUNGEN);
      if (fileEinstellungen.isFile()) {
        // (1.b) in .photo-manager/pm_einstellungen.xml Datei gefunden
        xmlFile = fileEinstellungen;
        openDocument(OPEN_READ_ONLY);
        locale = getLocale();

        if (locale == null) {
          locale = (new PM_WindowDialogGetLocale().getLocale());
          setLocale(locale);
          writeDocument();
        }
      } else {
        // pm_einstellungen.xml nigefu:
        // locale prompten und pm_einstellungen neu anlegen
        locale = (new PM_WindowDialogGetLocale().getLocale());
        xmlFile = fileEinstellungen;
        rootTagName = rootTag;
        openDocument(OPEN_CREATE);
        setLocale(locale);
        writeDocument();
      }
    }

    // ---------------------------------------------------------------
    // (2) Bilder Dir ermitteln
    // ---------------------------------------------------------------

    if (directoryHomeBilder != null && directoryHomeBilder.isDirectory()) {
      // --- es wurde -b <top level directory> angegeben
      homeBilder = directoryHomeBilder;
      setHomeBilder(homeBilder.getPath());
      writeDocument();
    } else {
      // jetzt muss homeBilder aus der xml-Datei gelesen werden.
      // Wenn nigefu., dann prompten und eingtragen
      homeBilder = getHomeFile();
      if (homeBilder == null || homeBilder.isDirectory() == false) {
        if (batch) {
          System.out.println("ERROR: batch kein TLPD gefunden");
          System.out.println("abnormal end");
          System.exit(0);
        }
        PM_MSG.setResourceBundle(locale);
        PM_WindowGetTLPD sp = new PM_WindowGetTLPD();
        homeBilder = sp.getResult();
        if (homeBilder == null) {
          setLocale(locale);
          writeDocument();
          System.out.println("abnormal end (no TLPD)");
          System.exit(0);
        }
        setLocale(locale);
        setHomeBilder(homeBilder.getPath());
        writeDocument();
      }
    }

    // -----------------------------------------------------
    // Jetzt gibt es:
    // ein korrektes xmlFile mit einem homeBilder Eintrag
    // homeBilder ist korrekt versorgt
    // --------------------------------------------------------

    // System.out.println("Locale = "+ locale);
    PM_MSG.setResourceBundle(locale);

    setAllPrinter();
    setPrinterFormat();
    setDateFromTo();
    setPrefetch();
    setSlideshow();
    setBackup();
    setSequences();
    setMpeg();

    // homeLuceneDB in -e nicht eingetragn
    if (homeLuceneDB == null) {
      homeLuceneDB =
          new File(
              homeBilder.getPath()
                  + File.separator
                  + DIR_METADATEN_ROOT
                  + File.separator
                  + DIR_LUCENE_DB);
      homeLuceneDB.mkdirs();
    }

    // Temp-Dir nicht vorhanden
    if (homeTemp == null) {
      homeTemp = new File(homeBilder.getPath() + File.separator + DIR_PM_TEMP); // "pm_temp");
      homeTemp.mkdirs();
    }

    // Externe-Programme nicht vorhanden
    if (homeExtProgramme == null) {
      homeExtProgramme =
          new File(PM_Utils.getConfigDir() + File.separator + FILE_EXTERNE_PROGRAMME);
    }

    // InitValues nicht vorhanden
    if (homeInitValues == null) {
      homeInitValues = new File(PM_Utils.getConfigDir() + File.separator + FILE_INIT_VALUES);
    }
  }