Changeset View
Changeset View
Standalone View
Standalone View
bin/Source/ArchiveSource.py
1 | # | 1 | # | ||
---|---|---|---|---|---|
2 | # copyright (c) 2009 Ralf Habacker <ralf.habacker@freenet.de> | 2 | # copyright (c) 2009 Ralf Habacker <ralf.habacker@freenet.de> | ||
3 | # | 3 | # | ||
4 | 4 | | |||
5 | import shutil | 5 | import shutil | ||
6 | 6 | | |||
7 | import EmergeDebug | 7 | import EmergeDebug | ||
8 | from Source.SourceBase import * | 8 | from Source.SourceBase import * | ||
9 | import EmergeHash | ||||
9 | 10 | | |||
10 | 11 | | |||
11 | class ArchiveSource(SourceBase): | 12 | class ArchiveSource(SourceBase): | ||
12 | """ file download source""" | 13 | """ file download source""" | ||
13 | filenames = [] | 14 | filenames = [] | ||
14 | def __init__(self, subinfo=None): | 15 | def __init__(self, subinfo=None): | ||
15 | EmergeDebug.debug("ArchiveSource.__init__ called", 2) | 16 | EmergeDebug.debug("ArchiveSource.__init__ called", 2) | ||
16 | if subinfo: | 17 | if subinfo: | ||
Show All 24 Lines | 39 | def localFileNamesBase(self): | |||
41 | 42 | | |||
42 | filenames = [] | 43 | filenames = [] | ||
43 | for i in range(self.repositoryUrlCount()): | 44 | for i in range(self.repositoryUrlCount()): | ||
44 | filenames.append( os.path.basename( self.repositoryUrl( i ) ) ) | 45 | filenames.append( os.path.basename( self.repositoryUrl( i ) ) ) | ||
45 | return filenames | 46 | return filenames | ||
46 | 47 | | |||
47 | def __checkFilesPresent(self, filenames): | 48 | def __checkFilesPresent(self, filenames): | ||
48 | """check if all files for the current target are available""" | 49 | """check if all files for the current target are available""" | ||
49 | available = True | | |||
50 | for filename in filenames: | 50 | for filename in filenames: | ||
51 | path = os.path.join(EmergeStandardDirs.downloadDir(), filename) | 51 | path = os.path.join(EmergeStandardDirs.downloadDir(), filename) | ||
52 | if self.subinfo.hasTargetDigests(): | 52 | if self.subinfo.hasTargetDigests(): | ||
53 | if not os.path.exists(path): | 53 | if not os.path.exists(path): | ||
54 | available = False | 54 | return False | ||
55 | elif self.subinfo.hasTargetDigestUrls(): | 55 | elif self.subinfo.hasTargetDigestUrls(): | ||
56 | if not os.path.exists("%s.sha1" % path): | 56 | algorithm = EmergeHash.HashAlgorithm.SHA1 | ||
57 | available = False | 57 | if type(self.subinfo.targetDigestUrl()) == tuple: | ||
58 | _, algorithm = self.subinfo.targetDigestUrl() | ||||
59 | if not os.path.exists(path + algorithm.fileEnding()): | ||||
60 | return False | ||||
58 | elif not os.path.exists(path): | 61 | elif not os.path.exists(path): | ||
59 | available = False | 62 | return False | ||
60 | return available | 63 | return True | ||
61 | 64 | | |||
62 | def fetch( self, dummyRepopath = None ): | 65 | def fetch( self, dummyRepopath = None ): | ||
63 | """fetch normal tarballs""" | 66 | """fetch normal tarballs""" | ||
64 | EmergeDebug.debug("ArchiveSource.fetch called", 2) | 67 | EmergeDebug.debug("ArchiveSource.fetch called", 2) | ||
65 | 68 | | |||
66 | filenames = self.localFileNames() | 69 | filenames = self.localFileNames() | ||
67 | 70 | | |||
68 | if ( self.noFetch ): | 71 | if ( self.noFetch ): | ||
69 | EmergeDebug.debug("skipping fetch (--offline)") | 72 | EmergeDebug.debug("skipping fetch (--offline)") | ||
70 | return True | 73 | return True | ||
71 | 74 | | |||
72 | self.setProxy() | 75 | self.setProxy() | ||
73 | if self.subinfo.hasTarget(): | 76 | if self.subinfo.hasTarget(): | ||
74 | if self.__checkFilesPresent(filenames): | 77 | if self.__checkFilesPresent(filenames): | ||
75 | EmergeDebug.debug("files and digests available, no need to download files", 1) | 78 | EmergeDebug.debug("files and digests available, no need to download files", 1) | ||
76 | return True | 79 | return True | ||
77 | 80 | | |||
78 | result = utils.getFiles( self.subinfo.target(), EmergeStandardDirs.downloadDir() , filenames = self.subinfo.archiveName() ) | 81 | result = utils.getFiles( self.subinfo.target(), EmergeStandardDirs.downloadDir() , filenames = self.subinfo.archiveName() ) | ||
79 | if not result: | 82 | if not result: | ||
80 | EmergeDebug.debug("failed to download files", 1) | 83 | EmergeDebug.debug("failed to download files", 1) | ||
81 | return False | 84 | return False | ||
82 | if result and self.subinfo.hasTargetDigestUrls(): | 85 | if result and self.subinfo.hasTargetDigestUrls(): | ||
83 | if self.subinfo.targetDigestUrl() == "auto": | 86 | if type(self.subinfo.targetDigestUrl()) == tuple: | ||
84 | return utils.getFiles( self.subinfo.target(), EmergeStandardDirs.downloadDir(), ".sha1", self.subinfo.archiveName() ) | 87 | url, alg = self.subinfo.targetDigestUrl() | ||
88 | return utils.getFiles(url, EmergeStandardDirs.downloadDir(), | ||||
89 | filenames = self.subinfo.archiveName() | ||||
90 | + EmergeHash.HashAlgorithm.fileEndings().get(alg)) | ||||
85 | else: | 91 | else: | ||
86 | return utils.getFiles( self.subinfo.targetDigestUrl(), EmergeStandardDirs.downloadDir(), filenames = '' ) | 92 | return utils.getFiles( self.subinfo.targetDigestUrl(), EmergeStandardDirs.downloadDir(), filenames = '' ) | ||
87 | else: | 93 | else: | ||
88 | EmergeDebug.debug("no digestUrls present", 2) | 94 | EmergeDebug.debug("no digestUrls present", 2) | ||
89 | return True | 95 | return True | ||
90 | else: | 96 | else: | ||
91 | return utils.getFiles( "", EmergeStandardDirs.downloadDir() ) | 97 | return utils.getFiles( "", EmergeStandardDirs.downloadDir() ) | ||
92 | 98 | | |||
93 | def checkDigest(self): | 99 | def checkDigest(self): | ||
94 | EmergeDebug.debug("ArchiveSource.checkDigest called", 2) | 100 | EmergeDebug.debug("ArchiveSource.checkDigest called", 2) | ||
95 | filenames = self.localFileNames() | 101 | filenames = self.localFileNames() | ||
96 | 102 | | |||
97 | if self.subinfo.hasTargetDigestUrls(): | 103 | if self.subinfo.hasTargetDigestUrls(): | ||
98 | EmergeDebug.debug("check digests urls", 1) | 104 | EmergeDebug.debug("check digests urls", 1) | ||
99 | if not utils.checkFilesDigests( EmergeStandardDirs.downloadDir(), filenames): | 105 | if not EmergeHash.checkFilesDigests(EmergeStandardDirs.downloadDir(), filenames): | ||
100 | EmergeDebug.error("invalid digest file") | 106 | EmergeDebug.error("invalid digest file") | ||
101 | return False | 107 | return False | ||
102 | elif self.subinfo.hasTargetDigests(): | 108 | elif self.subinfo.hasTargetDigests(): | ||
103 | EmergeDebug.debug("check digests", 1) | 109 | EmergeDebug.debug("check digests", 1) | ||
104 | if not utils.checkFilesDigests( EmergeStandardDirs.downloadDir(), filenames, self.subinfo.targetDigest()): | 110 | digests = self.subinfo.targetDigest() | ||
111 | if type(digests) == tuple: | ||||
112 | digests, algorithm = digests | ||||
113 | if not EmergeHash.checkFilesDigests( EmergeStandardDirs.downloadDir(), filenames, digests, algorithm): | ||||
105 | EmergeDebug.error("invalid digest file") | 114 | EmergeDebug.error("invalid digest file") | ||
106 | return False | 115 | return False | ||
107 | else: | 116 | else: | ||
108 | EmergeDebug.debug("print source file digests", 1) | 117 | EmergeDebug.debug("print source file digests", 1) | ||
109 | digests = utils.createFilesDigests( EmergeStandardDirs.downloadDir(), filenames ) | 118 | EmergeHash.printFilesDigests(EmergeStandardDirs.downloadDir(), filenames, self.subinfo.buildTarget, algorithm = EmergeHash.HashAlgorithm.SHA256) | ||
110 | utils.printFilesDigests( digests, self.subinfo.buildTarget) | | |||
111 | return True | 119 | return True | ||
112 | 120 | | |||
113 | def unpack(self): | 121 | def unpack(self): | ||
114 | """unpacking all zipped(gz, zip, bz2) tarballs""" | 122 | """unpacking all zipped(gz, zip, bz2) tarballs""" | ||
115 | EmergeDebug.debug("ArchiveSource.unpack called", 2) | 123 | EmergeDebug.debug("ArchiveSource.unpack called", 2) | ||
116 | 124 | | |||
117 | filenames = self.localFileNames() | 125 | filenames = self.localFileNames() | ||
118 | ## @todo: unpack destination is probably sourceDir() | 126 | ## @todo: unpack destination is probably sourceDir() | ||
Show All 10 Lines | 135 | elif self.subinfo.options.unpack.unpackIntoBuildDir: | |||
129 | EmergeDebug.debug("unpacking files into build dir %s" % destdir, 1) | 137 | EmergeDebug.debug("unpacking files into build dir %s" % destdir, 1) | ||
130 | else: | 138 | else: | ||
131 | destdir = self.workDir() | 139 | destdir = self.workDir() | ||
132 | EmergeDebug.debug("unpacking files into work root %s" % destdir, 1) | 140 | EmergeDebug.debug("unpacking files into work root %s" % destdir, 1) | ||
133 | 141 | | |||
134 | if hasattr(self.subinfo.options.unpack, 'unpackDir'): | 142 | if hasattr(self.subinfo.options.unpack, 'unpackDir'): | ||
135 | destdir = os.path.join(destdir, self.subinfo.options.unpack.unpackDir) | 143 | destdir = os.path.join(destdir, self.subinfo.options.unpack.unpackDir) | ||
136 | 144 | | |||
137 | if self.subinfo.hasTargetDigestUrls(): | 145 | self.checkDigest() | ||
138 | EmergeDebug.debug("check digests urls", 1) | | |||
139 | if not utils.checkFilesDigests( EmergeStandardDirs.downloadDir(), filenames): | | |||
140 | EmergeDebug.error("invalid digest file") | | |||
141 | return False | | |||
142 | elif self.subinfo.hasTargetDigests(): | | |||
143 | EmergeDebug.debug("check digests", 1) | | |||
144 | if not utils.checkFilesDigests( EmergeStandardDirs.downloadDir(), filenames, self.subinfo.targetDigest()): | | |||
145 | EmergeDebug.error("invalid digest file") | | |||
146 | return False | | |||
147 | else: | | |||
148 | EmergeDebug.debug("print source file digests", 1) | | |||
149 | digests = utils.createFilesDigests( EmergeStandardDirs.downloadDir(), filenames ) | | |||
150 | utils.printFilesDigests( digests, self.subinfo.buildTarget) | | |||
151 | 146 | | |||
152 | binEndings = (".exe", ".bat", ".msi") | 147 | binEndings = (".exe", ".bat", ".msi") | ||
153 | if (self.subinfo.archiveName() == "" and self.url.endswith(binEndings)) or self.subinfo.archiveName().endswith(binEndings): | 148 | if (self.subinfo.archiveName() == "" and self.url.endswith(binEndings)) or self.subinfo.archiveName().endswith(binEndings): | ||
154 | for filename in filenames: | 149 | for filename in filenames: | ||
155 | filePath = os.path.abspath( os.path.join(EmergeStandardDirs.downloadDir(), filename) ) | 150 | filePath = os.path.abspath( os.path.join(EmergeStandardDirs.downloadDir(), filename) ) | ||
156 | if self.subinfo.options.unpack.runInstaller: | 151 | if self.subinfo.options.unpack.runInstaller: | ||
157 | _, ext = os.path.splitext( filename ) | 152 | _, ext = os.path.splitext( filename ) | ||
158 | if ext == ".exe": | 153 | if ext == ".exe": | ||
▲ Show 20 Lines • Show All 111 Lines • Show Last 20 Lines |