homer 0.1.2 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -3,6 +3,7 @@ source "http://rubygems.org"
3
3
  # Example:
4
4
  # gem "activesupport", ">= 2.3.5"
5
5
  gem "github_api"
6
+ gem "highline"
6
7
 
7
8
  # Add dependencies to develop your gem here.
8
9
  # Include everything needed to run rake, tests, features, etc.
data/Gemfile.lock CHANGED
@@ -12,6 +12,7 @@ GEM
12
12
  nokogiri (~> 1.5.2)
13
13
  oauth2
14
14
  hashie (1.2.0)
15
+ highline (1.6.15)
15
16
  httpauth (0.1)
16
17
  jeweler (1.8.4)
17
18
  bundler (~> 1.0)
@@ -44,6 +45,7 @@ PLATFORMS
44
45
  DEPENDENCIES
45
46
  bundler
46
47
  github_api
48
+ highline
47
49
  jeweler (~> 1.8.4)
48
50
  rdoc (~> 3.12)
49
51
  rspec
data/README.md CHANGED
@@ -29,4 +29,7 @@ Need to pair program at co-worker's hostile box .
29
29
  homer hi <github login>
30
30
  - When friend complains after your display of awesomeness
31
31
 
32
- homer bye
32
+ homer bye
33
+
34
+ ## Wishlist
35
+ - Use a table for listing tracked files and Symlinks ( Use [terminal table](https://github.com/visionmedia/terminal-table) ? )
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.2
1
+ 0.2.0
data/bin/homer CHANGED
@@ -7,7 +7,7 @@ class HomerRunner < Thor
7
7
 
8
8
  default_task :help
9
9
 
10
- desc "wipe", "Removes ~/.homer folder. WARNING : THIS IS DANGEROUS . Have a sip of Green Tea and ask yourself why you are doing this"
10
+ desc "wipe", "Removes ~/.homer folder. WARNING : THIS IS DANGEROUS"
11
11
  def wipe
12
12
  Homer.wipe
13
13
  rescue Exception => e
@@ -38,8 +38,7 @@ class HomerRunner < Thor
38
38
 
39
39
  desc "push", "Pushes your dotfiles to GitHub"
40
40
  def push
41
- puts "This should push the dotfiles folder to github"
42
- GitHubLayer.push
41
+ Homer.push
43
42
  rescue Exception => e
44
43
  puts "Error: #{e.message}"
45
44
  end
data/homer.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "homer"
8
- s.version = "0.1.2"
8
+ s.version = "0.2.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Emil Soman"]
12
- s.date = "2012-10-01"
12
+ s.date = "2012-10-20"
13
13
  s.description = "Homer makes tracking your Unix dotfiles easay peasay - UNDER DEVELOPMENT"
14
14
  s.email = "emil.soman@gmail.com"
15
15
  s.executables = ["homer"]
@@ -51,6 +51,7 @@ Gem::Specification.new do |s|
51
51
 
52
52
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
53
53
  s.add_runtime_dependency(%q<github_api>, [">= 0"])
54
+ s.add_runtime_dependency(%q<highline>, [">= 0"])
54
55
  s.add_development_dependency(%q<rspec>, [">= 0"])
55
56
  s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
56
57
  s.add_development_dependency(%q<bundler>, [">= 0"])
@@ -58,6 +59,7 @@ Gem::Specification.new do |s|
58
59
  s.add_development_dependency(%q<jeweler>, ["~> 1.8.4"])
59
60
  else
60
61
  s.add_dependency(%q<github_api>, [">= 0"])
62
+ s.add_dependency(%q<highline>, [">= 0"])
61
63
  s.add_dependency(%q<rspec>, [">= 0"])
62
64
  s.add_dependency(%q<rdoc>, ["~> 3.12"])
63
65
  s.add_dependency(%q<bundler>, [">= 0"])
@@ -66,6 +68,7 @@ Gem::Specification.new do |s|
66
68
  end
67
69
  else
68
70
  s.add_dependency(%q<github_api>, [">= 0"])
71
+ s.add_dependency(%q<highline>, [">= 0"])
69
72
  s.add_dependency(%q<rspec>, [">= 0"])
70
73
  s.add_dependency(%q<rdoc>, ["~> 3.12"])
71
74
  s.add_dependency(%q<bundler>, [">= 0"])
@@ -5,64 +5,59 @@ require 'yaml'
5
5
  class FileLayer
6
6
  class << self
7
7
 
8
- def save_authorization_token(token)
9
- f = File.open(token_path, "a")
10
- f.puts token
11
- f.close
12
- rescue Exception => e
13
- raise "GitHub token could not be saved : Error : #{e.message}"
14
- end
15
-
8
+ #Creates the homer root directory if it does not exist already
9
+ #Creates the dotfiles directory if it does not exist already
10
+ #Creates a dotfiles list YML file if it does not exist already
16
11
  def prepare_homer_folder
17
- Dir.mkdir(File.join(Dir.home, ".homer")) unless Dir.exists?(File.join(Dir.home, ".homer"))
18
- Dir.mkdir(File.join(Dir.home, ".homer", "dotfiles")) unless Dir.exists?(File.join(Dir.home, ".homer", "dotfiles"))
12
+ Dir.mkdir(root_path) unless Dir.exists?(root_path)
13
+ Dir.mkdir(dotfiles_directory_path) unless Dir.exists?(dotfiles_directory_path)
19
14
  File.new(dotfiles_path , "w") unless File.exists?(dotfiles_path)
20
15
  rescue Exception => e
21
16
  raise "~/.homer cannot be created : #{e.message}"
22
17
  end
23
18
 
19
+ #Deletes the homer root
24
20
  def delete_homer_folder
25
- FileUtils.rm_rf(File.join(Dir.home, ".homer"))
21
+ FileUtils.rm_rf(root_path)
26
22
  end
27
23
 
28
- def add_filename_to_dotfiles(dotfile)
29
- dotfile = File.expand_path(dotfile)
30
- f = File.open(dotfiles_path, "a")
31
- raise "#{dotfile} does not exist." unless File.exists?(dotfile)
32
- f.puts dotfile
33
- f.close
34
- end
35
-
24
+ #Reads and returns the contents of the dotfiles list YML file
36
25
  def read_symlink_file
37
26
  return {} if !File.exists?(dotfiles_path) or File.zero?(dotfiles_path)
38
27
  YAML.load_file(dotfiles_path)
39
28
  end
40
29
 
30
+ #Writes contents to dotfiles list YML file
41
31
  def save_symlink_file(symlinks)
42
32
  File.open(dotfiles_path,"w") do |out|
43
33
  YAML.dump(symlinks,out)
44
34
  end
45
35
  end
46
36
 
37
+ #Moves the file to dotfiles directory and creates a symlink at original location
47
38
  def create_symlink(filename,file_path)
48
- FileUtils.mv(file_path, File.join(dotfiles_directory_path, filename))
49
- File.symlink(File.join(dotfiles_directory_path, filename), file_path)
39
+ file_in_dotfiles_folder = File.join(dotfiles_directory_path, filename)
40
+ FileUtils.mv(file_path, file_in_dotfiles_folder)
41
+ File.symlink(file_in_dotfiles_folder, file_path)
50
42
  end
51
43
 
52
- def dotfiles_directory_path
53
- File.join(Dir.home, ".homer", "dotfiles", "/")
54
- end
44
+ #HOMER PATHS
55
45
 
46
+ #This is the dotfiles list YML file .
47
+ #This is where a mapping of files in dotfiles folder
48
+ #to actual location in filesystem exists
56
49
  def dotfiles_path
57
- return File.join(Dir.home, ".homer", "dotfiles", "dotfiles_list")
50
+ return File.join(dotfiles_directory_path, "dotfiles_list.yml")
58
51
  end
59
52
 
60
- def root_path
61
- return File.join(Dir.home, ".homer")
53
+ #This is the directory to which the dotfiles will be moved
54
+ def dotfiles_directory_path
55
+ return File.join(root_path, "dotfiles/")
62
56
  end
63
57
 
64
- def token_path
65
- File.join(root_path, "token")
58
+ #This is where homer
59
+ def root_path
60
+ return File.join(Dir.home, ".homer")
66
61
  end
67
62
 
68
63
  def get_generic_home_relative_path(filepath)
@@ -1,29 +1,38 @@
1
1
  require 'github_api'
2
2
  require 'homer/file_layer'
3
- Github::Authorizations::VALID_AUTH_PARAM_NAMES = Github::Authorizations::VALID_AUTH_PARAM_NAMES + ["note"]
3
+ require 'highline/import'
4
4
 
5
5
  class GitHubLayer
6
+ REPO_NAME = 'dotfiles'
6
7
  class << self
7
8
 
8
- def push
9
+ def push(directory)
10
+ create_repo_if_repo_does_not_exist(directory)
11
+ %x{git pull origin master}
12
+ %x{git add .}
13
+ %x{git commit -m "Homer push"}
14
+ %x{git push origin master}
9
15
  end
10
16
 
11
- def login(login, password)
17
+ def create_repo_if_repo_does_not_exist(directory)
18
+ Dir.chdir(directory)
19
+ return if origin_added_as_remote?
20
+ puts "I need your GitHub login to create a '#{REPO_NAME}' repo if it doesn't exist already"
21
+ login = ask("Login: ")
22
+ password = ask("Password: ") { |q| q.echo = false }
12
23
  github = Github.new(login: login, password: password)
13
- authorization = github.oauth.create(scopes: ['public_repo'], note: 'Homer')
14
- FileLayer.save_authorization_token(authorization.token)
15
- rescue Github::Error::Unauthorized
16
- raise "Invalid GitHub Login/Password"
17
- end
18
-
19
- def create_repo_if_repo_does_not_exist(repo_name)
20
- token = FileLayer.read_authorization_token
21
- github = Github.new(oauth_token: token)
22
24
  begin
23
- github.repos.get(github.login, repo_name)
25
+ github.repos.get(github.login, REPO_NAME)
24
26
  rescue Github::Error::NotFound
25
- github.repos.create(name: repo_name)
27
+ github.repos.create(name: REPO_NAME)
26
28
  end
29
+ %x{git init .}
30
+ %x{git remote add origin git@github.com:#{login}/#{REPO_NAME}.git}
31
+ end
32
+
33
+ def origin_added_as_remote?
34
+ remotes = %x{git remote -v}
35
+ return remotes.include?("origin\t")
27
36
  end
28
37
 
29
38
  end
data/lib/homer/symlink.rb CHANGED
@@ -1,10 +1,13 @@
1
1
  class SymLink
2
2
 
3
+ #Returns all files in dotfiles_list
3
4
  def self.filenames
4
5
  symlinks = FileLayer.read_symlink_file
5
6
  symlinks.keys
6
7
  end
7
8
 
9
+ #Adds file to dotfiles_list , moves the file to dotfiles folder
10
+ #and creates a symlink with original filepath
8
11
  def self.add(dotfile)
9
12
  dotfile = File.expand_path(dotfile)
10
13
  raise "#{dotfile} does not exist." unless File.exists?(dotfile)
@@ -17,6 +20,8 @@ class SymLink
17
20
  end
18
21
 
19
22
  private
23
+
24
+ #Gets the next unused filename by adding an integer suffix to filename
20
25
  def self.get_unused_filename(filename, existing_filenames)
21
26
  filename_to_store = filename
22
27
  count = 1
data/lib/homer.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require 'homer/file_layer'
2
+ require 'homer/github_layer'
2
3
  require 'homer/symlink'
3
4
 
4
5
  class Homer
@@ -22,6 +23,11 @@ class Homer
22
23
  SymLink.filenames
23
24
  end
24
25
 
26
+ def push
27
+ dotfiles_dir = FileLayer.dotfiles_directory_path
28
+ GitHubLayer.push(dotfiles_dir)
29
+ end
30
+
25
31
  end
26
32
 
27
33
  end
@@ -16,13 +16,7 @@ describe FileLayer do
16
16
 
17
17
  describe ".dotfiles_path" do
18
18
  it "should return the path to dotfiles_list" do
19
- FileLayer.dotfiles_path.should == File.join(Dir.home, ".homer", "dotfiles", "dotfiles_list")
20
- end
21
- end
22
-
23
- describe ".token_path" do
24
- it "should return the path to file where GitHub token is saved" do
25
- FileLayer.token_path.should == File.join(Dir.home, ".homer", "token")
19
+ FileLayer.dotfiles_path.should == File.join(Dir.home, ".homer", "dotfiles", "dotfiles_list.yml")
26
20
  end
27
21
  end
28
22
 
@@ -32,12 +26,4 @@ describe FileLayer do
32
26
  end
33
27
  end
34
28
 
35
- describe ".save_authorization_token" do
36
- it "should store token into token file" do
37
- Homer.init
38
- FileLayer.save_authorization_token("abc")
39
- Homer.wipe
40
- end
41
- end
42
-
43
29
  end
@@ -2,46 +2,5 @@ require 'spec_helper'
2
2
  require 'homer/github_layer'
3
3
 
4
4
  describe GitHubLayer do
5
-
6
- describe "create_token" do
7
- context "invalid credentials" do
8
- it "should raise exception" do
9
- github = double('GitHub')
10
- Github.should_receive(:new).with(login: "login",password: "password").and_return(github)
11
- github.should_receive(:oauth).and_raise(Github::Error::Unauthorized.new({}))
12
- expect { GitHubLayer.login("login","password") }.to raise_error "Invalid GitHub Login/Password"
13
- end
14
- end
15
- context "valid credentials" do
16
- it "should save the authorization token" do
17
- github = double('GitHub').as_null_object
18
- Github.should_receive(:new).with(login: "login", password: "password").and_return(github)
19
- github.stub_chain(:oauth, :create).and_return Hashie::Mash.new({"token" => "received_token" })
20
- FileLayer.should_receive(:save_authorization_token).with("received_token")
21
- GitHubLayer.login("login","password")
22
- end
23
- end
24
- end
25
-
26
- describe "create_repo" do
27
- it "should create a repository"
28
- end
29
-
30
- describe "initialization" do
31
- it "should log in to github account with login and password"
32
- describe "handling dotfiles repo" do
33
- context "when dotfiles repo already exists" do
34
- context "when homer folder does not exist inside the dotfiles repo" do
35
- it "should create the directory"
36
- end
37
- context "when homer folder does not exist inside the dotfiles repo" do
38
- it "should ask the user what to do"
39
- end
40
- end
41
- context "when dotfiles repo does not exist" do
42
- it "should create the repo"
43
- end
44
- end
45
- end
46
5
 
47
6
  end
data/spec/homer_spec.rb CHANGED
@@ -13,7 +13,7 @@ describe Homer do
13
13
  Dir.exists?(File.join(Dir.home,'.homer/dotfiles')).should be_true
14
14
  end
15
15
  it "should create an empty dotfiles file in ~/.homer" do
16
- File.zero?(File.join(Dir.home,'.homer/dotfiles/dotfiles_list')).should be_true
16
+ File.zero?(File.join(Dir.home,'.homer/dotfiles/dotfiles_list.yml')).should be_true
17
17
  end
18
18
  end
19
19
 
@@ -23,7 +23,6 @@ describe Homer do
23
23
  expect do
24
24
  Homer.add('~/.file_that_does_not_exist')
25
25
  end.to raise_error("#{ENV['HOME']}/.file_that_does_not_exist does not exist.")
26
- #File.read(Homer.dotfiles_path).should include(File.join(Dir.home, ".file_that_does_not_exist"))
27
26
  end
28
27
  end
29
28
  context "when dotfile exists" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: homer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-10-01 00:00:00.000000000 Z
12
+ date: 2012-10-20 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: github_api
@@ -27,6 +27,22 @@ dependencies:
27
27
  - - ! '>='
28
28
  - !ruby/object:Gem::Version
29
29
  version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: highline
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
30
46
  - !ruby/object:Gem::Dependency
31
47
  name: rspec
32
48
  requirement: !ruby/object:Gem::Requirement
@@ -152,7 +168,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
152
168
  version: '0'
153
169
  segments:
154
170
  - 0
155
- hash: -950767089
171
+ hash: 792016573
156
172
  required_rubygems_version: !ruby/object:Gem::Requirement
157
173
  none: false
158
174
  requirements: