Rusty Russell 17 years ago
parent
commit
4106954981
10 changed files with 217 additions and 63 deletions
  1. 25 0
      ccan/string/test/run-grab.c
  2. 13 2
      ccan/string/test/run.c
  3. 2 1
      tools/Makefile
  4. BIN
      tools/create_dep_tar
  5. 68 11
      tools/create_dep_tar.c
  6. 12 2
      web/configuration
  7. BIN
      web/db/ccan.db
  8. 25 16
      web/dispmoduleinfo.php
  9. BIN
      web/tarball/.tar
  10. 72 31
      web/uploader.php

+ 25 - 0
ccan/string/test/run-grab.c

@@ -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 */

+ 13 - 2
ccan/string/test/run.c

@@ -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();
 }				

+ 2 - 1
tools/Makefile

@@ -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
 

BIN
tools/create_dep_tar


+ 68 - 11
tools/create_dep_tar.c

@@ -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;
 }

+ 12 - 2
web/configuration

@@ -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/';
 ?>

BIN
web/db/ccan.db


+ 25 - 16
web/dispmoduleinfo.php

@@ -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();
+	}
+} 
+?>

BIN
web/tarball/.tar


+ 72 - 31
web/uploader.php

@@ -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"]);
 }