Class: Slackware::Repo

Inherits:
Object
  • Object
show all
Defined in:
lib/slackware/repo.rb

Overview

Stub

Constant Summary collapse

RE_PACKAGE_NAME =
/^PACKAGE NAME:\s+(.*)\.t[gbx]z\s*/
RE_PACKAGE_LOCATION =
/^PACKAGE LOCATION:\s+(.*)$/
RE_COMPRESSED_SIZE =
/^PACKAGE SIZE \(compressed\):\s+(.*)$/
RE_UNCOMPRESSED_SIZE =
/^PACKAGE SIZE \(uncompressed\):\s+(.*)$/

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(repo = nil) ⇒ Repo

Returns a new instance of Repo.



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/slackware/repo.rb', line 43

def initialize(repo = nil)
  @packages = nil
  if (repo.nil?)
    self.proto  = "ftp://"
    self.mirror  = "ftp.osuosl.org"
    self.path  = "/pub/slackware/"
    self.version  = begin 
            v = Slackware::System.version
            if v =~ /(\d+)\.(\d+)\.\d+/
              v = $1 + "." + $2
            end
            v
          end
    self.arch  = begin
            a = RbConfig::CONFIG["arch"]
            if a =~ /x86_64/
              a = "64"
            else
              a = ""
            end
            a
          end
  else
    ## TODO do some hot parsing of 'repo'
  end
end

Instance Attribute Details

#archObject

Returns the value of attribute arch.



41
42
43
# File 'lib/slackware/repo.rb', line 41

def arch
  @arch
end

#changelogObject

Returns the value of attribute changelog.



41
42
43
# File 'lib/slackware/repo.rb', line 41

def changelog
  @changelog
end

#mirrorObject

Returns the value of attribute mirror.



41
42
43
# File 'lib/slackware/repo.rb', line 41

def mirror
  @mirror
end

#packagesObject

Returns the value of attribute packages.



41
42
43
# File 'lib/slackware/repo.rb', line 41

def packages
  @packages
end

#pathObject

Returns the value of attribute path.



41
42
43
# File 'lib/slackware/repo.rb', line 41

def path
  @path
end

#protoObject

Returns the value of attribute proto.



41
42
43
# File 'lib/slackware/repo.rb', line 41

def proto
  @proto
end

#versionObject

Returns the value of attribute version.



41
42
43
# File 'lib/slackware/repo.rb', line 41

def version
  @version
end

Instance Method Details

#fetch(file = nil) ⇒ Object



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/slackware/repo.rb', line 70

def fetch(file = nil)
  #if file.nil?
    #url = URI.parse(self.proto + self.mirror + self.path)
  #else
    #url = URI.parse(self.proto + self.mirror + self.path + file)
  #end
  if self.proto =~ /ftp/
    ftp = Net::FTP.open(self.mirror)
    ftp.
    ftp.chdir(self.path + "slackware" + self.arch + "-" + self.version)
    if (file.nil?)
      data = ftp.list('*')
    else
      data = ftp.get(file, nil)
    end
    ftp.close
    return data
  elsif self.proto =~ /http/
    # XXX this is not working yet
    req = Net::HTTP::Get.new(url.path)
    res = Net::HTTP.start(url.host, url.port) {|http| http.request(req) }
    return res
  elsif self.proto =~ /file/
    if (file.nil?)
      return Dir.glob(self.path + "slackware" + self.arch + "-" + self.version + "/*")
    else
      return File.read(self.path + "slackware" + self.arch + "-" + self.version + "/" + file)
    end
  else
    return nil
  end
end

#get_changelogObject

Pkg count that should be removed pkgs = Slackware::System.installed_packages sr = Slackware::Repo.new sr.version = “current” c = get_changelog (pkgs.map {|p| p.fullname } & c.map {|p| p.fullname }).count



109
110
111
112
113
114
115
116
117
# File 'lib/slackware/repo.rb', line 109

def get_changelog
  if (@changelog.nil?)
    changelog = {}
    changelog_data = fetch("ChangeLog.txt")
    return changelog
  else
    return @changelog
  end
end

#get_packagesObject



124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
# File 'lib/slackware/repo.rb', line 124

def get_packages
  if (@packages.nil?)
    pkgs = []
    fetch("PACKAGES.TXT").split(/\n\n/).each {|p_block|
      p_block = p_block.split(/\n/).reject {|cell| cell if cell == "" }
      if (p_block.shift =~ RE_PACKAGE_NAME)
        pkg = Slackware::Package.parse($1)

        p_block.shift =~ RE_PACKAGE_LOCATION
        pkg.package_location = $1

        p_block.shift =~ RE_COMPRESSED_SIZE
        pkg.compressed_size = $1

        p_block.shift =~ RE_UNCOMPRESSED_SIZE
        pkg.uncompressed_size = $1

        # This is the empty PACKAGE DESCRIPTON: tag
        p_block.shift

        pkg.package_description = p_block.map {|cell|
          cell.sub(/^#{pkg.name}:\s*/, '')
        }

        pkgs << pkg
      end
    }
    return pkgs
  else
    return @packages
  end
end

#set_changelogObject



119
120
121
122
# File 'lib/slackware/repo.rb', line 119

def set_changelog
  @changelog = get_changelog
  return nil
end

#set_packagesObject



157
158
159
160
# File 'lib/slackware/repo.rb', line 157

def set_packages
  @packages = get_packages
  return @packages.count
end