Commit 41ab0ae9 authored by Gustavo Padovan's avatar Gustavo Padovan
Browse files

backlog-tree: use argparse and take commit list as stdin

parent d4830463
...@@ -30,40 +30,40 @@ To use it run the below from within your kernel directory: ...@@ -30,40 +30,40 @@ To use it run the below from within your kernel directory:
git log --pretty='format:%h,"%s",,' <revision range> | <path to>/contribution-stats.py git log --pretty='format:%h,"%s",,' <revision range> | <path to>/contribution-stats.py
``` ```
Options: Argument options:
* `-h, --help`: show help * `-h, --help`: show help
* `-s, --summary`: sort output according to the number of commits instead of alphabetic order * `-s, --summary`: sort output according to the number of commits instead of alphabetic order
* `-n, --numbered`: suppress commit description and provide a commit count summary only * `-n, --numbered`: suppress commit description and provide a commit count summary only
* `-e, --email`: show the email address of each contributor * `-e, --email`: show the email address of each contributor
* `-o FILE, --output FILE`: output result to a file instead of stdout * `-o FILE, --output FILE`: output result to a file instead of stdout
* `--html FILE`: output as html with link to commits * `--html FILE`: output as html with link to commits
### Generating HTML tree view ### Generating HTML tree view
Export the output of the git cmdline below to a csv file The `stdin` input is a csv list with the following format:
``` `hash,commit subject, comments, status`
git log --pretty='format:%h,"%s",,' <revision range>
```
then pass your csv file as arg:` *comments* and *status* are optional.
``` ```
generate-html-tree.py <csv file> <name> <git cmdline> <git HEAD> git log --pretty='format:%h,"%s",,' <revision range> | ../kernel-scripts/generate-html-tree.py
``` ```
*csv file*: your csv file generated from the git log with the `--pretty='format:%h,"%s"` or pass your csv file as as stdin:
*name*: the name for the output file, do not put a extension on it.
*git cmdline*: the cmd line used to generate the csv file ```
cat commits.csv | ../kernel-scripts/generate-html-tree.py
```
*git HEAD*: the current git HEAD used Argument options:
It will output \<name>.html and \<name>.json * `-h, --help`: show help
* `-o, --output`: basename for the json and HTML output files (default is 'tree')
* `-c, --cmdline`: the cmd line used to generate the list of patches
* `-t, --title`: title for the HTML report
### scripts/ folder ### scripts/ folder
The `scripts/` folder has some ready to use scripts to generate the analysis for some trees. The `scripts/` folder has some ready to use scripts to generate the analysis for some trees.
...@@ -6,7 +6,7 @@ import json ...@@ -6,7 +6,7 @@ import json
import os import os
from datetime import datetime from datetime import datetime
import jinja2 import jinja2
import argparse
#BASE_URL="https://chromium.googlesource.com/chromiumos/third_party/kernel/+/" #BASE_URL="https://chromium.googlesource.com/chromiumos/third_party/kernel/+/"
BASE_URL="https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/?id=" BASE_URL="https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/?id="
...@@ -28,29 +28,33 @@ def classify_commit(fs_dict, commit): ...@@ -28,29 +28,33 @@ def classify_commit(fs_dict, commit):
partial_dict[entry][1] += 1 partial_dict[entry][1] += 1
partial_dict = partial_dict[entry][0] partial_dict = partial_dict[entry][0]
def generate_html(repo, fs_dict, title, cmd, head): def generate_html(repo, fs_dict, title, cmd):
env = jinja2.Environment(loader=jinja2.FileSystemLoader('{}/templates'.format(sys.path[0]))) env = jinja2.Environment(loader=jinja2.FileSystemLoader('{}/templates'.format(sys.path[0])))
template = env.get_template('backlog-tree.html.j2') template = env.get_template('backlog-tree.html.j2')
return template.render(data=fs_dict, baseurl=BASE_URL, title=title, cmdline=cmd, head=head, now=datetime.now()) return template.render(data=fs_dict, baseurl=BASE_URL, title=title, cmdline=cmd, now=datetime.now())
if __name__ == "__main__": if __name__ == "__main__":
repo = git.Repository(os.getcwd()) parser = argparse.ArgumentParser()
parser.set_defaults(func=lambda x: parser.print_help())
parser.add_argument('-t','--title', type=str, default="Kernel commits - tree view",
help="title for the HTML report")
parser.add_argument('-c','--cmdline', type=str,
help="the command line used to generate the list of patches")
parser.add_argument('-o', '--output', metavar="FILE", default="tree",
help="basename for the json and HTML output files")
name = sys.argv[2] args = parser.parse_args(sys.argv[1:])
cmdline = sys.argv[3]
head = sys.argv[4]
repo = git.Repository(os.getcwd())
fs_dict = {} fs_dict = {}
with open(sys.argv[1], newline='') as cvslog: for line in csv.reader(sys.stdin, delimiter=','):
reader = csv.reader(cvslog, delimiter=',' ) classify_commit(fs_dict, line)
for line in reader:
classify_commit(fs_dict, line)
with open(name + '.json', 'w') as json_file: with open(args.output + '.json', 'w') as json_file:
json.dump(fs_dict, json_file) json.dump(fs_dict, json_file)
html = generate_html(repo, fs_dict, name, cmdline, head) html = generate_html(repo, fs_dict, args.title, args.cmdline)
with open(name + '.html', 'w') as html_file: with open(args.output + '.html', 'w') as html_file:
html_file.write(html) html_file.write(html)
...@@ -44,8 +44,9 @@ ...@@ -44,8 +44,9 @@
<body> <body>
<h1 class="m-3">{{ title }}</h1> <h1 class="m-3">{{ title }}</h1>
<h4><code class="badge badge-dark ml-3 p-2">{{ cmdline }}</code></h4> {% if cmdline %}
<p class="m-3">HEAD: <code>{{ head }}</code></p> <h4><code class="badge badge-dark ml-3 p-2">{{ cmdline }}</code></h4>
{% endif %}
<p class="text-monospace m-3">Generated on {{ now }} </p> <p class="text-monospace m-3">Generated on {{ now }} </p>
<ul> <ul>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment