<commit_before>/* vim: set et ts=4 sts=4 sw=4 tw=72 */
/* See the LICENSE file for the license of the project */
package uk.ac.cam.UROP.twentyfourteen;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 * @author <NAME> <<EMAIL>>
 * @author <NAME> <<EMAIL>>
 * @version 0.1
 */
public class ConfigDatabase {

	/**
	 * Generates config file for gitolite.
	 * <p>
	 * Accesses mongoDB look up relevant information.
	 * 
	 * @return The gitolite config file
	 */
	public static void generateConfigFile() {
		/* TODO: implement
         *
         * 1) Create a new StringBuilder
         * 2) Fill in StringBuilder according to a template
         * 3) Write file to disk
         */
		StringBuilder output = new StringBuilder();
		output.append("repo create-new\n");
		output.append("    RW = admin\n");
		output.append("    R  = u2");
		try {
			String home = System.getProperty("user.home");
			File configFile = new File(home+"/test.conf");
			BufferedWriter buffWriter = new BufferedWriter(new FileWriter(configFile, false));
			buffWriter.write(output.toString());
			buffWriter.close();
			Process p = Runtime.getRuntime().exec(home+"/.gitolite/hooks/gitolite-admin/post-update",
						new String[] {"HOME="+home, "PATH="+home+"/bin/:/bin:/usr/bin", "GL_LIBDIR="+home+"/git/gitolite/src/lib"});
			
			BufferedReader errorReader = new BufferedReader(new InputStreamReader(p.getErrorStream()));
			BufferedReader outputReader = new BufferedReader(new InputStreamReader(p.getInputStream()));
			String line;
			while ((line = outputReader.readLine()) != null) {
				System.out.println(line);
			}
			while ((line = errorReader.readLine()) != null) {
				System.err.println(line);
			}
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
	public static void main(String[] args) {
		generateConfigFile();
		System.out.println("Done");
	}
	
	
	/**
	 * Adds student SSH public key.
	 * 
	 * @param key The SSH key to be added
	 */
	public void addSSHKey(String key) {
		/* TODO: implement
         *
         * See gitolite §11.5
         */
	}

}<commit_msg>generateConfigFile now reads repo names from mongoDB<commit_after>/* vim: set et ts=4 sts=4 sw=4 tw=72 */
/* See the LICENSE file for the license of the project */
package uk.ac.cam.UROP.twentyfourteen;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.List;

import com.mongodb.BasicDBObject;
import com.mongodb.Cursor;
import com.mongodb.DBCollection;
import com.mongodb.DBObject;

import uk.ac.cam.UROP.twentyfourteen.database.Mongo;

/**
 * @author <NAME> <<EMAIL>>
 * @author <NAME> <<EMAIL>>
 * @version 0.1
 */
public class ConfigDatabase {

	/**
	 * Generates config file for gitolite.
	 * <p>
	 * Accesses mongoDB look up relevant information.
	 * 
	 * @return The gitolite config file
	 */
	public static void generateConfigFile() {
		/* TODO: implement
         *
         * 1) Create a new StringBuilder
         * 2) Fill in StringBuilder according to a template
         * 3) Write file to disk
         */
		StringBuilder output = new StringBuilder();
		Cursor allRepos = Mongo.getDB().getCollection("repos").find();
		while (allRepos.hasNext()) {
			//DBObject repoDoc = allRepos.next();
			output.append("repo " + allRepos.next().get("repoName") + "\n");
			output.append("    RW = admin\n");
			output.append("    R  = u1\n\n");
		}
		try {
			String home = System.getProperty("user.home");
			File configFile = new File(home+"/test.conf");
			BufferedWriter buffWriter = new BufferedWriter(new FileWriter(configFile, false));
			buffWriter.write(output.toString());
			buffWriter.close();
			Process p = Runtime.getRuntime().exec(home+"/.gitolite/hooks/gitolite-admin/post-update",
						new String[] {"HOME="+home, "PATH="+home+"/bin/:/bin:/usr/bin", "GL_LIBDIR="+home+"/git/gitolite/src/lib"});
						BufferedReader errorReader = new BufferedReader(new InputStreamReader(p.getErrorStream()));
			BufferedReader outputReader = new BufferedReader(new InputStreamReader(p.getInputStream()));
			String line;
			while ((line = outputReader.readLine()) != null) {
				System.out.println(line);
			}
			while ((line = errorReader.readLine()) != null) {
				System.err.println(line);
			}
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
	public static void addRepo(String repoName) {
		DBCollection repoTable = Mongo.getDB().getCollection("repos");
		BasicDBObject repoDoc = new BasicDBObject();
		repoDoc.put("repoName", repoName);
		repoTable.insert(repoDoc);
	}
	
	public static void main(String[] args) {
		DBCollection repoTable = Mongo.getDB().getCollection("repos");
		if (repoTable != null)
			repoTable.remove(new BasicDBObject());
		addRepo("test-repo-one");
		addRepo("test-repo-two");
		generateConfigFile();
		System.out.println("Done");
	}
	
	
	/**
	 * Adds student SSH public key.
	 * 
	 * @param key The SSH key to be added
	 */
	public void addSSHKey(String key) {
		/* TODO: implement
         *
         * See gitolite §11.5
         */
	}

}
{'fraction_non_alphanumeric': 0.1441976254308694, 'fraction_numerical': 0.005361930294906166, 'mean_word_length': 3.46792130025663, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2014127', 'n_tokens_mistral': 1823, 'n_tokens_neox': 1634, 'n_words': 402}