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/>.
31 Object holding data from an ArchLinux package.
34 def __init__(self
, name
, version
= "1.0-1"):
35 self
.path
= "" #the path of the generated package
38 self
.version
= version
50 self
.md5sum
= "" # sync only
51 self
.replaces
= [] # sync only (will be moved to depends)
52 self
.force
= 0 # sync only (will be moved to depends)
84 s
= ["%s" % self
.fullname()]
85 s
.append("description: %s" % self
.desc
)
86 s
.append("url: %s" % self
.url
)
87 s
.append("depends: %s" % " ".join(self
.depends
))
88 s
.append("files: %s" % " ".join(self
.files
))
89 s
.append("reason: %d" % self
.reason
)
93 """Long name of a package.
95 Returns a string formatted as follows: "pkgname-pkgver".
97 return "%s-%s" % (self
.name
, self
.version
)
100 """File name of a package, including its extension.
102 Returns a string formatted as follows: "pkgname-pkgver.PKG_EXT_PKG".
104 return "%s%s" % (self
.fullname(), PM_EXT_PKG
)
106 def install_files(self
, root
):
107 """Install files in the filesystem located under "root".
109 Files are created with content generated automatically.
111 [mkfile(os
.path
.join(root
, f
), f
) for f
in self
.files
]
113 def makepkg(self
, path
):
114 """Creates an ArchLinux package archive.
116 A package archive is generated in the location 'path', based on the data
119 self
.path
= os
.path
.join(path
, self
.filename())
122 tmpdir
= tempfile
.mkdtemp()
125 # Generate package file system
128 self
.size
+= os
.stat(getfilename(f
))[stat
.ST_SIZE
]
131 data
= ["pkgname = %s" % self
.name
]
132 data
.append("pkgver = %s" % self
.version
)
133 data
.append("pkgdesc = %s" % self
.desc
)
134 data
.append("url = %s" % self
.url
)
135 data
.append("builddate = %s" % self
.builddate
)
136 data
.append("packager = %s" % self
.packager
)
137 data
.append("size = %s" % self
.size
)
139 data
.append("arch = %s" % self
.arch
)
140 for i
in self
.license
:
141 data
.append("license = %s" % i
)
142 for i
in self
.replaces
:
143 data
.append("replaces = %s" % i
)
144 for i
in self
.groups
:
145 data
.append("group = %s" % i
)
146 for i
in self
.depends
:
147 data
.append("depend = %s" % i
)
148 for i
in self
.optdepends
:
149 data
.append("optdepend = %s" % i
)
150 for i
in self
.conflicts
:
151 data
.append("conflict = %s" % i
)
152 for i
in self
.provides
:
153 data
.append("provides = %s" % i
)
154 for i
in self
.backup
:
155 data
.append("backup = %s" % i
)
156 mkfile(".PKGINFO", "\n".join(data
))
159 if len(self
.install
.values()) > 0:
160 mkinstallfile(".INSTALL", self
.install
)
162 # safely create the dir
163 mkdir(os
.path
.dirname(self
.path
))
165 # Generate package archive
166 tar
= tarfile
.open(self
.path
, "w:gz")
169 for root
, dirs
, files
in os
.walk('.'):
171 tar
.add(os
.path
.join(root
, d
), recursive
=False)
173 tar
.add(os
.path
.join(root
, f
))
178 shutil
.rmtree(tmpdir
)
181 if __name__
== "__main__":
184 # vim: set ts=4 sw=4 et: