vcs 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,26 @@
1
+ # Copyright:: Copyright (c) 2005 Nicolas Pouillard. All rights reserved.
2
+ # Author:: Nicolas Pouillard <ertai@lrde.epita.fr>.
3
+ # License:: Gnu General Public License.
4
+ # Revision:: $Id: junk.rb 257 2005-09-30 16:43:57Z pouill_n $
5
+
6
+
7
+ class Vcs
8
+
9
+ # This command removes all junk files (by default all files begining with `,').
10
+ # Warning: this command removes some files that may contains some important
11
+ # information. For example during a commit the information that you type is
12
+ # stored in one of these `,files'. So be careful using this command.
13
+ # See the user configuration to customize what is considered a junk file.
14
+ def junk! ( files=[], options={} )
15
+ list!(files, options.merge(:junk => true)) do |path_list|
16
+ path_list.each { |path| logger.info { "Remove #{path}" } }
17
+ if @h.agree('Are you sure? (y/n)', true)
18
+ path_list.each do |path|
19
+ logger.info { "Removing #{path}..." }
20
+ path.rm_f
21
+ end
22
+ end
23
+ end
24
+ end
25
+
26
+ end # class Vcs
@@ -1,16 +1,14 @@
1
- # Author:: Nicolas Pouillard <ertai@lrde.epita.fr>.
2
- # Copyright:: Copyright (c) 2004 LRDE. All rights reserved.
3
- # License:: GNU General Public License (GPL).
4
- # $Id$
1
+ # Author:: Nicolas Pouillard <ertai@lrde.epita.fr>.
2
+ # Copyright:: Copyright (c) 2004, 2005 LRDE. All rights reserved.
3
+ # License:: GNU General Public License (GPL).
4
+ # Revision:: $Id$
5
5
 
6
- require 'vcs/svn'
7
-
8
- class Svn
6
+ class Vcs
9
7
 
10
8
  def last_changed_date! ( *args )
11
- puts info.read[/^Last Changed Date:.*?\(([^)]*)\).*$/, 1]
9
+ puts info(*args).read[/^Last Changed Date:.*?\(([^)]*)\).*$/, 1]
12
10
  end
13
11
 
14
12
  alias_command :date, :last_changed_date
15
13
 
16
- end # class Svn
14
+ end # class Vcs
@@ -0,0 +1,71 @@
1
+ # Author:: Nicolas Pouillard <ertai@lrde.epita.fr>.
2
+ # Copyright:: Copyright (c) 2005 LRDE. All rights reserved.
3
+ # License:: Gnu General Public License.
4
+ # Revision:: $Id: list.rb 264 2005-10-03 12:32:51Z pouill_n $
5
+
6
+ require 'vcs/svn'
7
+
8
+ class Svn
9
+
10
+ specific_options << '--do ACTION'
11
+ Vcs.categories.each do |name|
12
+ specific_options << "--#{name}"
13
+ end
14
+
15
+ def list! ( files=[], options={}, &block )
16
+ if options.has_key?(:do) or block \
17
+ or Vcs.categories.any? { |cat| options.has_key?(cat) }
18
+
19
+ action = options[:do]
20
+ options.delete(:do)
21
+ categories = []
22
+ Vcs.categories.each do |cat|
23
+ if options.has_key? cat
24
+ categories << cat
25
+ options.delete(cat)
26
+ end
27
+ end
28
+ inside_versioned = []
29
+ outside_versioned = []
30
+ if categories.empty?
31
+ list_(files, options).output.read.each do |line|
32
+ inside_versioned << line.chomp
33
+ end
34
+ else
35
+ files << '.' if files.empty?
36
+ files.each do |file|
37
+ file.to_path.find do |path|
38
+ Find.prune if path.to_s =~ /(\/|^)\.svn$/
39
+ if path.directory?
40
+ if (path/'.svn').exist?
41
+ inside_versioned << path
42
+ else
43
+ outside_versioned << path
44
+ Find.prune
45
+ end
46
+ else
47
+ outside_versioned << path
48
+ end
49
+ end
50
+ end
51
+ end
52
+ path_list = PathList.new
53
+ status(inside_versioned) do |se|
54
+ path_list << se.file if categories.include? se.category
55
+ end
56
+ outside_versioned.each do |path|
57
+ path_list << path if categories.include? Vcs.classify(path)
58
+ end
59
+ if action
60
+ system "#{action} #{path_list}"
61
+ elsif block
62
+ block[path_list]
63
+ else
64
+ puts path_list
65
+ end
66
+ else
67
+ list_!(files, options)
68
+ end
69
+ end
70
+
71
+ end # class Svn
@@ -1,5 +1,5 @@
1
1
  # Author:: Nicolas Pouillard <ertai@lrde.epita.fr>.
2
- # Copyright:: Copyright (c) 2004 LRDE. All rights reserved.
2
+ # Copyright:: Copyright (c) 2004, 2005 LRDE. All rights reserved.
3
3
  # License:: GNU General Public License (GPL).
4
4
  # Revision:: $Id: header 98 2004-09-29 12:07:43Z ertai $
5
5
 
@@ -8,41 +8,46 @@ require 'sendmail'
8
8
 
9
9
  class Vcs
10
10
 
11
- MAIL = Sendmail::MAIL_FILE
12
- MAILER = Sendmail.new
13
- DEFAULT_OPTIONS = %w[ --confirm --sign --mime ]
11
+ MAIL = Sendmail::MAIL_FILE unless defined? MAIL
12
+ @@mailer ||= Sendmail.new
13
+ @@default_options ||= { :confirm => true, :mime => true,
14
+ :header => "X-Mailer: Vcs.mail (#{Vcs.version})" }
14
15
 
15
16
  #
16
17
  # Mail.
17
18
  #
18
- def mail! ( *args )
19
+ # FIXME handle options properly.
20
+ # Delegate the option parsing to Sendmail.
21
+ def mail! ( files=[], options={} )
22
+
23
+ # Backward compatiblity
24
+ files, options = [], files if files.is_a? Hash
25
+
19
26
  error_handling :mail_failed
20
27
  unless MAIL.exist?
21
- print_body(MAIL, MAILER.parse_mail_options(*(DEFAULT_OPTIONS + args)))
28
+ options = @@default_options.merge(options)
29
+ options[:signed] = Vcs.user_conf.sign
30
+ print_body(MAIL, @@mailer.parse_mail_options(options), files)
22
31
  end
23
- MAILER.sendmail
24
- MAIL.delete
32
+ @@mailer.sendmail
25
33
  puts 'Mail: Sent.'
26
34
  end
27
35
 
28
36
  def mail_failed
29
- if defined? MAIL and MAIL.exist?
30
- LOG.info "#{MAIL}: Contains the generated mail " +
31
- "(generated from #{@@message})"
37
+ if defined? @@mail and @@mail.exist?
38
+ logger.info { "#{MAIL}: Contains the generated mail" }
39
+ logger.info { " AND information to send it (smtpserver, port...)" }
32
40
  end
33
41
  end
34
42
 
35
43
  def mail_conf_checker
36
- %w[ EMAIL FULLNAME SMTPSERVER ].each do |var|
37
- if ENV[var].nil? or ENV[var].empty?
38
- LOG.error "environment variable `#{var}' not set"
44
+ if Vcs.user_conf.sign
45
+ unless `gpg --version` =~ /^gpg \(GnuPG\)/
46
+ logger.error 'mail: gunpg is required'
47
+ end
48
+ unless File.exist?("#{ENV['HOME']}/.gnupg/secring.gpg")
49
+ logger.error 'no private key: in your ~/.gnupg'
39
50
  end
40
- end
41
- unless `gpg --version` =~ /^gpg \(GnuPG\)/
42
- LOG.error 'command not found: gpg'
43
- end
44
- unless File.exist?("#{ENV['HOME']}/.gnupg/secring.gpg")
45
- LOG.error 'no private key: in your ~/.gnupg'
46
51
  end
47
52
  end
48
53
 
@@ -1,79 +1,49 @@
1
- # Author:: Nicolas Pouillard <ertai@lrde.epita.fr>.
2
- # Copyright:: Copyright (c) 2004 LRDE. All rights reserved.
3
- # License:: GNU General Public License (GPL).
4
-
5
- # $LastChangedBy: ertai $
6
- # $Id: header 98 2004-09-29 12:07:43Z ertai $
7
-
8
- require 'vcs/vcs'
9
- require 'vcs/changelog'
10
-
11
- class Vcs
12
- def diffw! ( *args )
13
- diff!(*args)
14
- end
15
- end
16
-
17
- class Svn
18
- def diffw! ( *args )
19
- diff! '--diff-cmd', 'diff', '-x', '-NPbuw', *args
20
- end
21
- end
1
+ # Author:: Nicolas Pouillard <ertai@lrde.epita.fr>.
2
+ # Copyright:: Copyright (c) 2004, 2005 LRDE. All rights reserved.
3
+ # License:: GNU General Public License (GPL).
4
+ # Revision:: $Id: header 98 2004-09-29 12:07:43Z ertai $
22
5
 
23
6
  class Vcs
24
7
 
25
- @@message = Pathname.new(',message')
26
-
27
- def print_body ( file, options )
28
- LOG.info "Creating a new `#{file}' file"
8
+ def print_body ( file, options, files=[] )
9
+ logger.info "Creating a new `#{file}' file"
29
10
  file.open('w') do |f|
30
- f.puts options.to_yaml
11
+ f.puts '---'
12
+ f.puts options.to_yaml.gsub(/---\s*/, '')
31
13
  f.puts '---'
32
14
  f.puts
33
- f.print message.read
15
+ with(f).mk_message!(files)
34
16
  end
35
17
  end
36
18
  private :print_body
37
19
 
38
- def message ( *args )
39
- error_handling :message_failed
40
20
 
41
- unless @@message.exist?
42
- cl_entry = mkchangelog(*args)
43
- TempPath.new('message') do |tmp|
44
- tmp.open('w') do |f|
45
- with(f).url!
46
- if defined? COLLABOA
47
- f.puts
48
- f.puts 'You can also view this changeset here:'
49
- f.puts
50
- next_rev = rev.output.read.to_i
51
- next_rev += 1 unless ',commited'.to_path.exist?
52
- f.puts "http://#{COLLABOA}/repository/changesets/#{next_rev}"
53
- end
54
- f.puts
55
- f.puts 'Index: ChangeLog'
56
- f.print cl_entry.sub(/^\d+-\d+-\d+/, 'from')
57
- f.puts
58
- with(f).diffstat!(*args)
59
- f.puts
60
- diffw_from_status(*args).each_line do |line|
61
- f.print line if line !~ /^=+$/
62
- end
63
- end
64
- tmp.mv(@@message)
21
+ def mk_message! ( files=[], options={} )
22
+ with_cache! Message, 'generated message (ChangeLog, diffstat, diff)' do
23
+ url!
24
+ if defined? COLLABOA
25
+ puts
26
+ puts 'You can also view this changeset here:'
27
+ puts
28
+ next_rev = rev.output.read.to_i
29
+ next_rev += 1 unless commited?
30
+ puts "http://#{COLLABOA}/repository/changesets/#{next_rev}"
31
+ end
32
+ puts
33
+ flush
34
+ mk_message_entry!(files)
35
+ puts
36
+ flush
37
+ diffstat!(files)
38
+ puts
39
+ flush
40
+ diffw(files).each_line do |line|
41
+ print line if line !~ /^=+$/
65
42
  end
66
43
  end
67
- @@message.open('r')
68
44
  end
45
+ alias_command :msg, :mk_message
46
+ Message = ',message'.to_path unless defined? Message
69
47
 
70
- alias_command :msg, :message
71
-
72
- def message_failed
73
- if @@message.exist?
74
- LOG.info "#{@@message}: Contains the generated message"
75
- LOG.info ' (the ChangeLog entry, the diffstat, the diff)'
76
- end
77
- end
78
48
 
79
49
  end # class Vcs
@@ -5,20 +5,19 @@
5
5
  # $LastChangedBy: ertai $
6
6
  # $Id: header 98 2004-09-29 12:07:43Z ertai $
7
7
 
8
- require 'vcs/tools'
9
8
  require 'vcs/message'
10
9
 
11
10
  class Vcs
12
11
 
13
- NEWS = Pathname.new(',news')
12
+ NEWS = ',news'.to_path unless defined? NEWS
14
13
 
15
14
  def parse_news_options ( *args )
16
15
  require 'optparse'
17
16
  result =
18
17
  {
19
- :from => FULL_EMAIL,
18
+ :from => Vcs.full_email,
20
19
  :groups => [],
21
- :server => ENV['NNTPSERVER'],
20
+ :server => Vcs.nntpserver,
22
21
  }
23
22
  if !args.nil? and !args.empty? and args[0].is_a?(Hash)
24
23
  return result.merge!(args[0])
@@ -48,9 +47,9 @@ class Vcs
48
47
 
49
48
  def check_line ( anIO, aRegex )
50
49
  line = anIO.readline.chomp!
51
- LOG.debug('news') { "Server: #{line}" }
50
+ logger.debug('news') { "Server: #{line}" }
52
51
  unless line =~ aRegex
53
- LOG.error('news') { "Bad answer: #{line}" }
52
+ logger.error('news') { "Bad answer: #{line}" }
54
53
  @news_status = 'Error.'
