]> git.ozlabs.org Git - ccan/commitdiff
merge
authorRusty Russell <rusty@rustcorp.com.au>
Thu, 14 Aug 2008 05:15:17 +0000 (15:15 +1000)
committerRusty Russell <rusty@rustcorp.com.au>
Thu, 14 Aug 2008 05:15:17 +0000 (15:15 +1000)
ccan/string/test/run-grab.c [new file with mode: 0644]
ccan/string/test/run.c
tools/Makefile
tools/create_dep_tar [new file with mode: 0755]
tools/create_dep_tar.c
web/configuration
web/db/ccan.db
web/dispmoduleinfo.php
web/tarball/.tar [new file with mode: 0644]
web/uploader.php

diff --git a/ccan/string/test/run-grab.c b/ccan/string/test/run-grab.c
new file mode 100644 (file)
index 0000000..cfd8b9b
--- /dev/null
@@ -0,0 +1,25 @@
+/* This is test for grab_file() function */
+
+/*
+ * Example:
+ * 
+ * void *grab_file(const void *ctx, const char *filename)
+ *     {
+ *     int fd; 
+ *     char *buffer;
+ * 
+ *     if (streq(filename, "-"))
+ *             fd = dup(STDIN_FILENO);
+ *     else
+ *             fd = open(filename, O_RDONLY, 0); 
+ *
+ *     if (fd < 0)
+ *             return NULL; 
+ *
+ *     buffer = grab_fd(ctx, fd);
+ *     close_noerr(fd);
+ *     return buffer;
+ *     }
+ */
+
+/* End of grab_file() test */
index 02403d24511300a68f05d182d68fa98f66a6503e..f68e7ec56c5c886293be9b5f8e4c086e6076ebfb 100644 (file)
@@ -27,6 +27,8 @@ int main(int argc, char *argv[])
        char **split, *str;
        void *ctx;
        char *strings[NUM_SUBSTRINGS * NUM_SUBSTRINGS];
+       int length;
+       struct stat st;
 
        n = 0;
        for (i = 0; i < NUM_SUBSTRINGS; i++) {
@@ -115,7 +117,16 @@ int main(int argc, char *argv[])
        ok1(talloc_parent(str) == ctx);
        talloc_free(ctx);
 
-
-       
+       str = grab_file(NULL, "ccan/string/test/run-grab.c");
+       split = strsplit(NULL, str, "\n", NULL);
+       length = strlen(split[0]);
+       ok1(streq(split[0], "/* This is test for grab_file() function */"));
+       for(i = 1; split[i]; i++)       
+               length += strlen(split[i]);
+       ok1(streq(split[i-1], "/* End of grab_file() test */"));
+       if (stat("ccan/string/test/run-grab.c", &st) != 0) 
+               err(1, "Could not stat self");
+       ok1(st.st_size == length);
+               
        return exit_status();
 }                              
index 141eb3267b2772dd98444804dedd387fb9fb8ff4..a03cc9a4c113e9abaaa40e72c3f96998e877ab01 100644 (file)
@@ -6,7 +6,8 @@ tools/doc_extract: tools/doc_extract.o ccan/string/string.o ccan/noerr/noerr.o c
 
 tools/namespacize: tools/namespacize.o tools/depends.o ccan/string/string.o ccan/noerr/noerr.o ccan/talloc/talloc.o
 
-tools/create_dep_tar: tools/create_dep_tar.o tools/depends.o ccan/string/string.o ccan/noerr/noerr.o ccan/talloc/talloc.o
+tools/create_dep_tar: tools/create_dep_tar.o tools/depends.o ccan/string/string.o ccan/noerr/noerr.o ccan/talloc/talloc.o tools/_infotojson/sqlite3_database.o tools/_infotojson/utils.o
+       $(CC) $(LDFLAGS) -o $@ $^ -lsqlite3
 
 tools/run_tests.o tools/namespacize.o tools/depends.o: tools/tools.h
 
diff --git a/tools/create_dep_tar b/tools/create_dep_tar
new file mode 100755 (executable)
index 0000000..7920b0b
Binary files /dev/null and b/tools/create_dep_tar differ
index 8247e57ef11d8642706985b7582344a9dd694998..09c331c6f7a09be8f3100bb9a177eb1aec5d3035 100644 (file)
@@ -3,23 +3,60 @@
 #include <stdlib.h>
 #include <stdio.h>
 #include <string.h>
