aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Brett Witherspoon <spoonb@exherbo.org> 2011-02-23 21:29:02 +0000
committerAvatar Brett Witherspoon <spoonb@exherbo.org> 2011-02-23 21:29:02 +0000
commit1b790bc1931db2c523799b67a3a2a1b43f502c27 (patch)
tree074466b981f12208189e2a70a390d44c5a27d5cb
parenta38d92be00f0ae5b8d6dd1df332e2a19ce868894 (diff)
downloaddexter-1b790bc1931db2c523799b67a3a2a1b43f502c27.tar.gz
dexter-1b790bc1931db2c523799b67a3a2a1b43f502c27.tar.xz
dexter: disambiguate package names
-rwxr-xr-xdexter.rb84
1 files changed, 31 insertions, 53 deletions
diff --git a/dexter.rb b/dexter.rb
index b64962f..07afc18 100755
--- a/dexter.rb
+++ b/dexter.rb
@@ -114,16 +114,17 @@ end
class Victim
attr_reader :qpn
- def initialize(env, qpn, repo)
+ def initialize(env, spec)
@env = env
- @qpn = qpn
- @repo = repo
+ @spec = spec
+ @qpn = spec.package
+ @repo = nil
@is_repo = false
@is_pkg = false
end
def repo
- return @repo.name
+ return @repo.nil? ? nil : @repo.name
end
def is_repo?
@@ -137,11 +138,11 @@ class Victim
protected
def bury_single(qpn)
- commit_id = ""
- user_name = "#{`git config --get user.name`.strip} " + "<#{`git config --get user.email`.strip}>"
- homepage = "[no homepage available]"
- desc = "[no description available]"
- grave = ""
+ commit_id = ""
+ user_name = "#{`git config --get user.name`.strip} " + "<#{`git config --get user.email`.strip}>"
+ homepage = "[no homepage available]"
+ desc = "[no description available]"
+ grave = ""
if self.is_pkg? and File.directory?(@location + "/packages")
Dir.chdir(@location + "/packages") unless Dir.pwd == @location + "/packages"
@@ -195,33 +196,26 @@ protected
end
class Victim::Package < Victim
- def initialize(env, qpn, repo, location, comment="")
- super(env, qpn, repo)
- pkg_sanity_check
- @comment = comment
- @location = location
- @is_repo = false
- @is_pkg = true
+ def initialize(env, spec, repo_dir, comment=nil)
+ super(env, spec)
+ @repo = env.package_database.fetch_repository(spec.in_repository)
+ @comment = comment
+ @location = repo_dir + "/" + @repo.name
+ @is_repo = false
+ @is_pkg = true
end
def bury
return self.bury_single(@qpn)
end
-
- protected
-
- def pkg_sanity_check
- unless @repo.has_package_named?(@qpn)
- error "Package \'#{@qpn}\' doesn't exist in repository \'#{@repo.name}\'"
- end
- end
end
class Victim::Repository < Victim
- def initialize(env, qpn, repo)
- super(env, qpn, repo)
+ def initialize(env, spec)
+ super(env, spec)
+ @repo = env.package_database.fetch_repository(spec.package.package)
@is_repo = true
- @is_pkg = false
+ @is_pkg = false
end
def bury
@@ -249,7 +243,7 @@ options = GetoptLong.new(
graveyard_dir = Dir.pwd
repo_dir = nil
targets = []
-comment = ""
+comment = nil
envspec = ""
options.each do | opt, arg |
@@ -264,16 +258,6 @@ options.each do | opt, arg |
puts " --repository-dir, -r Path to the repository directory"
puts " --comment, -c A comment to include for all targets"
puts
- puts " Arguements should be given in the format:"
- puts
- puts " CATEGORY/PACKAGE::REPOSITORY or repository/NAME"
- puts
- puts " When the path to the graveyard is not specified the current working"
- puts " directory is used"
- puts
- puts " If you bury individual packages you must give the path to the repository"
- puts " from which to get a commit-id."
- puts
exit 0
when '--log-level'
@@ -307,23 +291,17 @@ error "#{graveyard_dir} is not writeable" unless File.writable?(graveyard_dir)
env = Paludis::EnvironmentFactory.instance.create(envspec)
-ARGV.each do |target|
+ARGV.each do |arg|
begin
- case target
- when /([-\w]+\/[-\w]+)::([-\w]+)/
- error "The --repository-dir option is required." if repo_dir.nil?
- qpn = Paludis::QualifiedPackageName.new($1)
- repo = env.package_database.fetch_repository($2)
- location = repo_dir + "/" + repo.name
- targets << Victim::Package.new(env, qpn, repo, location, comment)
- when /repository\/([-\w]+)/
- qpn = Paludis::QualifiedPackageName.new("repository/" + $1)
- repo = env.package_database.fetch_repository($1)
- targets << Victim::Repository.new(env, qpn, repo)
- else
- error "Invalid package name \"#{target}\". Try --help"
+ spec = Paludis::parse_user_package_dep_spec(arg, env, [:throw_if_set])
+ if spec.package.category == "repository"
+ targets << Victim::Repository.new(env, spec)
+ else
+ error "The --repository-dir option is required when burying packages." if repo_dir.nil?
+ error "A repository spec must be given when burying packages." if spec.in_repository.nil?
+ targets << Victim::Package.new(env, spec, repo_dir, comment)
end
- rescue Paludis::NoSuchRepositoryError
+ rescue
error $!
end
end