55
54
  end
56
55
  end
@@ -69,11 +68,11 @@ class Vcs
69
68
  opt = YAML::chop_header(file)
70
69
  server, port = opt[:server].split(/:/)
71
70
  port ||= 119
72
- LOG.info('news') { "Nntp Server: #{server}:#{port}" }
71
+ logger.info('news') { "Nntp Server: #{server}:#{port}" }
73
72
  unless @h.agree("Post a news, with this subject: #{opt[:subject]}\n" +
74
73
  " to #{opt[:groups].join(', ')}\n from #{opt[:from]}\n" +
75
74
  'Are you sure? (y/n)', true)
76
- LOG.error('news') { 'Aborting' }
75
+ logger.error('news') { 'Aborting' }
77
76
  exit
78
77
  end
79
78
  require 'socket'
@@ -100,7 +99,7 @@ class Vcs
100
99
 
101
100
  def news_failed
102
101
  if defined? NEWS and NEWS.exist?
103
- LOG.info "#{NEWS}: Contains the generated news" +
102
+ logger.info "#{NEWS}: Contains the generated news" +
104
103
  "(generated from #{@@message})"
105
104
  end
106
105
  end
@@ -108,7 +107,7 @@ class Vcs
108
107
  def news_conf_checker
109
108
  %w[ NNTPSERVER ].each do |var|
110
109
  if ENV[var].nil? or ENV[var].empty?
111
- LOG.error "environment variable `#{var}' not set"
110
+ logger.error "environment variable `#{var}' not set"
112
111
  end
113
112
  end
114
113
  end
@@ -0,0 +1,82 @@
1
+ # Author:: Nicolas Pouillard <ertai@lrde.epita.fr>.
2
+ # Copyright:: Copyright (c) 2005 LRDE. All rights reserved.
3
+ # License:: GNU General Public License (GPL).
4
+ # Revision:: $Id: opt_parse.rb 242 2005-09-28 14:19:47Z pouill_n $
5
+
6
+
7
+ class Vcs
8
+
9
+ class OptParse
10
+
11
+ attr_reader :option_parser
12
+
13
+ def initialize
14
+ @option_parser = @@option_parser.dup
15
+ end
16
+
17
+ def parse! ( argv )
18
+ @option_parser.parse! argv
19
+ end
20
+
21
+ def parse ( argv )
22
+ @option_parser.parse argv
23
+ end
24
+
25
+ def to_s
26
+ @option_parser.to_s
27
+ end
28
+
29
+ @@option_parser = OptionParser.new do |o|
30
+
31
+ o.banner = "Usage: vcs [options] <file>*"
32
+ o.separator ''
33
+
34
+ o.on('-c', '--vcs TYPE', VcsApp.all_vcs, 'Set your vcs') do |aVcs|
35
+ Vcs.default = aVcs
36
+ end
37
+
38
+ o.on('-l', '--vcs-list', 'List all vcs') do |aVcs|
39
+ STDERR.puts 'Vcs list:'
40
+ VcsApp.all_vcs.each { |n| STDERR.puts " - #{n}" }
41
+ exit
42
+ end
43
+
44
+ o.on('--mk-alias', 'Put the result of this command in your .zshrc or .bashrc') do
45
+ VcsApp.all_vcs.each do |n|
46
+ n = n.to_s.downcase
47
+ if VcsApp.path.executable?
48
+ puts "alias #{n}=#{VcsApp.path}-#{n} ;"
49
+ else
50
+ puts "alias #{n}=vcs-#{n} ;"
51
+ end
52
+ end
53
+ exit
54
+ end
55
+
56
+ o.on('-C', '--[no-]check', 'Check your vcs configuration') do |check|
57
+ if check
58
+ Vcs.new('vcs').call_conf_checkers
59
+ exit
60
+ end
61
+ end
62
+
63
+ o.on('-d', '--debug LEVEL', 'Set debug level') do |severity|
64
+ logger.level = Logger.const_get(severity.upcase)
65
+ end
66
+
67
+ o.on_tail('-h', '--help', 'Show this message') do |test|
68
+ STDERR.puts o
69
+ STDERR.puts "\n\nReport bugs to <ertai@lrde.epita.fr>."
70
+ exit
71
+ end
72
+
73
+ o.on_tail('--version', 'Show version') do
74
+ STDOUT.puts "Vcs version: #{Vcs.version}"
75
+ exit
76
+ end
77
+
78
+ end
79
+
80
+ end # class OptParse
81
+
82
+ end # class Vcs