]> git.ipfire.org Git - pakfire.git/blame - pakfire/packages/make.py
Add code, that actually runs scriptlets.
[pakfire.git] / pakfire / packages / make.py
CommitLineData
47a4cb89 1#!/usr/bin/python
b792d887
MT
2###############################################################################
3# #
4# Pakfire - The IPFire package management system #
5# Copyright (C) 2011 Pakfire development team #
6# #
7# This program is free software: you can redistribute it and/or modify #
8# it under the terms of the GNU General Public License as published by #
9# the Free Software Foundation, either version 3 of the License, or #
10# (at your option) any later version. #
11# #
12# This program is distributed in the hope that it will be useful, #
13# but WITHOUT ANY WARRANTY; without even the implied warranty of #
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
15# GNU General Public License for more details. #
16# #
17# You should have received a copy of the GNU General Public License #
18# along with this program. If not, see <http://www.gnu.org/licenses/>. #
19# #
20###############################################################################
47a4cb89
MT
21
22import os
23import tarfile
24
25from urlgrabber.grabber import URLGrabber, URLGrabError
26from urlgrabber.progress import TextMeter
27
28import packager
29
30from base import Package
31from source import SourcePackage
32from virtual import VirtualPackage
33from pakfire.errors import DownloadError
34from pakfire.constants import *
35
36class SourceDownloader(object):
37 def __init__(self, pakfire):
38 self.pakfire = pakfire
39
80104a80 40 # XXX need to use downloader.py
47a4cb89
MT
41 self.grabber = URLGrabber(
42 prefix = self.pakfire.config.get("source_download_url"),
43 progress_obj = TextMeter(),
44 quote = 0,
45 )
46
47 def download(self, filename):
48 filename = os.path.join(SOURCE_CACHE_DIR, filename)
49
50 if os.path.exists(filename):
51 return filename
52
53 dirname = os.path.dirname(filename)
54 if not os.path.exists(dirname):
55 os.makedirs(dirname)
56
57 try:
58 self.grabber.urlgrab(os.path.basename(filename), filename=filename)
59 except URLGrabError, e:
60 raise DownloadError, "%s %s" % (os.path.basename(filename), e)
61
62 return filename
63
64
d507be4d
MT
65class MakeVirtualPackage(VirtualPackage):
66 """
67 A simple package that always overwrites the file_patterns.
68 """
69 @property
70 def file_patterns(self):
71 """
72 All files that belong into a source package are located in /build.
73 """
74 return ["/",]
75
47a4cb89 76class Makefile(Package):
3723913b 77 def __init__(self, pakfire, filename):
a2d1644c 78 Package.__init__(self, pakfire)
440cede8 79 self.filename = os.path.abspath(filename)
3723913b 80
47a4cb89
MT
81 @property
82 def files(self):
83 basedir = os.path.dirname(self.filename)
84
85 for dirs, subdirs, files in os.walk(basedir):
86 for f in files:
87 yield os.path.join(dirs, f)
88
89 def extract(self, env):
90 # Copy all files that belong to the package
91 for f in self.files:
92 _f = f[len(os.path.dirname(self.filename)):]
93 env.copyin(f, "/build/%s" % _f)
94
95 downloader = SourceDownloader(env.pakfire)
96 for filename in env.make_sources():
97 _filename = downloader.download(filename)
98
99 if _filename:
100 env.copyin(_filename, "/build/files/%s" % os.path.basename(_filename))
101
102 @property
103 def package_filename(self):
104 return PACKAGE_FILENAME_FMT % {
105 "arch" : self.arch,
106 "ext" : PACKAGE_EXTENSION,
107 "name" : self.name,
108 "release" : self.release,
109 "version" : self.version,
110 }
111
112 @property
113 def arch(self):
114 """
115 This is only used to create the name of the source package.
116 """
117 return "src"
118
119 def dist(self, env):
120 """
121 Create a source package in env.
122
123 We assume that all requires files are in /build.
124 """
d507be4d 125 pkg = MakeVirtualPackage(self.pakfire, env.make_info)
47a4cb89 126
d507be4d
MT
127 p = packager.SourcePackager(self.pakfire, pkg, env)
128 p()
47a4cb89 129