This commit is contained in:
Rob Watson 2010-11-11 11:54:51 +00:00
parent 4a70eea676
commit f28ac5100d
8 changed files with 59 additions and 59 deletions

View File

@ -1,4 +1,4 @@
noprocast
noprocrast
=========
A gem to stop you procastinating. Noprocast automatically adds and removes items from your /etc/hosts, rendering addictive websites useless.
@ -6,18 +6,18 @@ A gem to stop you procastinating. Noprocast automatically adds and removes items
Installation
------------
gem install noprocast
gem install noprocrast
Usage
-----
`noprocast status` check if noprocast is enabled or not
`noprocrast status` check if noprocrast is enabled or not
`noprocast edit` edit noprocast's list of banned websites
`noprocrast edit` edit noprocrast's list of banned websites
`noprocast on` enable noprocast
`noprocrast on` enable noprocrast
`noprocast off` disable noprocast
`noprocrast off` disable noprocrast
Notes
-----

View File

@ -4,11 +4,11 @@ require 'rake'
begin
require 'jeweler'
Jeweler::Tasks.new do |gem|
gem.name = "noprocast"
gem.summary = %Q{Give procastination a swift kick in the balls.}
gem.name = "noprocrast"
gem.summary = %Q{Give procrastination a swift kick in the balls.}
gem.description = %Q{Block access to addictive websites in one command-line swoop.}
gem.email = "rfwatson@gmail.com"
gem.homepage = "http://github.com/rfwatson/noprocast"
gem.homepage = "http://github.com/rfwatson/noprocrast"
gem.authors = ["Rob Watson"]
gem.add_development_dependency "rspec", ">= 1.2.9"
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
@ -39,7 +39,7 @@ Rake::RDocTask.new do |rdoc|
version = File.exist?('VERSION') ? File.read('VERSION') : ""
rdoc.rdoc_dir = 'rdoc'
rdoc.title = "noprocast #{version}"
rdoc.title = "noprocrast #{version}"
rdoc.rdoc_files.include('README*')
rdoc.rdoc_files.include('lib/**/*.rb')
end

View File

@ -1,29 +0,0 @@
#!/usr/bin/env ruby
require File.join(File.expand_path(File.dirname(__FILE__)), '..', 'lib', 'noprocast')
begin
case ARGV.first
when 'on', 'reload'
Noprocast.activate!
when 'off'
Noprocast.deactivate!
when 'status'
puts Noprocast.status_message
when 'edit'
if File.exists?(Noprocast.deny_file_path) && (Process.uid != File.stat(Noprocast.deny_file_path).uid)
puts "Can't edit this file as it belongs to another user (hint: don't use sudo)"
exit
end
Noprocast.edit!
if Noprocast.active?
puts "Saved. Now: noprocast reload"
else
puts "Saved. Now: noprocast on"
end
when 'help', '-h', '--help', nil
puts "Usage: [sudo] noprocast [on|off|status|edit]"
end
rescue Errno::EACCES
puts "Permission denied: try sudo noprocast"
end

29
bin/noprocrast Normal file
View File

@ -0,0 +1,29 @@
#!/usr/bin/env ruby
require File.join(File.expand_path(File.dirname(__FILE__)), '..', 'lib', 'noprocrast')
begin
case ARGV.first
when 'on', 'reload'
Noprocrast.activate!
when 'off'
Noprocrast.deactivate!
when 'status'
puts Noprocrast.status_message
when 'edit'
if File.exists?(Noprocrast.deny_file_path) && (Process.uid != File.stat(Noprocrast.deny_file_path).uid)
puts "Can't edit this file as it belongs to another user (hint: don't use sudo)"
exit
end
Noprocrast.edit!
if Noprocrast.active?
puts "Saved. Now: noprocrast reload"
else
puts "Saved. Now: noprocrast on"
end
when 'help', '-h', '--help', nil
puts "Usage: [sudo] noprocrast [on|off|status|edit]"
end
rescue Errno::EACCES
puts "Permission denied: try sudo noprocrast"
end

