Permalink
Browse files

rework how the adafruit python library is loaded. Create new projects…

… folder
  • Loading branch information...
1 parent ab4b110 commit 9d1d5542ae79fe9433949cf493a730ad3e8dc321 @jwcooper jwcooper committed Sep 10, 2012
Showing with 100 additions and 19 deletions.
  1. +3 −0 config/README.md
  2. +43 −0 config/config.js
  3. +2 −2 controllers/editor.js
  4. +20 −1 helpers/fs_helper.js
  5. +12 −4 helpers/git_helper.js
  6. +20 −12 server.js
View
@@ -0,0 +1,3 @@
+Welcome to the Adafruit WebIDE.
+
+TODO: Write something unique
View
@@ -0,0 +1,43 @@
+exports.adafruit = {
+ "repository": "Adafruit-Raspberry-Pi-Python-Code",
+ "remote": "git://github.com/adafruit/Adafruit-Raspberry-Pi-Python-Code.git",
+ "remote_name": "adaremote"
+};
+
+exports.defaults = {
+ "repository": "my-pi-projects",
+ "readme": "README.md"
+};
+
+exports.term = {
+ "shell": "bash",
+ "cwd": "./repositories",
+ "log": true,
+ "term": {
+ "termName": "xterm",
+ "geometry": [80, 15],
+ "scrollback": 1000,
+ "visualBell": false,
+ "popOnBell": false,
+ "cursorBlink": false,
+ "screenKeys": false,
+ "colors": [
+ "#2e3436",
+ "#cc0000",
+ "#4e9a06",
+ "#c4a000",
+ "#3465a4",
+ "#75507b",
+ "#06989a",
+ "#d3d7cf",
+ "#555753",
+ "#ef2929",
+ "#8ae234",
+ "#fce94f",
+ "#729fcf",
+ "#ad7fa8",
+ "#34e2e2",
+ "#eeeeec"
+ ]
+ }
+};
View
@@ -1,10 +1,10 @@
var fs_helper = require('../helpers/fs_helper'),
git_helper = require('../helpers/git_helper'),
- config = require('../config');
+ config = require('../config/config');
//Loads the editor
exports.index = function(req, res) {
- git_helper.pull(config.adafruit.repository, config.adafruit.remote_name, "master", function() {
+ git_helper.pull(config.adafruit.repository, "origin", "master", function() {
console.log('pulled latest adafruit from github');
});
res.render('editor/index', {profile: req.user});
View
@@ -1,6 +1,7 @@
var path = require('path'),
fs = require('fs'),
util = require('util'),
+ config = require('../config/config');
exec = require('child_process').exec;
exports.has_ssh_key = function has_ssh_key(cb) {
@@ -102,4 +103,22 @@ exports.open_file = function(path, cb) {
fs.readFile(__dirname + '/' + path, 'ascii', function(err,data){
cb(data);
});
-}
+};
+
+exports.create_project_readme = function(cb) {
+ var source = __dirname + '/../config/README.md';
+ var destination = __dirname + '/../repositories/' + config.defaults.repository + '/' + config.defaults.readme;
+ var file = {repository: config.defaults.repository, path: config.defaults.readme, name: config.defaults.readme};
+
+ fs.lstat(destination, function(err, stat) {
+ if (stat) cb("README already exists", file); //file exists
+
+ var is = fs.createReadStream(source);
+ var os = fs.createWriteStream(destination);
+ util.pump(is, os, function(err) {
+ console.log(err);
+ cb(err, file);
+ });
+
+ });
+};
View
@@ -50,6 +50,7 @@ exports.clone_update_remote_push = function(profile, repository_url, cb) {
};
exports.clone_repository = function(profile, repository_path, cb) {
+ console.log(repository_path);
var repository_url = url.parse(repository_path);
console.log("cloning", repository_path);
@@ -161,10 +162,17 @@ exports.remove_commit_push = function(item, cb) {
};
exports.commit_push_and_save = function(file, cb) {
- var self = this;
- var path_array = file.path.split('/');
- var repository = path_array[2];
- var file_path = path_array.slice(3).join('/');
+ var self = this,
+ path_array, repository, file_path;
+ if (!file.repository) {
+ path_array = file.path.split('/');
+ repository = path_array[2];
+ file_path = path_array.slice(3).join('/');
+ } else {
+ repository = file.repository;
+ file_path = file.path;
+ }
+
self.add(repository, file_path, function(err, status) {
console.log("added", err, status);
View
@@ -13,12 +13,13 @@ var express = require('express'),
fs = require('fs'),
path = require('path'),
git_helper = require('./helpers/git_helper'),
+ fs_helper = require('./helpers/fs_helper'),
request_helper = require('./helpers/request_helper'),
exec_helper = require('./helpers/exec_helper'),
RedisStore = require('connect-redis')(express),
redis = require("redis"),
client = redis.createClient(),
- config = require('./config');
+ config = require('./config/config');
var davServer;
console.log(__dirname);
@@ -68,30 +69,37 @@ function setup_passport(consumer_key, consumer_secret) {
profile.consumer_key = consumer_key;
profile.consumer_secret = consumer_secret;
+ var project_repository = 'git@bitbucket.org:' + profile.username + '/my-pi-projects.git';
+
//TODO REFACTOR THIS MESS
request_helper.list_repositories(profile, function(err, list) {
var exists = list.some(function(repository) {
- return (repository.name === config.adafruit.repository);
+ return (repository.name.toLowerCase() === config.defaults.repository.toLowerCase());
});
git_helper.clone_adafruit_libraries(config.adafruit.repository, config.adafruit.remote, function() {
if (!exists) {
- request_helper.create_repository(profile, config.adafruit.repository, function(err, response) {
- console.log("created adafruit repository in bitbucket");
- git_helper.update_remote(profile, config.adafruit.repository, function(err, response) {
- console.log("updated remote for adafruit repository");
- git_helper.add_remote(config.adafruit.repository, config.adafruit.remote_name, config.adafruit.remote, function(err, response) {
- console.log("added remote for adafruit repository");
- git_helper.push(config.adafruit.repository, "origin", "master", function(err, response) {
+ request_helper.create_repository(profile, config.defaults.repository, function(err, response) {
+ git_helper.clone_repository(profile, project_repository, function(err, response) {
+ console.log("created personal repository in bitbucket");
+ fs_helper.create_project_readme(function(err, file) {
+ if (err) console.log(err);
+ console.log(file);
+
+ git_helper.commit_push_and_save(file, function(err, response) {
return done(null, profile);
});
});
});
});
} else {
- git_helper.update_remote(profile, config.adafruit.repository, function(err, response) {
- git_helper.add_remote(config.adafruit.repository, "adaremote", config.adafruit.remote, function(err, response) {
- git_helper.push(config.adafruit.repository, "origin", "master", function(err, response) {
+ git_helper.clone_repository(profile, project_repository, function(err, response) {
+ console.log(err, response);
+ fs_helper.create_project_readme(function(err, file) {
+ console.log(file);
+ if (err) console.log(err);
+
+ git_helper.commit_push_and_save(file, function(err, response) {
return done(null, profile);
});
});

0 comments on commit 9d1d554

Please sign in to comment.