Changes in tools/imgutil.py [0a0b3d8:a35b458] in mainline


Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • tools/imgutil.py

    r0a0b3d8 ra35b458  
    4040def align_up(size, alignment):
    4141        "Return size aligned up to alignment"
    42        
     42
    4343        if (size % alignment == 0):
    4444                return size
    45        
     45
    4646        return ((size // alignment) + 1) * alignment
    4747
    4848def count_up(size, alignment):
    4949        "Return units necessary to fit the size"
    50        
     50
    5151        if (size % alignment == 0):
    5252                return (size // alignment)
    53        
     53
    5454        return ((size // alignment) + 1)
    5555
    5656def num_of_trailing_bin_zeros(num):
    5757        "Return number of trailing zeros in binary representation"
    58        
     58
    5959        i = 0
    6060        if (num == 0): raise ValueError()
     
    6666def get_bit(number, n):
    6767        "Return True if n-th least-significant bit is set in the given number"
    68        
     68
    6969        return bool((number >> n) & 1)
    7070
    7171def set_bit(number, n):
    7272        "Return the number with n-th least-significant bit set"
    73        
     73
    7474        return number | (1 << n)
    7575
    7676class ItemToPack:
    7777        "Stores information about one directory item to be added to the image"
    78        
     78
    7979        def __init__(self, parent, name):
    8080                self.parent = parent
     
    8888def listdir_items(path):
    8989        "Return a list of items to be packed inside a fs image"
    90        
     90
    9191        for name in os.listdir(path):
    9292                if name in exclude_names:
    9393                        continue
    94                
     94
    9595                item = ItemToPack(path, name)
    96                
     96
    9797                if not (item.is_dir or item.is_file):
    9898                        continue
    99                
     99
    100100                yield item
    101101
    102102def chunks(item, chunk_size):
    103103        "Iterate contents of a file in chunks of a given size"
    104        
     104
    105105        inf = open(item.path, 'rb')
    106106        rd = 0
    107        
     107
    108108        while (rd < item.size):
    109109                data = bytes(inf.read(chunk_size))
    110110                yield data
    111111                rd += len(data)
    112        
     112
    113113        inf.close()
Note: See TracChangeset for help on using the changeset viewer.