[Clipart] r38 - makerelease
noreply at openclipart.org
noreply at openclipart.org
Sun Jun 28 02:10:43 PDT 2009
Author: rejon
Date: Sun Jun 28 09:10:42 2009
New Revision: 38
Log:
cleaned up the classes
Added:
makerelease/makerelease.php
makerelease/releaser.php
Modified:
makerelease/downloader.php
Modified: makerelease/downloader.php
==============================================================================
--- makerelease/downloader.php Sun Jun 28 08:33:43 2009 (r37)
+++ makerelease/downloader.php Sun Jun 28 09:10:42 2009 (r38)
@@ -5,172 +5,9 @@
* @version 1.1
* @date 2009-03-19
*
- * This php shell script creates a openclipart file release.
+ * This php shell script downloads the latest openclipart package
*
- * It uses wget to download the daily SVG tarball from openclipart.org,
- * fires inkscape to rasterize all images and create thumbnails,
- * creates a HTML-Gallery for offline viewing, creates .zip, .tar.gz and .tar.bz2
- * bundles and uploads them with rsync.
- * A log with all messages is stored in lastrun.log
- *
- * It has been developed for windows and linux
- *
- * It requires the following tools to be installed:
- * - php (obviously, to run this script, fire <path to your php>\php downloader.php). For windows you can also use xampp, http://www.apachefriends.org/en/xampp-windows.html
- * - the GD-extension of PHP
- * - a high memory_limit in the php.ini file. 32mb didn't suffice for big PNGs but I never had any issue with 320...
- * - wget, tar, bzip2 (for windows: http://getgnuwin32.sourceforge.net/)
- * - the templates for the HTML gallery in a subdirectory called template
- * - inkscape (www.inkcape.org) to create png thumbnails
- * - optional: rsync to upload, for windows e.g. cwrsync, http://www.rsync.net/resources/howto/windows_rsync.html
- * in case you want to use this feature you will have to setup cwrsync so that it connects to the remote host
- * w/o asking for a password or host authentication confirmation. Ted Ruegsegger has written a documentation
- * on that on http://www.tux.org/~tbr/rsync/#What1 but I think it's even easier:
- * the home directory on vista is automatically c:\users\<username>.
- * On XP and older your homedir might be somewhere else, e.g. "c:\documents and settings"
- * run rsync once manually from the rsync path, rsyncing anything you like to
- * your destination host to get the .ssh directory and confirm host authentity:
- * Step 1 (confirm host):
- * cd "\program files\cwrsync\bin"
- * rsync -avzP plink.exe <yourusername>@<yourhostname>:/tmp/
- * (confirm host identity and type your password manually)
- * (this should transmit plink.exe to <yourhostname>/tmp/ just as a test)
- * Step 2 (generate and submit keys):
- * (still in "\program files\cwrsync\bin")
- * ssh-keygen -t dsa -N "" -f \users\<username>\.ssh\id_dsa
- * rsync -avzP \users\<username>\.ssh\id_dsa.pub <yourusername>@<yourhostname>:/tmp/id_dsa.pub
- * Step 3 (host to accept the keys):
- * ssh to your host, e.g. via putty, with <yourusername>
- * rm /tmp/plink.exe (as this was just a test)
- * cat /tmp/id_dsa.pub >> ~/.ssh/authorized_keys
- * (keep this window open, I'll call it remote window)
- * Step 4 (test)
- * (back on local window in "\program files\cwrsync\bin")
- * rsync -avzP plink.exe <yourusername>@<yourhostname>:/tmp/
- * (this should now NOT ask for host authentication NOR password)
- * (on remote window)
- * rm /tmp/plink.exe
- * exit
- * (and you can also exit your local window)
- *
- * see also http://www.openclipart.org/wiki/Release_Procedure
- * */
-
-/**
- * This class was just a test for obtaining metadata but it never worked properly
- * and is not used at all at this time
-
-class tagParser {
-
- // XML parser variables
- var $parser;
- var $name;
- var $attr;
- private $lastContent;
- private $numItemsRetrieved;
- private $numItemsToRetrieve=300;
- private $chop=0;
- private $tag;
- private $completeContent="";
- private $emptyTranslations=array();
-
-
- // function with the default parameter value
- // it will automatically add &limit=300&chop=0
- function __construct($tag) {
- $this->tag = $tag;
-
- $translations = get_html_translation_table(HTML_ENTITIES);
- $this->emptyTranslations=array();
- foreach ($translations as $key=>$translation) {
- $this->emptyTranslations[$translation]="?";
- }
-
- }
-
- // parse XML data
- function parse()
- {
- $this->numItemsRetrieved=0;
- $this->parser = xml_parser_create ("UTF-8");
- xml_set_object($this->parser, $this);
- xml_set_element_handler($this->parser, 'startXML', 'endXML');
- xml_set_character_data_handler($this->parser, 'charXML');
-
- xml_parser_set_option($this->parser, XML_OPTION_CASE_FOLDING, false);
-
-
-// die(strtr("dies ist alles & nichts ", $emptyTranslations));
- do {
- $completeURL="http://openclipart.org/media/api/query?f=rss&tags=".$this->tag."&limit=300&offset=".$this->chop;
- // if use type = 'url' now we open the XML with fopen
-
- if (!($fp = @fopen($completeURL, 'rb'))) {
- $this->error("Cannot open {$this->url}");
- }
-
- while (($data = fread($fp, 8192))) {
- $data=strtr($data, $this->emptyTranslations);
- $this->completeContent.=$data;
- if (!xml_parse($this->parser, $data, feof($fp))) {
- $this->error(sprintf('XML error at line %d column %d',
- xml_get_current_line_number($this->parser),
- xml_get_current_column_number($this->parser)),$data);
- }
- }
- fclose($fp);
- $this->chop+=$this->numItemsRetrieved;
- echo "$completeURL\n";
- } while (!$this->isCompleted());
-
- echo "retrieved ".$this->numItemsRetrieved." items for tag ".$this->tag."\n";
- }
-
- function startXML($parser, $name, $attr) {
- $this->lastContent="";
- if ($name=="item") {
- $this->numItemsRetrieved++;
- }
-
- }
-
- function endXML($parser, $name) {
- if ($name=="guid") {
- //$progFile=fopen("prog.txt","a");
- print($this->chop." ".$this->lastContent."\n");
- //fclose ($progFile);
- }
-
- }
-
- function isCompleted() {
- return $this->numItemsRetrieved<$this->numItemsToRetrieve;
- }
-
- function charXML($parser, $data) {
- $this->lastContent.=$data;
- }
-
- function error($msg, $data=null) {
- echo "$msg";
- if ($data!=null) {
- $errFile=fopen("err.txt","w");
- fwrite($errFile, $data);
- fclose ($errFile);
- }
- exit();
- }
-}
-
-//$tags=array("abstract","activity","anatomy","ancient","animal","apple","arcade","architecture","armor","arrow","art","baby","ball","barbering","bear","beer","beverage","bird","birthday","black","blue","boat","book","border","bottle","box","boy","building","button","calligraphic","callout","camera","candle","car","card","cartography","cartoon","castle","cat","character","chicken","child","christmas","circuit","city","clock","clothing","cloud","coat_of_arms","color","colouring_book","comic","computer","container","contour","costume","country","cow","crest","danger","decoration","decorative","design","dessert","diagram","dog","drink","earth","egg","electric","electrical_appliances","electricity","electronics","epa","epa_sunwise","equipment","europe","eye","face","fantasy","farm","feline","female","figure","fire","fish","flag","flower","fly","food","frame","france","fruit","funny","furniture","fws","fws_lineart","game","geography","germany","girl","glass","globe","glossy","god
","greek","green","guitar","guy","hair","halloween","hand","happy","hardware","hat","head","heart","helmet","heraldry","historical","history","holiday","home","horse","house","household","human","icon","iec","illustration","inkscape","insect","instrument","japanese","jigsaw","key","kitchen","land","landscape","leaf","letter","line_art","literature","loc","logo","love","mammal","man","map","maritime","meat","medical","medicine","medieval","metal","military","money","monitor","mouse","music","mythology","nation","nature","night","no_contour","ocean","office","orange","outline","paper","party","pc_for_alla","pen","penguin","people","person","pet","phone","photorealistic","pink","pirate","plane","planet","plant","play","poland","portrait","puzzle","rabbit","reading","red","religion","roadsign","sailing","santa","scene","school","science","screen","sea","season","semaphore","shape","ship","sign","signal","silhouette","skull","sky","smiley","smiling","snow","sound","space","sport"
,"star","storage","sun","sweden","swiss","sword","symbol","tangram","technology","time","tool","tower","toy","traffic","transportation","tree","united_nations_member","uspto","valentine","vegetable","vehicle","war","warning","water","weapon","weather","white","wikimedia_commons","wine","wing","winter","woman","wood","work","world","worldlabel","writing","yellow");
-
-foreach ($tags as $tag) {
-
- $rp=new tagParser($tag);
- $rp->parse();
-
-
-}*/
+ */
class opsysDependendEntity{
protected $opsys; // 1=windows, 0=linux, adjusted in checkOpsys
@@ -515,277 +352,4 @@
}
}
-class releaser extends opsysDependendEntity {
-
- private $maxWidth=64; // maximal thumbnail width
- private $maxHeight=64; // max thumbnail height
- // technically maxWidth and maxHeight form a bounding box in
- // which the thumbnail will always fit (usually with free space around)
-
-
- private $rsyncUser; // upload user name entered by the user
- private $rsyncHost; // upload host name entered by the user
- private $rsyncDir; // upload directory entered by the user
-
- private $numSVGsAvailable; // the total number of svgs
- private $numThumbsGenerated; // the number of SVGs generated in this run. If a run is stopped(killed) and continued afterwards this can differ from the total number of svg files
- private $version; // version nr of this release, e.g. 0.19
- private $doDownload; // boolean if daily_svg_snapshot is to be downloaded (otherwise we just continue a previous run)
- private $doUnzip; // boolean if daily_svg_snapshot is to be unzipped again
- private $doRsync; // boolean if release is to be uploaded
-
- private $files; // in the end contains an array of all files, to be passed to a HTMLPreviewBuilder
- private $HTMLpreview;
- private $logger;
-
- function __construct() {
- if (!empty($_SERVER['SERVER_NAME'])) {
- die("This is a command line script. Please run it from the shell with 'php downloader.php'.");
- }
- $this->numThumbsGenerated=0;
- $this->numSVGsAvailable=0;
- $this->checkOpsys();
- $this->logger=new logger();
-
- }
-
-
- private function generate_thumbnails($dir) {
-
- if (is_dir($dir)) {
- if ($dh = opendir($dir)) {
- while (($file = readdir($dh)) !== false) {
- if (($file!=".")&&($file!="..")) {
- $completeFileLocation=$dir.$this->opsysDirSep.$file;
- if (is_dir($completeFileLocation)) {
- $this->generate_thumbnails($completeFileLocation);
- } else {
- if (strpos($file,".svg")!==false) {
- $this->numSVGsAvailable++;
- echo "File {$this->numSVGsAvailable} Creating thumbnail #{$this->numThumbsGenerated} for: $completeFileLocation \n";
- // my inkscape 0.46 for windows and linux crashes on orangeobject_background-ribbon.svg which destroys the overnight batch run, so lets leave it out
- if (strpos($completeFileLocation,"orangeobject_background-ribbon.svg")===false) {
- $this->HTMLpreview->addImage($completeFileLocation);
- $pngFilename=str_replace(".svg",".png",$completeFileLocation);
- $this->files[]=$completeFileLocation;
- if (!file_exists($pngFilename)) {
- $this->numThumbsGenerated++;
- $this->myExec($this->path_inkscape,'-f "'.$completeFileLocation.'" -e "'.$pngFilename.'" -w '.$this->maxWidth);
- list($width, $height)=getimagesize($pngFilename);
- // the GD library cant determine the aspect ratio of a SVG and I would not know how to do it in pure PHP, so
- // we create a png thumbnail with maxWidth, use the GD library on the thumbnail to find out if it was
- // a vertical image (height>maxHeigth) and if so, overwrite the thumbnail with a version enforcing maxHeigth
- if ($height>$this->maxHeight) {
- $this->myExec($this->path_inkscape,'-f "'.$completeFileLocation.'" -e "'.$pngFilename.'" -h '.$this->maxHeight);
-
- }
-
-/* if we had a png version which was guranteedly bigger than maxsize or minsize, we could create the thumb using gd as follows:
- * // the GD library cant determine the aspect ratio of a SVG and I would not know how to do it in pure PHP, so
- // we create a png thumbnail with maxWidth, use the GD library on the thumbnail to find out if it was
- // a vertical image (height>maxHeigth) and if so, overwrite the thumbnail with a version enforcing maxHeigth
- if ($height>$width) {
- $newHeight=$this->maxHeight;
- $newWidth=$width/$height*$newHeight;
- } else {
- $newWidth=$this->maxWidth;
- $newHeight=$height/$width*$newWidth;
- }
- $big= ImageCreateFromPNG($pngFilename);
- $thumb= imagecreatetruecolor($newWidth,$newHeight);
- // true color images seem to have by default bgcolor black: change this to transparent
- imagesavealpha($thumb, true);
- $trans_colour = imagecolorallocatealpha($thumb, 0, 0, 0, 127);
- imagefill($thumb, 0, 0, $trans_colour);
-
- imagecopyresampled($thumb,$big,0,0,0,0,$newWidth,$newHeight,$width,$height);
- imagepng($thumb,$pngThumbFilename);*/
-
- }
- }
-
- }
- }
-
- }
- }
- closedir($dh);
- }
- }
-
- }
- /**
- * This function will run a command and show the output as soon as it receives anything
- * from the program invoked.
- * It also shows error out (also used for status info), as it redirects stderr to stdout (2>&1)
- * In windows, it takes care of inserting the quotes to handle directories with spaces
- *
- * */
- private function myExec($cmd, $args, $message=null) {
-
- if (strpos($cmd," ")!==false) {
- $cmd=$this->opsysQuotes.$cmd.$this->opsysQuotes;
- }
- $args=$args." 2>&1"; //info on inkscape command line on windows http://kaioa.com/node/42, http://kaioa.com/node/63
- $msgToOutput="";
- if ($message!=null) {
- $msgToOutput="($message)";
- }
- $this->logger->shout("\nExecuting: $cmd $args $msgToOutput\n");
-
- $fp = popen("{$this->opsysQuotes}$cmd $args{$this->opsysQuotes}", "r"); //the args can contain paths, so they have to be quoted,
- // but the whole command has to be quoted as well in case both the cmd and the args contain directories with spaces.
- while(!feof($fp))
- {
- // send what has been read from the program to the console
- $this->logger->shout(fread($fp, 1024));
- // flush, in case any output should be cached somewhere
- flush();
- }
- fclose($fp);
-
- }
-
- private function prompt($prompt) {
- echo $prompt;
- $fp = fopen('php://stdin', 'r');
- return trim(fgets(STDIN));
- }
-
- private function checkProgramme($name, $defaultPath) {
- if (!file_exists($defaultPath)) {
- return $this->prompt("Where is your $name (not found in $defaultPath)?");
- } else {
- return $defaultPath;
- }
- }
-
- private function checkPrerequisites() {
- $this->path_wget=$this->checkProgramme("wget", $this->path_wget);
- $this->path_tar=$this->checkProgramme("tar", $this->path_tar);
- $this->path_bunzip=$this->checkProgramme("bunzip2", $this->path_bunzip);
- $this->path_gzip=$this->checkProgramme("gzip", $this->path_gzip);
- $this->path_bzip=$this->checkProgramme("bzip", $this->path_bzip);
- $this->path_zip=$this->checkProgramme("zip", $this->path_zip);
- $this->path_inkscape=$this->checkProgramme("inkscape", $this->path_inkscape);
- if ($this->doRsync) {
- $this->path_rsync=$this->checkProgramme("rsync", $this->path_rsync);
- }
-
-
- }
-
-
- public function run() {
- $this->version=$this->prompt("Release version (e.g. 0.19):");
- $this->HTMLpreview=new HTMLPreviewBuilder($this->logger, $this->version);
- $this->doDownload=true;
- $this->doUnzip=true;
- if (file_exists("daily_SVG_snapshot.tar.bz2")) {
- $this->doDownload=false;
- $shallDownload=$this->prompt("Create n)ew release, u)nzip and continue already downloaded daily_SVG_snapshot.tar.bz2 or c)ontinue previous run after unzip:");
-
- if (($shallDownload=="n")||($shallDownload=="N")) {
- $this->doDownload=true;
- $this->doUnzip=true;
- }
- if (($shallDownload=="u")||($shallDownload=="U")) {
- $this->doDownload=false;
- $this->doUnzip=true;
- }
- if (($shallDownload=="c")||($shallDownload=="C")) {
- $this->doDownload=false;
- $this->doUnzip=false;
- }
- }
- $rsyncResponse=$this->prompt("Upload release after creation? This will require a non-interactive rsync connection to your host (y/n)?:");
- if (($rsyncResponse=="y")||($rsyncResponse=="Y")) {
- $this->rsyncUser=$this->prompt("Upload user name:");
- $this->rsyncHost=$this->prompt("Upload host name:");
- $this->rsyncDir=$this->prompt("Upload directory (please include trailing slash, e.g. /var/www/):");
- $this->doRsync=true;
- }
- $this->checkPrerequisites();
-
- if ($this->doDownload) {
- $this->logger->shoutNewStatus("Downloading");
- if (file_exists("daily_SVG_snapshot.tar.bz2")) {
- unlink("daily_SVG_snapshot.tar.bz2");
- }
- $this->myExec($this->path_wget,"http://download.openclipart.org/downloads/daily_SVG_snapshot.tar.bz2");
- }
-
- $subdirname="openclipart-{$this->version}";
- if (!file_exists($subdirname)) {
- mkdir($subdirname);
- }
-
- if ($this->doUnzip) {
- $this->logger->shoutNewStatus("Unzipping");
- $this->myExec($this->path_bunzip,"-v daily_SVG_snapshot.tar.bz2", "This will take 5 minutes");
- }
- chdir($subdirname);
- if ($this->doUnzip) {
- $this->logger->shoutNewStatus("Untaring");
- $this->myExec($this->path_tar,"xvf ..{$this->opsysDirSep}daily_SVG_snapshot.tar ");
- }
-
- $this->logger->shoutNewStatus("Thumbnailing");
- $this->generate_thumbnails(getcwd());
- $this->logger->shout("Generated {$this->numThumbsGenerated} new thumbnails for {$this->numSVGsAvailable} files");
- chdir("..");
- $this->HTMLpreview->writeHTML(getcwd().$this->opsysDirSep."openclipart".$this->opsysDirSep);
- $this->logger->shoutNewStatus("Taring");
- $tarFile="openclipart-{$this->version}.tar";
- if (file_exists($tarFile)) {
- unlink($tarFile);
- }
- $this->myExec($this->path_tar,"cvf $tarFile $subdirname");
- $this->logger->shoutNewStatus("BZipping");
- $bzFile="openclipart-{$this->version}.tar.bz2";
- if (file_exists($bzFile)) {
- unlink($bzFile);
- }
- $this->myExec($this->path_bzip,"-k $tarFile");
- $this->logger->shoutNewStatus("GZipping");
- $tgzFile="openclipart-{$this->version}.tar.gz";
- if (file_exists($tgzFile)) {
- unlink($tgzFile);
- }
- $this->myExec($this->path_gzip,$tarFile);
-
- $this->logger->shoutNewStatus("Zipping");
- $zipFile="openclipart-{$this->version}.zip";
- if (file_exists($zipFile)) {
- unlink($zipFile);
- }
- $this->myExec($this->path_zip,"-r $zipFile $subdirname");
- if ($this->doRsync) {
- $this->logger->shoutNewStatus("Uploading");
- $sourceDir=getcwd();
- $rsyncDir=substr($this->path_rsync,0,strrpos($this->path_rsync,$this->opsysDirSep));
- chdir($rsyncDir);
- $RsyncSourceDir=$sourceDir;
- if ($this->opsys==1) {
- // windows cwrsync requires ssh.exe to be in the local path which is only the case if
- // one changes dir to the rsync programme
- $RsyncSourceDir=str_replace("\\","/",$sourceDir);
- // additionally, d:\\xyz would be /cygdrive/d in cwrsync
- if ($RsyncSourceDir{1}==':') {
- $RsyncSourceDir="/cygdrive/".$RsyncSourceDir{0}.substr($RsyncSourceDir,2);
- }
- }
-
- $this->myExec($this->path_rsync,"-avzP {$RsyncSourceDir}/$bzFile {$this->rsyncUser}@{$this->rsyncHost}:{$this->rsyncDir}");
- $this->myExec($this->path_rsync,"-avzP {$RsyncSourceDir}/$tgzFile {$this->rsyncUser}@{$this->rsyncHost}:{$this->rsyncDir}");
- $this->myExec($this->path_rsync,"-avzP {$RsyncSourceDir}/$zipFile {$this->rsyncUser}@{$this->rsyncHost}:{$this->rsyncDir}");
- chdir($sourceDir);
- }
- }
-
-
-}
-
-$rel=new releaser();
-$rel->run();
?>
Added: makerelease/makerelease.php
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ makerelease/makerelease.php Sun Jun 28 09:10:42 2009 (r38)
@@ -0,0 +1,183 @@
+<?php
+
+/**
+ * @author Jochen Stärk <jstaerk at usegroup.de>
+ * @version 1.1
+ * @date 2009-03-19
+ *
+ * This php shell script creates a openclipart file release.
+ *
+ * It uses wget to download the daily SVG tarball from openclipart.org,
+ * fires inkscape to rasterize all images and create thumbnails,
+ * creates a HTML-Gallery for offline viewing, creates .zip, .tar.gz and .tar.bz2
+ * bundles and uploads them with rsync.
+ * A log with all messages is stored in lastrun.log
+ *
+ * It has been developed for windows and linux
+ *
+ * It requires the following tools to be installed:
+ * - php (obviously, to run this script, fire <path to your php>\php downloader.php). For windows you can also use xampp, http://www.apachefriends.org/en/xampp-windows.html
+ * - the GD-extension of PHP
+ * - a high memory_limit in the php.ini file. 32mb didn't suffice for big PNGs but I never had any issue with 320...
+ * - wget, tar, bzip2 (for windows: http://getgnuwin32.sourceforge.net/)
+ * - the templates for the HTML gallery in a subdirectory called template
+ * - inkscape (www.inkcape.org) to create png thumbnails
+ * - optional: rsync to upload, for windows e.g. cwrsync, http://www.rsync.net/resources/howto/windows_rsync.html
+ * in case you want to use this feature you will have to setup cwrsync so that it connects to the remote host
+ * w/o asking for a password or host authentication confirmation. Ted Ruegsegger has written a documentation
+ * on that on http://www.tux.org/~tbr/rsync/#What1 but I think it's even easier:
+ * the home directory on vista is automatically c:\users\<username>.
+ * On XP and older your homedir might be somewhere else, e.g. "c:\documents and settings"
+ * run rsync once manually from the rsync path, rsyncing anything you like to
+ * your destination host to get the .ssh directory and confirm host authentity:
+ * Step 1 (confirm host):
+ * cd "\program files\cwrsync\bin"
+ * rsync -avzP plink.exe <yourusername>@<yourhostname>:/tmp/
+ * (confirm host identity and type your password manually)
+ * (this should transmit plink.exe to <yourhostname>/tmp/ just as a test)
+ * Step 2 (generate and submit keys):
+ * (still in "\program files\cwrsync\bin")
+ * ssh-keygen -t dsa -N "" -f \users\<username>\.ssh\id_dsa
+ * rsync -avzP \users\<username>\.ssh\id_dsa.pub <yourusername>@<yourhostname>:/tmp/id_dsa.pub
+ * Step 3 (host to accept the keys):
+ * ssh to your host, e.g. via putty, with <yourusername>
+ * rm /tmp/plink.exe (as this was just a test)
+ * cat /tmp/id_dsa.pub >> ~/.ssh/authorized_keys
+ * (keep this window open, I'll call it remote window)
+ * Step 4 (test)
+ * (back on local window in "\program files\cwrsync\bin")
+ * rsync -avzP plink.exe <yourusername>@<yourhostname>:/tmp/
+ * (this should now NOT ask for host authentication NOR password)
+ * (on remote window)
+ * rm /tmp/plink.exe
+ * exit
+ * (and you can also exit your local window)
+ *
+ * see also http://www.openclipart.org/wiki/Release_Procedure
+ * */
+
+/**
+ * This class was just a test for obtaining metadata but it never worked properly
+ * and is not used at all at this time
+
+class tagParser {
+
+ // XML parser variables
+ var $parser;
+ var $name;
+ var $attr;
+ private $lastContent;
+ private $numItemsRetrieved;
+ private $numItemsToRetrieve=300;
+ private $chop=0;
+ private $tag;
+ private $completeContent="";
+ private $emptyTranslations=array();
+
+
+ // function with the default parameter value
+ // it will automatically add &limit=300&chop=0
+ function __construct($tag) {
+ $this->tag = $tag;
+
+ $translations = get_html_translation_table(HTML_ENTITIES);
+ $this->emptyTranslations=array();
+ foreach ($translations as $key=>$translation) {
+ $this->emptyTranslations[$translation]="?";
+ }
+
+ }
+
+ // parse XML data
+ function parse()
+ {
+ $this->numItemsRetrieved=0;
+ $this->parser = xml_parser_create ("UTF-8");
+ xml_set_object($this->parser, $this);
+ xml_set_element_handler($this->parser, 'startXML', 'endXML');
+ xml_set_character_data_handler($this->parser, 'charXML');
+
+ xml_parser_set_option($this->parser, XML_OPTION_CASE_FOLDING, false);
+
+
+// die(strtr("dies ist alles & nichts ", $emptyTranslations));
+ do {
+ $completeURL="http://openclipart.org/media/api/query?f=rss&tags=".$this->tag."&limit=300&offset=".$this->chop;
+ // if use type = 'url' now we open the XML with fopen
+
+ if (!($fp = @fopen($completeURL, 'rb'))) {
+ $this->error("Cannot open {$this->url}");
+ }
+
+ while (($data = fread($fp, 8192))) {
+ $data=strtr($data, $this->emptyTranslations);
+ $this->completeContent.=$data;
+ if (!xml_parse($this->parser, $data, feof($fp))) {
+ $this->error(sprintf('XML error at line %d column %d',
+ xml_get_current_line_number($this->parser),
+ xml_get_current_column_number($this->parser)),$data);
+ }
+ }
+ fclose($fp);
+ $this->chop+=$this->numItemsRetrieved;
+ echo "$completeURL\n";
+ } while (!$this->isCompleted());
+
+ echo "retrieved ".$this->numItemsRetrieved." items for tag ".$this->tag."\n";
+ }
+
+ function startXML($parser, $name, $attr) {
+ $this->lastContent="";
+ if ($name=="item") {
+ $this->numItemsRetrieved++;
+ }
+
+ }
+
+ function endXML($parser, $name) {
+ if ($name=="guid") {
+ //$progFile=fopen("prog.txt","a");
+ print($this->chop." ".$this->lastContent."\n");
+ //fclose ($progFile);
+ }
+
+ }
+
+ function isCompleted() {
+ return $this->numItemsRetrieved<$this->numItemsToRetrieve;
+ }
+
+ function charXML($parser, $data) {
+ $this->lastContent.=$data;
+ }
+
+ function error($msg, $data=null) {
+ echo "$msg";
+ if ($data!=null) {
+ $errFile=fopen("err.txt","w");
+ fwrite($errFile, $data);
+ fclose ($errFile);
+ }
+ exit();
+ }
+}
+
+//$tags=array("abstract","activity","anatomy","ancient","animal","apple","arcade","architecture","armor","arrow","art","baby","ball","barbering","bear","beer","beverage","bird","birthday","black","blue","boat","book","border","bottle","box","boy","building","button","calligraphic","callout","camera","candle","car","card","cartography","cartoon","castle","cat","character","chicken","child","christmas","circuit","city","clock","clothing","cloud","coat_of_arms","color","colouring_book","comic","computer","container","contour","costume","country","cow","crest","danger","decoration","decorative","design","dessert","diagram","dog","drink","earth","egg","electric","electrical_appliances","electricity","electronics","epa","epa_sunwise","equipment","europe","eye","face","fantasy","farm","feline","female","figure","fire","fish","flag","flower","fly","food","frame","france","fruit","funny","furniture","fws","fws_lineart","game","geography","germany","girl","glass","globe","glossy","god
","greek","green","guitar","guy","hair","halloween","hand","happy","hardware","hat","head","heart","helmet","heraldry","historical","history","holiday","home","horse","house","household","human","icon","iec","illustration","inkscape","insect","instrument","japanese","jigsaw","key","kitchen","land","landscape","leaf","letter","line_art","literature","loc","logo","love","mammal","man","map","maritime","meat","medical","medicine","medieval","metal","military","money","monitor","mouse","music","mythology","nation","nature","night","no_contour","ocean","office","orange","outline","paper","party","pc_for_alla","pen","penguin","people","person","pet","phone","photorealistic","pink","pirate","plane","planet","plant","play","poland","portrait","puzzle","rabbit","reading","red","religion","roadsign","sailing","santa","scene","school","science","screen","sea","season","semaphore","shape","ship","sign","signal","silhouette","skull","sky","smiley","smiling","snow","sound","space","sport"
,"star","storage","sun","sweden","swiss","sword","symbol","tangram","technology","time","tool","tower","toy","traffic","transportation","tree","united_nations_member","uspto","valentine","vegetable","vehicle","war","warning","water","weapon","weather","white","wikimedia_commons","wine","wing","winter","woman","wood","work","world","worldlabel","writing","yellow");
+
+foreach ($tags as $tag) {
+
+ $rp=new tagParser($tag);
+ $rp->parse();
+
+
+}*/
+
+include_once 'downloader.php';
+include_once 'releaser.php';
+
+
+$rel = new releaser();
+$rel->run();
+
+
+exit;
Added: makerelease/releaser.php
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ makerelease/releaser.php Sun Jun 28 09:10:42 2009 (r38)
@@ -0,0 +1,287 @@
+<?php
+
+/**
+ * @author Jochen Stärk <jstaerk at usegroup.de>
+ * @version 1.1
+ * @date 2009-03-19
+ *
+ * This php shell script downloads the latest openclipart package
+ *
+ */
+
+/**
+ * @class Releaser does releasing
+ */
+
+class releaser extends opsysDependendEntity {
+
+ private $maxWidth=64; // maximal thumbnail width
+ private $maxHeight=64; // max thumbnail height
+ // technically maxWidth and maxHeight form a bounding box in
+ // which the thumbnail will always fit (usually with free space around)
+
+
+ private $rsyncUser; // upload user name entered by the user
+ private $rsyncHost; // upload host name entered by the user
+ private $rsyncDir; // upload directory entered by the user
+
+ private $numSVGsAvailable; // the total number of svgs
+ private $numThumbsGenerated; // the number of SVGs generated in this run. If a run is stopped(killed) and continued afterwards this can differ from the total number of svg files
+ private $version; // version nr of this release, e.g. 0.19
+ private $doDownload; // boolean if daily_svg_snapshot is to be downloaded (otherwise we just continue a previous run)
+ private $doUnzip; // boolean if daily_svg_snapshot is to be unzipped again
+ private $doRsync; // boolean if release is to be uploaded
+
+ private $files; // in the end contains an array of all files, to be passed to a HTMLPreviewBuilder
+ private $HTMLpreview;
+ private $logger;
+
+ function __construct() {
+ if (!empty($_SERVER['SERVER_NAME'])) {
+ die("This is a command line script. Please run it from the shell with 'php downloader.php'.");
+ }
+ $this->numThumbsGenerated=0;
+ $this->numSVGsAvailable=0;
+ $this->checkOpsys();
+ $this->logger=new logger();
+
+ }
+
+
+ private function generate_thumbnails($dir) {
+
+ if (is_dir($dir)) {
+ if ($dh = opendir($dir)) {
+ while (($file = readdir($dh)) !== false) {
+ if (($file!=".")&&($file!="..")) {
+ $completeFileLocation=$dir.$this->opsysDirSep.$file;
+ if (is_dir($completeFileLocation)) {
+ $this->generate_thumbnails($completeFileLocation);
+ } else {
+ if (strpos($file,".svg")!==false) {
+ $this->numSVGsAvailable++;
+ echo "File {$this->numSVGsAvailable} Creating thumbnail #{$this->numThumbsGenerated} for: $completeFileLocation \n";
+ // my inkscape 0.46 for windows and linux crashes on orangeobject_background-ribbon.svg which destroys the overnight batch run, so lets leave it out
+ if (strpos($completeFileLocation,"orangeobject_background-ribbon.svg")===false) {
+ $this->HTMLpreview->addImage($completeFileLocation);
+ $pngFilename=str_replace(".svg",".png",$completeFileLocation);
+ $this->files[]=$completeFileLocation;
+ if (!file_exists($pngFilename)) {
+ $this->numThumbsGenerated++;
+ $this->myExec($this->path_inkscape,'-f "'.$completeFileLocation.'" -e "'.$pngFilename.'" -w '.$this->maxWidth);
+ list($width, $height)=getimagesize($pngFilename);
+ // the GD library cant determine the aspect ratio of a SVG and I would not know how to do it in pure PHP, so
+ // we create a png thumbnail with maxWidth, use the GD library on the thumbnail to find out if it was
+ // a vertical image (height>maxHeigth) and if so, overwrite the thumbnail with a version enforcing maxHeigth
+ if ($height>$this->maxHeight) {
+ $this->myExec($this->path_inkscape,'-f "'.$completeFileLocation.'" -e "'.$pngFilename.'" -h '.$this->maxHeight);
+
+ }
+
+/* if we had a png version which was guranteedly bigger than maxsize or minsize, we could create the thumb using gd as follows:
+ * // the GD library cant determine the aspect ratio of a SVG and I would not know how to do it in pure PHP, so
+ // we create a png thumbnail with maxWidth, use the GD library on the thumbnail to find out if it was
+ // a vertical image (height>maxHeigth) and if so, overwrite the thumbnail with a version enforcing maxHeigth
+ if ($height>$width) {
+ $newHeight=$this->maxHeight;
+ $newWidth=$width/$height*$newHeight;
+ } else {
+ $newWidth=$this->maxWidth;
+ $newHeight=$height/$width*$newWidth;
+ }
+ $big= ImageCreateFromPNG($pngFilename);
+ $thumb= imagecreatetruecolor($newWidth,$newHeight);
+ // true color images seem to have by default bgcolor black: change this to transparent
+ imagesavealpha($thumb, true);
+ $trans_colour = imagecolorallocatealpha($thumb, 0, 0, 0, 127);
+ imagefill($thumb, 0, 0, $trans_colour);
+
+ imagecopyresampled($thumb,$big,0,0,0,0,$newWidth,$newHeight,$width,$height);
+ imagepng($thumb,$pngThumbFilename);*/
+
+ }
+ }
+
+ }
+ }
+
+ }
+ }
+ closedir($dh);
+ }
+ }
+
+ }
+ /**
+ * This function will run a command and show the output as soon as it receives anything
+ * from the program invoked.
+ * It also shows error out (also used for status info), as it redirects stderr to stdout (2>&1)
+ * In windows, it takes care of inserting the quotes to handle directories with spaces
+ *
+ * */
+ private function myExec($cmd, $args, $message=null) {
+
+ if (strpos($cmd," ")!==false) {
+ $cmd=$this->opsysQuotes.$cmd.$this->opsysQuotes;
+ }
+ $args=$args." 2>&1"; //info on inkscape command line on windows http://kaioa.com/node/42, http://kaioa.com/node/63
+ $msgToOutput="";
+ if ($message!=null) {
+ $msgToOutput="($message)";
+ }
+ $this->logger->shout("\nExecuting: $cmd $args $msgToOutput\n");
+
+ $fp = popen("{$this->opsysQuotes}$cmd $args{$this->opsysQuotes}", "r"); //the args can contain paths, so they have to be quoted,
+ // but the whole command has to be quoted as well in case both the cmd and the args contain directories with spaces.
+ while(!feof($fp))
+ {
+ // send what has been read from the program to the console
+ $this->logger->shout(fread($fp, 1024));
+ // flush, in case any output should be cached somewhere
+ flush();
+ }
+ fclose($fp);
+
+ }
+
+ private function prompt($prompt) {
+ echo $prompt;
+ $fp = fopen('php://stdin', 'r');
+ return trim(fgets(STDIN));
+ }
+
+ private function checkProgramme($name, $defaultPath) {
+ if (!file_exists($defaultPath)) {
+ return $this->prompt("Where is your $name (not found in $defaultPath)?");
+ } else {
+ return $defaultPath;
+ }
+ }
+
+ private function checkPrerequisites() {
+ $this->path_wget=$this->checkProgramme("wget", $this->path_wget);
+ $this->path_tar=$this->checkProgramme("tar", $this->path_tar);
+ $this->path_bunzip=$this->checkProgramme("bunzip2", $this->path_bunzip);
+ $this->path_gzip=$this->checkProgramme("gzip", $this->path_gzip);
+ $this->path_bzip=$this->checkProgramme("bzip", $this->path_bzip);
+ $this->path_zip=$this->checkProgramme("zip", $this->path_zip);
+ $this->path_inkscape=$this->checkProgramme("inkscape", $this->path_inkscape);
+ if ($this->doRsync) {
+ $this->path_rsync=$this->checkProgramme("rsync", $this->path_rsync);
+ }
+
+
+ }
+
+
+ public function run() {
+ $this->version=$this->prompt("Release version (e.g. 0.19):");
+ $this->HTMLpreview=new HTMLPreviewBuilder($this->logger, $this->version);
+ $this->doDownload=true;
+ $this->doUnzip=true;
+ if (file_exists("daily_SVG_snapshot.tar.bz2")) {
+ $this->doDownload=false;
+ $shallDownload=$this->prompt("Create n)ew release, u)nzip and continue already downloaded daily_SVG_snapshot.tar.bz2 or c)ontinue previous run after unzip:");
+
+ if (($shallDownload=="n")||($shallDownload=="N")) {
+ $this->doDownload=true;
+ $this->doUnzip=true;
+ }
+ if (($shallDownload=="u")||($shallDownload=="U")) {
+ $this->doDownload=false;
+ $this->doUnzip=true;
+ }
+ if (($shallDownload=="c")||($shallDownload=="C")) {
+ $this->doDownload=false;
+ $this->doUnzip=false;
+ }
+ }
+ $rsyncResponse=$this->prompt("Upload release after creation? This will require a non-interactive rsync connection to your host (y/n)?:");
+ if (($rsyncResponse=="y")||($rsyncResponse=="Y")) {
+ $this->rsyncUser=$this->prompt("Upload user name:");
+ $this->rsyncHost=$this->prompt("Upload host name:");
+ $this->rsyncDir=$this->prompt("Upload directory (please include trailing slash, e.g. /var/www/):");
+ $this->doRsync=true;
+ }
+ $this->checkPrerequisites();
+
+ if ($this->doDownload) {
+ $this->logger->shoutNewStatus("Downloading");
+ if (file_exists("daily_SVG_snapshot.tar.bz2")) {
+ unlink("daily_SVG_snapshot.tar.bz2");
+ }
+ $this->myExec($this->path_wget,"http://download.openclipart.org/downloads/daily_SVG_snapshot.tar.bz2");
+ }
+
+ $subdirname="openclipart-{$this->version}";
+ if (!file_exists($subdirname)) {
+ mkdir($subdirname);
+ }
+
+ if ($this->doUnzip) {
+ $this->logger->shoutNewStatus("Unzipping");
+ $this->myExec($this->path_bunzip,"-v daily_SVG_snapshot.tar.bz2", "This will take 5 minutes");
+ }
+ chdir($subdirname);
+ if ($this->doUnzip) {
+ $this->logger->shoutNewStatus("Untaring");
+ $this->myExec($this->path_tar,"xvf ..{$this->opsysDirSep}daily_SVG_snapshot.tar ");
+ }
+
+ $this->logger->shoutNewStatus("Thumbnailing");
+ $this->generate_thumbnails(getcwd());
+ $this->logger->shout("Generated {$this->numThumbsGenerated} new thumbnails for {$this->numSVGsAvailable} files");
+ chdir("..");
+ $this->HTMLpreview->writeHTML(getcwd().$this->opsysDirSep."openclipart".$this->opsysDirSep);
+ $this->logger->shoutNewStatus("Taring");
+ $tarFile="openclipart-{$this->version}.tar";
+ if (file_exists($tarFile)) {
+ unlink($tarFile);
+ }
+ $this->myExec($this->path_tar,"cvf $tarFile $subdirname");
+ $this->logger->shoutNewStatus("BZipping");
+ $bzFile="openclipart-{$this->version}.tar.bz2";
+ if (file_exists($bzFile)) {
+ unlink($bzFile);
+ }
+ $this->myExec($this->path_bzip,"-k $tarFile");
+ $this->logger->shoutNewStatus("GZipping");
+ $tgzFile="openclipart-{$this->version}.tar.gz";
+ if (file_exists($tgzFile)) {
+ unlink($tgzFile);
+ }
+ $this->myExec($this->path_gzip,$tarFile);
+
+ $this->logger->shoutNewStatus("Zipping");
+ $zipFile="openclipart-{$this->version}.zip";
+ if (file_exists($zipFile)) {
+ unlink($zipFile);
+ }
+ $this->myExec($this->path_zip,"-r $zipFile $subdirname");
+ if ($this->doRsync) {
+ $this->logger->shoutNewStatus("Uploading");
+ $sourceDir=getcwd();
+ $rsyncDir=substr($this->path_rsync,0,strrpos($this->path_rsync,$this->opsysDirSep));
+ chdir($rsyncDir);
+ $RsyncSourceDir=$sourceDir;
+ if ($this->opsys==1) {
+ // windows cwrsync requires ssh.exe to be in the local path which is only the case if
+ // one changes dir to the rsync programme
+ $RsyncSourceDir=str_replace("\\","/",$sourceDir);
+ // additionally, d:\\xyz would be /cygdrive/d in cwrsync
+ if ($RsyncSourceDir{1}==':') {
+ $RsyncSourceDir="/cygdrive/".$RsyncSourceDir{0}.substr($RsyncSourceDir,2);
+ }
+ }
+
+ $this->myExec($this->path_rsync,"-avzP {$RsyncSourceDir}/$bzFile {$this->rsyncUser}@{$this->rsyncHost}:{$this->rsyncDir}");
+ $this->myExec($this->path_rsync,"-avzP {$RsyncSourceDir}/$tgzFile {$this->rsyncUser}@{$this->rsyncHost}:{$this->rsyncDir}");
+ $this->myExec($this->path_rsync,"-avzP {$RsyncSourceDir}/$zipFile {$this->rsyncUser}@{$this->rsyncHost}:{$this->rsyncDir}");
+ chdir($sourceDir);
+ }
+ }
+
+
+}
+
+?>
More information about the clipart
mailing list