View File

@ -1,6 +1,6 @@
require 'fileutils'
class Noprocast
class Noprocrast
class << self
def default_hosts
['news.ycombinator.com', 'twitter.com', 'facebook.com', 'reddit.com']
@ -23,29 +23,29 @@ class Noprocast
backup_hosts_file_if_required!
deactivate! # ensure that /etc/hosts is clean
File.open("/etc/hosts", 'a') do |file|
file << "\n\n# noprocast start\n#{current_hosts.map { |host| "127.0.0.1 #{host}" }.join("\n")}\n# noprocast end"
file << "\n\n# noprocrast start\n#{current_hosts.map { |host| "127.0.0.1 #{host}" }.join("\n")}\n# noprocrast end"
end
system "dscacheutil -flushcache" # only for OSX >= 10.5: flush the DNS cache
end
def deactivate!
clean_hosts = hosts_file_content.gsub(/(\n\n)?\# noprocast start.*\# noprocast end/m, '')
clean_hosts = hosts_file_content.gsub(/(\n\n)?\# noprocrast start.*\# noprocrast end/m, '')
File.open("/etc/hosts", 'w') do |file|
file << clean_hosts
end
end
def active?
hosts_file_content.match(/\# noprocast start/)
hosts_file_content.match(/\# noprocrast start/)
end
def status_message
active? ? "noprocast enabled for #{current_hosts.size} hosts" : "noprocast disabled"
active? ? "noprocrast enabled for #{current_hosts.size} hosts" : "noprocrast disabled"
end
def backup_hosts_file_if_required!
unless File.exists?("/etc/.hosts.noprocastbackup")
FileUtils.cp("/etc/hosts", "/etc/.hosts.noprocastbackup")
unless File.exists?("/etc/.hosts.noprocrastbackup")
FileUtils.cp("/etc/hosts", "/etc/.hosts.noprocrastbackup")
end
end

View File

@ -4,16 +4,16 @@
# -*- encoding: utf-8 -*-
Gem::Specification.new do |s|
s.name = %q{noprocast}
s.version = "0.1.4"
s.name = %q{noprocrast}
s.version = "0.1.6"
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["Rob Watson"]
s.date = %q{2010-11-11}
s.default_executable = %q{noprocast}
s.default_executable = %q{noprocrast}
s.description = %q{Block access to addictive websites in one command-line swoop.}
s.email = %q{rfwatson@gmail.com}
s.executables = ["noprocast"]
s.executables = ["noprocrast"]
s.extra_rdoc_files = [
"LICENSE",
"README.md"
@ -25,20 +25,20 @@ Gem::Specification.new do |s|
"README.md",
"Rakefile",
"VERSION",
"bin/noprocast",
"lib/noprocast.rb",
"noprocast.gemspec",
"spec/noprocast_spec.rb",
"bin/noprocrast",
"lib/noprocrast.rb",
"noprocrast.gemspec",
"spec/noprocrast_spec.rb",
"spec/spec.opts",
"spec/spec_helper.rb"
]
s.homepage = %q{http://github.com/rfwatson/noprocast}
s.homepage = %q{http://github.com/rfwatson/noprocrast}
s.rdoc_options = ["--charset=UTF-8"]
s.require_paths = ["lib"]
s.rubygems_version = %q{1.3.7}
s.summary = %q{Give procastination a swift kick in the balls.}
s.summary = %q{Give procrastination a swift kick in the balls.}
s.test_files = [
"spec/noprocast_spec.rb",
"spec/noprocrast_spec.rb",
"spec/spec_helper.rb"
]

View File

@ -1,6 +1,6 @@
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
describe "Noprocast" do
describe "Noprocrast" do
it "fails" do
fail "hey buddy, you should probably rename this file and start specing for real"
end

View File

@ -1,6 +1,6 @@
$LOAD_PATH.unshift(File.dirname(__FILE__))
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
require 'noprocast'
require 'noprocrast'
require 'spec'
require 'spec/autorun'