Changes in tools/imgutil.py [a35b458:0a0b3d8] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
tools/imgutil.py
ra35b458 r0a0b3d8 40 40 def align_up(size, alignment): 41 41 "Return size aligned up to alignment" 42 42 43 43 if (size % alignment == 0): 44 44 return size 45 45 46 46 return ((size // alignment) + 1) * alignment 47 47 48 48 def count_up(size, alignment): 49 49 "Return units necessary to fit the size" 50 50 51 51 if (size % alignment == 0): 52 52 return (size // alignment) 53 53 54 54 return ((size // alignment) + 1) 55 55 56 56 def num_of_trailing_bin_zeros(num): 57 57 "Return number of trailing zeros in binary representation" 58 58 59 59 i = 0 60 60 if (num == 0): raise ValueError() … … 66 66 def get_bit(number, n): 67 67 "Return True if n-th least-significant bit is set in the given number" 68 68 69 69 return bool((number >> n) & 1) 70 70 71 71 def set_bit(number, n): 72 72 "Return the number with n-th least-significant bit set" 73 73 74 74 return number | (1 << n) 75 75 76 76 class ItemToPack: 77 77 "Stores information about one directory item to be added to the image" 78 78 79 79 def __init__(self, parent, name): 80 80 self.parent = parent … … 88 88 def listdir_items(path): 89 89 "Return a list of items to be packed inside a fs image" 90 90 91 91 for name in os.listdir(path): 92 92 if name in exclude_names: 93 93 continue 94 94 95 95 item = ItemToPack(path, name) 96 96 97 97 if not (item.is_dir or item.is_file): 98 98 continue 99 99 100 100 yield item 101 101 102 102 def chunks(item, chunk_size): 103 103 "Iterate contents of a file in chunks of a given size" 104 104 105 105 inf = open(item.path, 'rb') 106 106 rd = 0 107 107 108 108 while (rd < item.size): 109 109 data = bytes(inf.read(chunk_size)) 110 110 yield data 111 111 rd += len(data) 112 112 113 113 inf.close()
Note:
See TracChangeset
for help on using the changeset viewer.