3 # Copyright (c) 2006 by Aurelien Foret <orelien@chez.com>
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program. If not, see <http://www.gnu.org/licenses/>.
30 Object holding data from an Arch Linux package.
33 def __init__(self
, name
, version
= "1.0-1"):
34 self
.path
= "" #the path of the generated package
37 self
.version
= version
50 self
.md5sum
= "" # sync only
51 self
.pgpsig
= "" # sync only
71 s
= ["%s" % self
.fullname()]
72 s
.append("description: %s" % self
.desc
)
73 s
.append("url: %s" % self
.url
)
74 s
.append("files: %s" % " ".join(self
.files
))
75 s
.append("reason: %d" % self
.reason
)
79 """Long name of a package.
81 Returns a string formatted as follows: "pkgname-pkgver".
83 return "%s-%s" % (self
.name
, self
.version
)
86 """File name of a package, including its extension.
88 Returns a string formatted as follows: "pkgname-pkgver.PKG_EXT_PKG".
90 return "%s%s" % (self
.fullname(), util
.PM_EXT_PKG
)
93 def parse_filename(name
):
95 if filename
[-1] == "*":
96 filename
= filename
.rstrip("*")
97 if filename
.find(" -> ") != -1:
98 filename
, extra
= filename
.split(" -> ")
99 elif filename
.find("|") != -1:
100 filename
, extra
= filename
.split("|")
103 def makepkg(self
, path
):
104 """Creates an Arch Linux package archive.
106 A package archive is generated in the location 'path', based on the data
109 self
.path
= os
.path
.join(path
, self
.filename())
112 tmpdir
= tempfile
.mkdtemp()
115 # Generate package file system
118 self
.size
+= os
.lstat(self
.parse_filename(f
))[stat
.ST_SIZE
]
121 data
= ["pkgname = %s" % self
.name
]
122 data
.append("pkgver = %s" % self
.version
)
123 data
.append("pkgdesc = %s" % self
.desc
)
124 data
.append("url = %s" % self
.url
)
125 data
.append("builddate = %s" % self
.builddate
)
126 data
.append("packager = %s" % self
.packager
)
127 data
.append("size = %s" % self
.size
)
129 data
.append("arch = %s" % self
.arch
)
130 for i
in self
.license
:
131 data
.append("license = %s" % i
)
132 for i
in self
.replaces
:
133 data
.append("replaces = %s" % i
)
134 for i
in self
.groups
:
135 data
.append("group = %s" % i
)
136 for i
in self
.depends
:
137 data
.append("depend = %s" % i
)
138 for i
in self
.optdepends
:
139 data
.append("optdepend = %s" % i
)
140 for i
in self
.conflicts
:
141 data
.append("conflict = %s" % i
)
142 for i
in self
.provides
:
143 data
.append("provides = %s" % i
)
144 for i
in self
.backup
:
145 data
.append("backup = %s" % i
)
146 util
.mkfile(".PKGINFO", "\n".join(data
))
149 if any(self
.install
.values()):
150 util
.mkinstallfile(".INSTALL", self
.install
)
152 # safely create the dir
153 util
.mkdir(os
.path
.dirname(self
.path
))
155 # Generate package archive
156 tar
= tarfile
.open(self
.path
, "w:gz")
157 for i
in os
.listdir("."):
162 shutil
.rmtree(tmpdir
)
164 def full_filelist(self
):
165 """Generate a list of package files.
167 Each path is decomposed to generate the list of all directories leading
170 Example with 'usr/local/bin/dummy':
171 The resulting list will be:
178 for name
in self
.files
:
179 name
= self
.parse_filename(name
)
182 name
, tmp
= name
.rsplit("/", 1)
183 file_set
.add(name
+ "/")
184 return sorted(file_set
)
186 def local_backup_entries(self
):
187 return ["%s\t%s" % (self
.parse_filename(i
), util
.mkmd5sum(i
)) for i
in self
.backup
]
189 # vim: set ts=4 sw=4 et: