2019-01-26 05:44:02 +01:00
|
|
|
#!/usr/bin/env python3
|
2020-04-16 09:29:20 +02:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
#
|
|
|
|
|
# Copyright (C) 2017-2020 The Project X-Ray Authors.
|
|
|
|
|
#
|
|
|
|
|
# Use of this source code is governed by a ISC-style
|
|
|
|
|
# license that can be found in the LICENSE file or at
|
|
|
|
|
# https://opensource.org/licenses/ISC
|
|
|
|
|
#
|
|
|
|
|
# SPDX-License-Identifier: ISC
|
2019-01-26 05:44:02 +01:00
|
|
|
|
2019-01-30 04:47:46 +01:00
|
|
|
import argparse
|
2019-01-26 05:44:02 +01:00
|
|
|
import hashlib
|
|
|
|
|
import os
|
2019-01-30 04:47:46 +01:00
|
|
|
import parse as format_parser
|
2019-01-26 05:44:02 +01:00
|
|
|
import subprocess
|
|
|
|
|
import sys
|
|
|
|
|
"""Module for generating the Info.md file found in the database directory."""
|
|
|
|
|
|
|
|
|
|
info_md_header = """
|
|
|
|
|
# Details
|
|
|
|
|
|
|
|
|
|
Last updated on {human_date} ({iso8601_date}).
|
|
|
|
|
|
|
|
|
|
Created using [Project X-Ray](https://github.com/SymbiFlow/prjxray) version [{commit_hash_short}](https://github.com/SymbiFlow/prjxray/commit/{commit_hash_long}).
|
|
|
|
|
|
|
|
|
|
Latest commit was;
|
|
|
|
|
```
|
|
|
|
|
{commit_latest}
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
info_md_section = """
|
|
|
|
|
|
|
|
|
|
## Database for [{part_line}]({part_line}/)
|
|
|
|
|
|
|
|
|
|
### Settings
|
|
|
|
|
|
|
|
|
|
Created using following [settings/{part_line}.sh (sha256: {settings_sha256})](https://github.com/SymbiFlow/prjxray/blob/{commit_hash_long}/settings/{part_line}.sh)
|
|
|
|
|
```shell
|
|
|
|
|
{settings_contents}
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
### [Results]({part_line}/)
|
|
|
|
|
|
|
|
|
|
Results have checksums;
|
|
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
|
2019-01-30 05:30:59 +01:00
|
|
|
info_md_file = " * [`{file_sha256} ./{file_short_path}`](./{file_short_path})\n"
|
2019-01-26 05:44:02 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
def sha256(s):
|
|
|
|
|
m = hashlib.sha256()
|
|
|
|
|
m.update(s)
|
|
|
|
|
return m.hexdigest()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def sha256_file(p):
|
|
|
|
|
return sha256(open(p, 'rb').read())
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def run(c):
|
|
|
|
|
o = subprocess.check_output(c, shell=True)
|
|
|
|
|
return o.decode('utf-8').strip()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def main(argv):
|
|
|
|
|
|
2019-01-30 04:47:46 +01:00
|
|
|
parser = argparse.ArgumentParser()
|
|
|
|
|
parser.add_argument(
|
|
|
|
|
'--keep',
|
|
|
|
|
default=False,
|
|
|
|
|
action="store_true",
|
|
|
|
|
help="""\
|
|
|
|
|
Keep the existing commit information.
|
|
|
|
|
""")
|
|
|
|
|
args = parser.parse_args()
|
|
|
|
|
|
|
|
|
|
info_md_filename = os.path.join('database', 'Info.md')
|
2019-02-05 03:09:29 +01:00
|
|
|
assert os.path.exists(info_md_filename), info_md_filename
|
2019-01-30 04:47:46 +01:00
|
|
|
|
2019-01-26 05:44:02 +01:00
|
|
|
info_md = []
|
|
|
|
|
|
|
|
|
|
info_md.append(open('database/README.md').read())
|
|
|
|
|
|
|
|
|
|
v = {}
|
|
|
|
|
v['human_date'] = run('TZ=UTC date')
|
|
|
|
|
v['iso8601_date'] = run('TZ=UTC date --iso-8601=seconds')
|
2019-01-30 04:47:46 +01:00
|
|
|
if not args.keep:
|
|
|
|
|
v['commit_latest'] = run('git log -1')
|
|
|
|
|
v['commit_hash_short'] = run('git log -1 --pretty=%h')
|
|
|
|
|
v['commit_hash_long'] = run('git log -1 --pretty=%H')
|
|
|
|
|
else:
|
|
|
|
|
with open(info_md_filename) as f:
|
|
|
|
|
result = format_parser.parse(
|
|
|
|
|
'{before}' + info_md_header + '{after}', f.read())
|
|
|
|
|
assert result
|
|
|
|
|
assert result['human_date']
|
|
|
|
|
assert result['iso8601_date']
|
|
|
|
|
v['commit_latest'] = result['commit_latest']
|
|
|
|
|
v['commit_hash_short'] = result['commit_hash_short']
|
|
|
|
|
v['commit_hash_long'] = result['commit_hash_long']
|
2019-01-26 05:44:02 +01:00
|
|
|
|
|
|
|
|
info_md.append(info_md_header.format(**v))
|
|
|
|
|
|
|
|
|
|
for part_line in sorted(os.listdir('database')):
|
|
|
|
|
if part_line.startswith('.'):
|
|
|
|
|
continue
|
|
|
|
|
part_path = os.path.join('database', part_line)
|
|
|
|
|
|
|
|
|
|
if not os.path.isdir(part_path):
|
|
|
|
|
continue
|
|
|
|
|
|
|
|
|
|
files = list(os.listdir(part_path))
|
|
|
|
|
files.sort()
|
|
|
|
|
|
|
|
|
|
settings_path = os.path.join('settings', part_line + '.sh')
|
|
|
|
|
settings_raw = open(settings_path, 'rb').read()
|
|
|
|
|
|
|
|
|
|
w = {}
|
|
|
|
|
w['commit_hash_long'] = v['commit_hash_long']
|
|
|
|
|
w['part_line'] = part_line
|
|
|
|
|
w['settings_contents'] = settings_raw.decode('utf-8')
|
|
|
|
|
w['settings_sha256'] = sha256(settings_raw)
|
|
|
|
|
|
|
|
|
|
info_md.append(info_md_section.format(**w))
|
|
|
|
|
|
2019-01-30 05:30:59 +01:00
|
|
|
files = []
|
2019-01-26 05:44:02 +01:00
|
|
|
for dirpath, dirnames, filenames in os.walk(part_path):
|
|
|
|
|
for f in filenames:
|
2019-01-30 05:30:59 +01:00
|
|
|
files.append(os.path.join(dirpath, f))
|
|
|
|
|
|
|
|
|
|
files.sort()
|
|
|
|
|
for p in files:
|
|
|
|
|
x = {}
|
|
|
|
|
x['file_real_path'] = './' + p
|
|
|
|
|
x['file_short_path'] = os.path.join(
|
|
|
|
|
part_line, os.path.relpath(p, part_path))
|
|
|
|
|
x['file_sha256'] = sha256_file(p)
|
|
|
|
|
info_md.append(info_md_file.format(**x))
|
2019-01-26 05:44:02 +01:00
|
|
|
|
2019-01-30 04:47:46 +01:00
|
|
|
with open(info_md_filename, 'w') as f:
|
2019-01-26 05:44:02 +01:00
|
|
|
f.write("".join(info_md))
|
|
|
|
|
|
|
|
|
|
return 0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
|
sys.exit(main(sys.argv))
|