Skip to content

Commit

Permalink
synchronize_owners: Introduce multiple tracking dirs
Browse files Browse the repository at this point in the history
It comes handy to update more than one traking directory at the same
time.
Extend the "tracking_dir" command line parameter to accept one or more
parameters, that will all be used as the original "tracking_dir".

Test: build/synchronize_owners common-mainline android-mainline \
  common11-5.4 common12-5.10 common12-5.4 common-4.19-stable
Signed-off-by: Alessio Balsini <[email protected]>
Change-Id: Ibdf84a70c52acb3e3a574b832ea023192c5c0481
  • Loading branch information
balsini committed May 13, 2021
1 parent 186a707 commit ef08cc4
Showing 1 changed file with 18 additions and 17 deletions.
35 changes: 18 additions & 17 deletions synchronize_owners
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import pathlib
import sys


def process_owners(main_dir, main_branch, tracking_dir):
def process_owners(main_dir, main_branch, tracking_dirs):
# walk the tree ...
for subdir, _, files in os.walk(main_dir):
for file in files:
Expand All @@ -30,23 +30,24 @@ def process_owners(main_dir, main_branch, tracking_dir):
rel_dir = pathlib.Path(subdir[len(main_dir.name) + 1:])
owners = rel_dir / file

target = tracking_dir / owners
comment_line = (f'# include OWNERS from the authoritative '
f'{main_branch} branch\n')
include_line = f'include kernel/common:{main_branch}:/{owners}\n'
for tracking_dir in tracking_dirs:
target = tracking_dir / owners
comment_line = (f'# include OWNERS from the authoritative '
f'{main_branch} branch\n')
include_line = f'include kernel/common:{main_branch}:/{owners}\n'

# ... either add a new file with include directive ...
if not target.is_file():
with open(target, 'w') as file:
file.writelines([comment_line, include_line])

# ... or ensure the include directive is in the file
else:
with open(target) as file:
contents = file.readlines()
if include_line not in contents:
# ... either add a new file with include directive ...
if not target.is_file():
with open(target, 'w') as file:
file.writelines([comment_line, include_line, '\n'] + contents)
file.writelines([comment_line, include_line])

# ... or ensure the include directive is in the file
else:
with open(target) as file:
contents = file.readlines()
if include_line not in contents:
with open(target, 'w') as file:
file.writelines([comment_line, include_line, '\n'] + contents)


def is_dir(dirname):
Expand All @@ -64,7 +65,7 @@ def main():
'main_dir', type=is_dir, help='main directory to synchronize from')
parser.add_argument('main_branch', help='main branch name'),
parser.add_argument(
'tracking_dir', type=is_dir, help='tracking directory to synchronize to')
'tracking_dir', type=is_dir, nargs='+', help='tracking directory to synchronize to')

args = parser.parse_args()

Expand Down

0 comments on commit ef08cc4

Please sign in to comment.