OSDN Git Service

meson.build: Make keyutils independent from keyring
[qmiga/qemu.git] / scripts / qemu-stamp.py
1 #! /usr/bin/env python3
2
3 # Usage: scripts/qemu-stamp.py STRING1 STRING2... -- FILE1 FILE2...
4 import hashlib
5 import os
6 import sys
7
8 sha = hashlib.sha1()
9 is_file = False
10 for arg in sys.argv[1:]:
11     if arg == '--':
12         is_file = True
13         continue
14     if is_file:
15         with open(arg, 'rb') as f:
16             for chunk in iter(lambda: f.read(65536), b''):
17                 sha.update(chunk)
18     else:
19         sha.update(os.fsencode(arg))
20         sha.update(b'\n')
21
22 # The hash can start with a digit, which the compiler doesn't
23 # like as an symbol. So prefix it with an underscore
24 print("_" + sha.hexdigest())