Advertisement
Guest User

Untitled

a guest
Jul 19th, 2019
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.00 KB | None | 0 0
  1. diff --git a/blob_list.py b/blob_list.py
  2. index 11903a4..3ae7268 100755
  3. --- a/blob_list.py
  4. +++ b/blob_list.py
  5. @@ -1,31 +1,47 @@
  6. #!/usr/bin/python
  7.  
  8. -import os
  9. import sys
  10. -import subprocess
  11.  
  12. from blobs import *
  13.  
  14. +
  15. class BlobList:
  16. def __init__(self, dir_path):
  17. self.__dir_path = dir_path
  18. self.__modules = self._read_modules()
  19. self.__blacklisted = self._read_blacklisted()
  20.  
  21. - def _read_modules(self):
  22. + all_file_paths = self._get_dir_file_paths(self.__dir_path)
  23. +
  24. + executable_blobs = self._extract_elf_blobs(all_file_paths, ["bin/"])
  25. + lib_groups = self._extract_elf_groups(all_file_paths, ["lib/", "lib64/"])
  26. + all_blobs = self._extract_blobs(all_file_paths, [])
  27. +
  28. + self._blobs = executable_blobs + lib_groups + all_blobs
  29. +
  30. + # Figure out non-elf dependencies
  31. + self._adopt_blobs(self._blobs, all_blobs)
  32. +
  33. + # Figure out elf dependencies
  34. + self._adopt_blobs(self._blobs, lib_groups)
  35. +
  36. + @staticmethod
  37. + def _read_modules():
  38. with open("source_available_files.txt", "r") as file:
  39. modules = file.read().splitlines()
  40.  
  41. return modules
  42.  
  43. - def _read_blacklisted(self):
  44. + @staticmethod
  45. + def _read_blacklisted():
  46. with open("blacklisted_files.txt", "r") as file:
  47. blacklisted = file.read().splitlines()
  48.  
  49. return blacklisted
  50.  
  51. - def _get_dir_file_paths(self, dir_path):
  52. - '''
  53. + @staticmethod
  54. + def _get_dir_file_paths(dir_path):
  55. + """
  56. Get a list of file paths found inside `dir_path`.
  57.  
  58. Args:
  59. @@ -33,7 +49,7 @@ class BlobList:
  60.  
  61. Returns:
  62. list: A list of all the file paths.
  63. - '''
  64. + """
  65.  
  66. file_paths = []
  67. for root, _, files in os.walk(dir_path):
  68. @@ -47,8 +63,9 @@ class BlobList:
  69.  
  70. return file_paths
  71.  
  72. - def _extract_subdir_file_paths(self, file_paths, subdirs):
  73. - '''
  74. + @staticmethod
  75. + def _extract_subdir_file_paths(file_paths, subdirs):
  76. + """
  77. Extract file paths that are found under `subdir` from a list of file paths.
  78.  
  79. Args:
  80. @@ -57,7 +74,7 @@ class BlobList:
  81.  
  82. Returns:
  83. list: A list of all the extracted file paths.
  84. - '''
  85. + """
  86.  
  87. subdir_file_paths = []
  88.  
  89. @@ -81,7 +98,7 @@ class BlobList:
  90. return subdir_file_paths
  91.  
  92. def _extract_blobs(self, all_file_paths, subdirs):
  93. - '''
  94. + """
  95. Extract a list of simple blobs from the file paths that are
  96. found under `subdir` from a list of file paths.
  97.  
  98. @@ -91,7 +108,7 @@ class BlobList:
  99.  
  100. Returns:
  101. list: A list of all the extracted simple blobs.
  102. - '''
  103. + """
  104.  
  105. blobs = []
  106.  
  107. @@ -109,7 +126,7 @@ class BlobList:
  108. return blobs
  109.  
  110. def _extract_elf_blobs(self, all_file_paths, subdirs):
  111. - '''
  112. + """
  113. Extract a list of elf blobs from the file paths that are
  114. found under `subdir` from a list of file paths.
  115.  
  116. @@ -119,10 +136,10 @@ class BlobList:
  117.  
  118. Returns:
  119. list: A list of all the extracted elf blobs.
  120. - '''
  121. + """
  122.  
  123. elf_blobs = []
  124. - nonelf_file_paths = []
  125. + non_elf_file_paths = []
  126.  
  127. file_paths = self._extract_subdir_file_paths(all_file_paths, subdirs)
  128. for file_path in file_paths:
  129. @@ -130,16 +147,16 @@ class BlobList:
  130. elf_blob = ELFBlob(self.__dir_path, file_path)
  131. elf_blobs.append(elf_blob)
  132. except:
  133. - nonelf_file_paths.append(file_path)
  134. + non_elf_file_paths.append(file_path)
  135.  
  136. # Add back non-ELF files
  137. - for file_path in nonelf_file_paths:
  138. + for file_path in non_elf_file_paths:
  139. all_file_paths.append(file_path)
  140.  
  141. return elf_blobs
  142.  
  143. def _extract_elf_groups(self, all_file_paths, subdirs):
  144. - '''
  145. + """
  146. Extract a list of elf groups from the file paths that are
  147. found under `subdir` from a list of file paths.
  148.  
  149. @@ -149,7 +166,7 @@ class BlobList:
  150.  
  151. Returns:
  152. list: A list of all the extracted elf groups.
  153. - '''
  154. + """
  155.  
  156. nonelf_file_paths = []
  157.  
  158. @@ -173,14 +190,15 @@ class BlobList:
  159.  
  160. return elf_groups
  161.  
  162. - def _adopt_blobs(self, target_blobs, source_blobs):
  163. - '''
  164. + @staticmethod
  165. + def _adopt_blobs(target_blobs, source_blobs):
  166. + """
  167. Adopt needed blobs from a list of blobs.
  168.  
  169. Args:
  170. target_blobs (list): The list of blobs to adopt into.
  171. source_blobs (list): The list of blobs to adopt from.
  172. - '''
  173. + """
  174. i = 0
  175. while True:
  176. if i == len(source_blobs):
  177. @@ -201,21 +219,6 @@ class BlobList:
  178. else:
  179. i += 1
  180.  
  181. - def build_blob_trees(self):
  182. - all_file_paths = self._get_dir_file_paths(self.__dir_path)
  183. -
  184. - executable_blobs = self._extract_elf_blobs(all_file_paths, ["bin/"])
  185. - lib_groups = self._extract_elf_groups(all_file_paths, ["lib/", "lib64/"])
  186. - all_blobs = self._extract_blobs(all_file_paths, [])
  187. -
  188. - self._blobs = executable_blobs + lib_groups + all_blobs
  189. -
  190. - # Figure out non-elf dependencies
  191. - self._adopt_blobs(self._blobs, all_blobs)
  192. -
  193. - # Figure out elf dependencies
  194. - self._adopt_blobs(self._blobs, lib_groups)
  195. -
  196. def print_blobs(self, file):
  197. for blob in self._blobs:
  198. blob_name = blob.get_name()
  199. @@ -272,6 +275,7 @@ class BlobList:
  200. file.write(string)
  201. file.write("\n")
  202.  
  203. +
  204. if len(sys.argv) < 2:
  205. print("not enough arguments!")
  206. print("usage: blob_list.py <vendor_path> <target_path>")
  207. @@ -287,7 +291,6 @@ target_proprietary_files_path = os.path.join(target_path, "proprietary_files.txt
  208. target_modules_path = os.path.join(target_path, "modules.mk")
  209.  
  210. blob_list = BlobList(vendor_path)
  211. -blob_list.build_blob_trees()
  212. with open(target_proprietary_files_path, "w") as file:
  213. blob_list.print_blobs(file)
  214.  
  215. diff --git a/blobs.py b/blobs.py
  216. index 518020d..b7fa682 100644
  217. --- a/blobs.py
  218. +++ b/blobs.py
  219. @@ -2,6 +2,7 @@ import os
  220.  
  221. from utils import *
  222.  
  223. +
  224. class CommonBlobInterface:
  225. def __init__(self):
  226. self._blobs = set()
  227. @@ -85,6 +86,13 @@ class CommonBlobInterface:
  228.  
  229. return final_blobs
  230.  
  231. + def get_absolute_path(self):
  232. + raise Exception("Not implemented")
  233. +
  234. + def get_name(self):
  235. + raise Exception("Not implemented")
  236. +
  237. +
  238. class Blob(CommonBlobInterface):
  239. def __init__(self, dir_path, path):
  240. super().__init__()
  241. @@ -110,6 +118,7 @@ class Blob(CommonBlobInterface):
  242. def get_absolute_path(self):
  243. return self._absolute_path
  244.  
  245. +
  246. class ELFBlob(Blob):
  247. def __init__(self, dir_path, path):
  248. super().__init__(dir_path, path)
  249. @@ -122,8 +131,9 @@ class ELFBlob(Blob):
  250. def get_arch(self):
  251. return self._arch
  252.  
  253. +
  254. class ELFGroup(CommonBlobInterface):
  255. - def __init__(self, dir_path, blobs):
  256. + def __init__(self, _, blobs):
  257. super().__init__()
  258.  
  259. self._initial_blobs = blobs
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement