Changeset 27317


Ignore:
Timestamp:
2013-05-08T15:27:52+12:00 (11 years ago)
Author:
davidb
Message:

Changes after testing on the jamendo set

Location:
gs2-extensions/afrepo/trunk/src/src
Files:
1 added
2 edited

Legend:

Unmodified
Added
Removed
  • gs2-extensions/afrepo/trunk/src/src/AFRepo.GSDLEXT.class.php.in

    r27290 r27317  
    66 * AFRepo top-level class to slot in with the Greenstone extension framework
    77 *
    8  * The audio is expected to be in subdirectories of the 'import-mp3' directory, and
     8 * The audio is expected to be in subdirectories of the 'audio-files' directory, and
    99 * for example purposes can be named in such a way that the example
    1010 * PathClassifier classifier can get meanining from it.
     
    1313class AFRepo extends AFRepoBase {
    1414    private $allfiles;
     15
     16    public function AFRepo()
     17    {
     18      $this->audio_files_dir = "audio-files";
     19      $this->af_prefix = getcwd() . "/" . $this->audio_files_dir;
     20    }
    1521
    1622    public function getName() {
     
    3642    }
    3743
    38     public function getAllFiles() {
     44    /**
     45     * getAudioPath
     46     * Return the path to the audio links in this repository (without a trailing
     47     * slash)
     48     */
     49    public function getAudioPath() {
     50        return realpath("audio-ids");
     51    }
     52
     53
     54    protected function remove_audio_files_prefix($full_filepath) {
     55#     echo "full filepath = " . $full_filepath . "\n";
     56#     echo "af prefix = " . $this->af_prefix . "\n";
     57
     58      $af_prefix_len = strlen($this->af_prefix);
     59      $filepath = $full_filepath;
     60
     61      if (substr($filepath, 0, $af_prefix_len) == $this->af_prefix) {
     62        $filepath = substr($filepath, $af_prefix_len);
     63      }
     64
     65#     echo "** filepath = " . $filepath . "\n";
     66
     67      return $filepath;
     68    }
     69
     70
     71    /**
     72     * fileInRepo
     73     * Return true if the audiofile with the given path (canonical or symlink)
     74     * is in the repository or false if not
     75     */
     76    public function fileInRepo($full_filepath) {
     77      $realpath = realpath($full_filepath);
     78      if ($realpath === false) {
     79        trigger_error("file '$filepath' does not exist on disk or is a broken symlink", E_USER_WARNING);
     80        return false;
     81      }
     82
     83      return array_key_exists($full_filepath, $this->getAllFiles());
     84    }
     85
     86
     87    /**
     88     * filePathToId
     89     * Return the ID of the audiofile with the given path (which can be
     90     * canonical or a symlink)
     91     */
     92    public function filePathToId($full_filepath) {
     93      if (!$this->fileInRepo($full_filepath)) {
     94        throw new Exception("file with path '$filepath' is not in the repository");
     95      }
     96
     97      $hash_filepath = "salami:/" . $this->remove_audio_files_prefix($full_filepath);
     98
     99##    echo "Hashing on: " . $hash_filepath . "\n";
     100
     101      $id = md5($hash_filepath);
     102      return $id;
     103    }
     104
     105
     106
     107    // recursive method to delete things from the links directory according to the
     108    // options
     109    function getAllCollectionFilesRec($collection, $path) {
     110
     111      echo "Processing directory: " . $path . "\n";
     112
     113      $dir = dir($path);
     114
     115      while (($entry = $dir->read()) !== false) {
     116
     117        if ($entry == "." || $entry == "..") {
     118          continue;
     119        }
     120
     121        $fullpath = $path . "/" . $entry;
     122
     123        $isdir = false;
     124        if (is_link($fullpath)) {
     125
     126          $realpath = readlink($fullpath);
     127
     128          // follow potential chain of sym-links
     129          while (is_link($realpath)) {
     130        $realpath = readlink($realpath);
     131          }
     132
     133          $isdir = is_dir($realpath);
     134        }
     135        else {
     136          $isdir = is_dir($fullpath);
     137        }
     138
     139
     140        if ($isdir) {
     141
     142          $this->getAllCollectionFilesRec($collection,$fullpath);
     143        }
     144        else {
     145          // assume it is a file
     146##        echo "Adding file: " . $fullpath . "\n";
     147          $this->allfiles[$fullpath] = true;
     148        }
     149      }
     150
     151      $dir->close();
     152     
     153    }
     154   
     155   
     156    public function getAllFiles()
     157    {
     158      if (!is_null($this->allfiles)) {
     159        return $this->allfiles;
     160      }
     161     
     162      $this->allfiles = array();
     163
     164##    $path = realpath($this->audio_files_dir);   
     165      $path = $this->af_prefix;
     166      $dir  = dir($path);
     167     
     168      while (($file = $dir->read()) !== false) {
     169
     170        if ($file[0] == ".") {
     171          // skip all dot files and dirs
     172          continue;
     173        }
     174
     175        $fullpath = $path . "/" . $file;
     176
     177        $isdir = false;
     178        if (is_link($fullpath)) {
     179
     180          $realpath = readlink($fullpath);
     181
     182          // follow potential chain of sym-links
     183          while (is_link($realpath)) {
     184        $realpath = readlink($realpath);
     185          }
     186
     187          $isdir = is_dir($realpath);
     188        }
     189        else {
     190          $isdir = is_dir($fullpath);
     191        }
     192
     193        if ($isdir) {
     194
     195          // recursively work through each collection directory
     196          $this->getAllCollectionFilesRec($file, $fullpath);
     197        }
     198      }
     199
     200      $dir->close();
     201     
     202      return $this->allfiles;
     203    }
     204
     205
     206    public function getAllFilesOLD() {
    39207        if (!is_null($this->allfiles))
    40208            return $this->allfiles;
    41209
    42210        $this->allfiles = array();
    43         $path = realpath("import-mp3");
     211        $path = realpath("audio-files");
    44212        $dir = dir($path);
    45213        while (($file = $dir->read()) !== false) {
  • gs2-extensions/afrepo/trunk/src/src/CASCADE-MAKE.sh

    r27287 r27317  
    3636
    3737echo ""
    38 echo "What about Override apache settings ?????"
    39 echo "****** Test to see if 'audiofiles' exists => generate message if not? ==> auto run cmd ???"
     38echo "****** Test to see if 'audio-files' exists => generate message if not? ==> auto run cmd ???"
    4039
     40./INSTALL-PHP.sh
    4141
    42 protocol=http
    43 hostname=`hostname`
    44 port=`egrep "^Listen" $GEXTAMP_INSTALLED/conf/httpd.conf | awk '{print $2}'`
    45 
    46 f4store_port=`echo $port+1 | bc`
    47 
    48 has_afrepo_conf=`egrep "^Include conf/httpd-afrepo.conf" "$GEXTAMP_INSTALLED/conf/httpd.conf"`
    49 
    50 if [ "x$has_afrepo_conf" = "x" ] ; then
    51   # Not currently in file => append it
    52 
    53   echo "Include conf/httpd-afrepo.conf" >> "$GEXTAMP_INSTALLED/conf/httpd.conf"
    54 fi
    55 
    56 cat "httpd-afrepo.conf.in" \
    57   | sed "s%@4store-http-prefix@%$protocol://$hostname:$f4store_port%g" > "$GEXTAMP_INSTALLED/conf/httpd-afrepo.conf"
    58 
    59 
    60 cat "AFRepo.GSDLEXT.class.php.in" \
    61   | sed "s%@afrepo-http-prefix@%$protocol://$hostname:$port%g" \
    62   | sed "s%@4store-http-prefix@%$protocol://$hostname:$f4store_port%g" > "$GEXTAMP_INSTALLED/htdocs/afrepo/AFRepo.class.php"
    63 
    64 cat DONE.txt \
    65   | sed "s%@GEXTAMP_INSTALLED@%$GEXTAMP_INSTALLED%g" \
    66   | sed "s%@4store-port@%$f4store_port%g" \
    67   | sed "s%@afrepo-http-prefix@%$protocol://$hostname:$port%g"
    68 
Note: See TracChangeset for help on using the changeset viewer.