+#include <sqlite3.h>
 #include "ccan/string/string.h"
 #include "ccan/talloc/talloc.h"
+#include "tools/_infotojson/database.h"
 
 #define TAR_CMD "tar cvvf "
 
-static void create_tar(char **deps, const char *dir)
+/* get dependents of the module from db */
+static char**
+get_dependents(const char *dir, const char *db)
 {
-       FILE *p;
-       char *cmd_args, *cmd, *module, *buffer;
+       char            *query, *module, **dependents;
+       sqlite3         *handle;
+       int             i;
+       struct db_query *q;
+
+       module = strrchr(dir, '/');
+       module++;
+
+       /* getting dependents from db */
+       handle = db_open(db);
+       query = talloc_asprintf(NULL, "select module from search where depends LIKE \"%%%s%%\";", module);
+       q = db_query(handle, query);
+       db_close(handle);
+
+       if (q->num_rows == 0)
+               return 0;
+       else {  
+               /* getting query results and returning */
+               dependents = talloc_array(NULL, char *, q->num_rows + 1);
+               for (i = 0; i < q->num_rows; i++)
+                       dependents[i] = talloc_asprintf(dependents, "ccan/%s", q->rows[i][0]);
+               dependents[q->num_rows] = NULL;
+               return dependents;
+       }
+}
+
+/* create tar ball of dependencies */
+static void
+create_tar(char **deps, const char *dir, const char *targetdir)
+{
+       FILE    *p;
+       char    *cmd_args, *cmd, *module, *buffer;
 
        /* getting module name*/
        module = strrchr(dir, '/');
        module++;
        
-       cmd_args = strjoin(NULL, deps, " ");    
-       cmd = talloc_asprintf(NULL, TAR_CMD "%s/%s_dep.tar %s", dir, module, cmd_args);
-               
+       if (deps != NULL) {
+               cmd_args = strjoin(NULL, deps, " ");    
+               cmd = talloc_asprintf(NULL, TAR_CMD "%s/%s_dependencies.tar %s %s", targetdir, module, cmd_args, dir);
+       } else 
+               cmd = talloc_asprintf(NULL, TAR_CMD "%s/%s.tar %s", targetdir, module, dir);
+                       
        p = popen(cmd, "r");
        if (!p)
                err(1, "Executing '%s'", cmd);
@@ -32,14 +69,34 @@ static void create_tar(char **deps, const char *dir)
 
 int main(int argc, char *argv[])
 {
-       char **deps;
+       char    **deps, **dependents;
+       int     i;
 
-       if (argc != 2)
-               errx(1, "Usage: create_dep_tar <dir>\n"
+       if (argc != 4)
+               errx(1, "Usage: create_dep_tar <dir> <targetdir> <db>\n"
                        "Create tar of all the ccan dependencies");
 
+       /* creating tar of the module */
+       create_tar(NULL, argv[1], argv[2]);
+       printf("creating tar ball of \"%s\"\n", argv[1]);       
+
+       /* creating tar of the module dependencies */
        deps = get_deps(NULL, argv[1]);
-       if(deps != NULL)
-               create_tar(deps, argv[1]);
+       if (deps != NULL)
+               create_tar(deps, argv[1], argv[2]);
+       talloc_free(deps);
+
+       /* creating/updating tar of the module dependents */
+       dependents = get_dependents(argv[1], argv[3]);
+       if (dependents != NULL)
+               for (i = 0; dependents[i]; i++) {       
+                       printf("creating tar ball of \"%s\"\n", dependents[i]); 
+                       deps = get_deps(NULL, dependents[i]);
+                       if (deps != NULL)
+                               create_tar(deps, dependents[i], argv[2]);                       
+                       talloc_free(deps);
+               }
+
+       talloc_free(dependents);
        return 0;
 }
index 80c6b88960a1013ab60f527e7b6b1eb76a040d70..d29bed87e294e6df753f5a98e8cf65eeb657f4ad 100644 (file)
@@ -9,10 +9,10 @@ $repopath = "testrepo/";
 $ccanlint = "tools/ccanlint -d ";
 
 //infotojson 
-$infotojson = "tools/infotojson ";
+$infotojson = "../../tools/infotojson ";
 
 //create tar of all dependencies
-$create_dep_tar = "../tools/create_dep_tar ";
+$create_dep_tar = "../../tools/create_dep_tar ";
 
 //junk code
 $junkcode = "junkcode/";
@@ -32,5 +32,15 @@ $frommail = "ccan@ozlabs.org";
 //email for admins
 $ccan_admin = "g.dinesh.cse@gmail.com";
 
+//ccan home 
 $ccan_home_dir = "ccan/";
+
+//bzr clone 
+$bzr_clone = 'bzr clone /home/dinesh/testwebsite/ ';
+
+//bzr push 
+$bzr_push = 'bzr push /home/dinesh/testwebsite/ ';
+
+//tar home dir
+$tar_dir = 'tarball/';
 ?>
\ No newline at end of file
index 30078430204eee429a34814a69569db88508b1fe..77ba6a0124043f33651ca520d14f848fa4d6fc46 100755 (executable)
Binary files a/web/db/ccan.db and b/web/db/ccan.db differ
index b6f0817286c6b6c48bdbf31aa7e247071111b44e..b0aba20e0097b4694b92f3992b122ec5523abee6 100644 (file)
@@ -8,25 +8,20 @@ $handle = sqlite3_open($db) or die("Could not open database");
 $query = "select * from search where module=\"".$_GET['module']."\"";
 $result = sqlite3_query($handle, $query) or die("Error in query: ".sqlite3_error($handle));
 $row = sqlite3_fetch_array($result);
-
-if (!file_exists($repopath . $ccan_home_dir.$_GET['module']."/".$_GET['module'].".tar")) {
-       chdir($repopath);
-       exec("tar -cvvf ".$ccan_home_dir. $_GET['module']. "/". $_GET['module'].".tar ". $ccan_home_dir.$_GET['module'], $status);
-       chdir("..");
-}
-
-if (!file_exists($repopath . $ccan_home_dir.$_GET['module']."/".$_GET['module']."_dep.tar")) {
-       chdir($repopath);
-       exec($create_dep_tar." ".$ccan_home_dir.$_GET['module'], $status);
-       chdir("..");
-}
-
-
 ?>
 <table align="center" bgcolor="lightblue" width="70%" border="0" cellpadding="3" cellspacing="1">
 <tr align="center" bgcolor="FFFFCC">
-<td width="50%"><a href=<?=$repopath . $ccan_home_dir.$_GET['module']?>/<?=$_GET['module']?>.tar>Download</a></td>
-<td><a href=<?=$repopath . $ccan_home_dir.$_GET['module']?>/<?=$_GET['module']?>_dep.tar>Download Dependencies</a></td>
+<td width="50%">
+       <?php 
+               if(file_exists($tar_dir . $_GET['module']."_dependencies.tar"))
+                       echo '<a href='. $tar_dir . $_GET['module'] . '.tar>Download</a>';
+       ?>
+<td>
+       <?php 
+               if(file_exists($tar_dir . $_GET['module']."_dependencies.tar"))
+                       echo '<a href='. $tar_dir . $_GET['module'] . '_dependencies.tar>Download Dependencies</a>';
+       ?>
+</td>
 </tr>
 </table>
 <table align="center" bgcolor="lightblue" width="70%" border="0" cellpadding="8" cellspacing="1">
@@ -42,7 +37,21 @@ if (!file_exists($repopath . $ccan_home_dir.$_GET['module']."/".$_GET['module'].
 <td><h3>Author: </h3> <pre><a href=search.php?author=<?=$row['author'];?>><?=$row['author'];?></a></pre></td>
 </tr>
 
+<tr align="left" bgcolor="FFFFCC">
+<td><h3>Dependencies: </h3> <pre><?=$row['depends'];?></pre></td>
+</tr>
+
 <tr align="left" bgcolor="FFFFCC">
 <td><h3>Description: </h3> <pre><?=$row['desc'];?></pre></td>
 </tr>
 </table><hr>
+
+<?php 
+function checkerror($status, $msg)
+{
+       if($status != 0) {
+                   echo "<div align=\"center\">" . $msg . "Contact ccan admin. </div>";
+                   exit();
+       }
+} 
+?>
\ No newline at end of file
diff --git a/web/tarball/.tar b/web/tarball/.tar
new file mode 100644 (file)
index 0000000..54203d2
Binary files /dev/null and b/web/tarball/.tar differ
index 467c51c04e7e0e4af1a22f3aa1419d00ff056df7..0cb1c18409b5c030d263160f996d474fc53c399b 100644 (file)
@@ -22,22 +22,12 @@ if($_FILES["uploadedfile"]["type"] == "application/x-gzip"
                $tempfolder . $_FILES["uploadedfile"]["name"]);
        
        //extracting code
-       if($_FILES["uploadedfile"]["type"] == "application/zip") {
+       if($_FILES["uploadedfile"]["type"] == "application/zip")
                exec('unzip '.$tempfolder.$_FILES["uploadedfile"]["name"].' -d '.$tempfolder, $op, $status);
-       }
-       else {
+       else
                exec('tar -xf '.$tempfolder.$_FILES["uploadedfile"]["name"].' -C '.$tempfolder, $op, $status);
-       }
-       checkerror($status[0],"Error: cannot extract(tar error).");     
+       checkerror($status,"Error: cannot extract(tar error).");        
 
-       //chmod
-       exec('chmod -R 0777 '. $tempfolder.$folder, $status);
-       checkerror($status[0],"Error: chmod execution error."); 
-       
-       //running ccanlint
-       exec($ccanlint.$tempfolder.$folder, $score, $status);
-       //checkerror($status,"Error: ccanlint execution error.");       
-       
        //if user not logged in
        if($_SESSION["slogged"] == false) {
                //move to temp folder 
@@ -47,56 +37,107 @@ if($_FILES["uploadedfile"]["type"] == "application/x-gzip"
                
                //send mail for review to admins 
                $subject = "Review: code upload at temporary repository"; 
-               $message = "Some developer has uploaded code who has not logged in.\n\nModule is stored in ".$temprepo.$folder.".\n\nOutput of ccanlint: \n";
-               foreach($score as $disp)
-                       $message = $message.$disp."\n";
+               $message = "Some developer has uploaded code who has not logged in.\n\nModule is stored in ".
+                                                       $temprepo.$folder.".\n\nOutput of ccanlint: \n";
                        
        $toaddress = getccanadmin($db);
        mail($toaddress, $subject, $message, "From: $frommail");
-       echo "<div align=\"center\"> Stored to temporary repository. Mail will be send to admin to get verification of the code.<//div>";
+       echo "<div align=\"center\"> Stored to temporary repository. 
+                               Mail will be send to admin to get verification of the code.<//div>";
        unlink($tempfolder.$_FILES["uploadedfile"]["name"]);
        exit();
        } 
 
+       //running ccanlint
+       exec($ccanlint.$tempfolder.$folder, $score, $status);
+               
        //if not junk code 
        if($status == 0) {
                $rename = $folder;
+               $exactpath = $repopath . $_SESSION['susername'] .'/';
+               
+               if (file_exists($exactpath)) {
+                       echo "<div align=\"center\"> Your another upload is in progress please wait...</div>";
+                       exit();
+               }
+               
+               //bzr local repo for commit
+               chdir($repopath);
+               unset($op); exec($bzr_clone . $_SESSION['susername'], $op, $status);
+               checkerror($status, "Error: bzr local repo.");
+               chdir('..');
+                               
                //if module already exist 
-               if (file_exists($repopath.$ccan_home_dir . $folder)) {
+               if (file_exists($exactpath . $ccan_home_dir . $folder)) {
+
                        // if owner is not same 
-                       if(!(getowner($repopath.$ccan_home_dir.$folder, $db) == $_SESSION['susername'])) {      
-                               if(!file_exists($repopath . $ccan_home_dir. $folder.'-'.$_SESSION['susername']))                        
-                               echo "<div align=\"center\">".$repopath . $ccan_home_dir. $folder . " already exists. Renaming to ". $folder."-".$_SESSION['susername']."</div>";
+                       if(!(getowner($ccan_home_dir . $folder, $db) == $_SESSION['susername'])) {      
+                               if(!file_exists($repopath . $ccan_home_dir . $folder . '-' . $_SESSION['susername']))                           
+                               echo "<div align=\"center\">". $ccan_home_dir . $folder . 
+                                               " already exists. Renaming to " . $folder . "-" . $_SESSION['susername'] . "</div>";
                else
-                               echo "<div align=\"center\">".$repopath . $ccan_home_dir. $folder."-".$_SESSION['susername'] . " already exists. Overwriting ". $folder."-".$_SESSION['susername']."</div>";
+                               echo "<div align=\"center\">". $ccan_home_dir . $folder . 
+                                               "-" . $_SESSION['susername'] . " already exists. Overwriting " . 
+                                                       $folder. "-" . $_SESSION['susername'] . "</div>";
                        $rename = $folder."-".$_SESSION['susername'];
                }
+               
                else
-                       echo "<div align=\"center\">".$repopath. $ccan_home_dir. $folder. " already exists(uploaded by you). Overwriting ". $repopath. $folder."</div>";        
+                       echo "<div align=\"center\">".$repopath. $ccan_home_dir. $folder.
+                                        " already exists(uploaded by you). Overwriting ". $repopath. $folder."</div>";
+                               
                }
+
                //module not exist. store author to db 
                else {
-                       storefileowner($repopath . $ccan_home_dir. $folder, $_SESSION['susername'], $db);
+                       storefileowner($ccan_home_dir . $folder, $_SESSION['susername'], $db);
                }
-               rmdirr($repopath. $ccan_home_dir. $rename);
-      rename($tempfolder.$folder, $repopath. $ccan_home_dir. $rename);
-      echo "<div align=\"center\"> Stored to ".$repopath . $ccan_home_dir. $rename . "</div>";
+
+               rmdirr($exactpath . $ccan_home_dir . $rename);
+          rename($tempfolder . $folder, $exactpath . $ccan_home_dir . $rename);
+               
+       chdir($exactpath);
+               unset($op); exec($infotojson . $ccan_home_dir . $rename . " " . $ccan_home_dir.
+                                                $rename."/_info.c ". $ccan_home_dir . $rename . "/json_" . $rename . " " 
+                                                       . $_SESSION['susername']. " ../../" . $db, $op, $status);
+               checkerror($status,"Error: In infotojson.");
+               
+               unset($op); exec('bzr add', $op, $status);
+               checkerror($status,"Error: bzr add error.");
+               
+               unset($op); exec('bzr commit --unchanged -m "commiting from ccan web ' . $rename . 
+                                                       " " . $_SESSION['susername'] . '"', $op, $status);
+               checkerror($status,"Error: bzr commit error."); 
+                       
+               unset($op); exec($bzr_push, $op, $status);
+               checkerror($status,"Error: bzr push error.");
                
-               exec($infotojson . $repopath. $ccan_home_dir. $rename."/_info.c ". $repopath. $ccan_home_dir. $rename."/json_".$rename. " ". $_SESSION['susername']." ".$db, $status);
-               checkerror($status[0],"Error: In infotojson."); 
-               //createsearchindex($rename, $repopath.$rename, $infofile, $db, $_SESSION['susername']);
+               unset($op); exec($create_dep_tar . " " . $ccan_home_dir. $rename . " ../../" . 
+                                                       $tar_dir . " ../../" . $db , $op, $status); 
+               checkerror($status,"Error: bzr push error.");
+               
+               chdir('../..');
+               rmdirr($exactpath);
+       echo "<div align=\"center\"> Stored to ". $ccan_home_dir . $rename . "</div>";
        }
        
        //if junk code (no _info.c etc) 
        else {
+       
                rmdirr($junkcode.$folder.'-'.$_SESSION['susername']);
                rename($tempfolder.$folder, $junkcode.$folder.'-'.$_SESSION['susername']);
+               
                if($score == '')
                        $msg =  'Below is details for test.';
-               echo "<div align=\"center\"><table><tr><td> Score for code is low. Cannot copy to repository. Moving to ". $junkcode.$folder.'-'.$_SESSION['susername']."... </br></br>". $msg ." </br></br></td></tr><tr><td>";
+                       
+               echo "<div align=\"center\"><table><tr><td> Score for code is low.
+                                Cannot copy to repository. Moving to ". $junkcode.$folder.'-'.
+                                       $_SESSION['susername']."... </br></br>". $msg ." </br></br></td></tr><tr><td>";
+
                foreach($score as $disp)
                        echo "$disp</br>";
                echo "</td></tr></table></div>";
+               
        }
        unlink($tempfolder.$_FILES["uploadedfile"]["name"]);
 }