Skip to content

Instantly share code, notes, and snippets.

@Nimrodda
Last active February 1, 2020 13:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Nimrodda/e9d5e21557d7ca1a9e1e69b2b7bd25b2 to your computer and use it in GitHub Desktop.
Save Nimrodda/e9d5e21557d7ca1a9e1e69b2b7bd25b2 to your computer and use it in GitHub Desktop.
Python script for verifying moved files in an Android projects with variants
"""
Helper script for verifying moved files match variant folders in an Android project.
Useful when modularizing.
Pipe the script to a Git diff command like so:
git --no-pager diff develop --name-status -R|python move-check.py
"""
import re
import sys
def check_moved_files(diff):
errors = 0
match = re.search('^(R\\d{3})', diff)
if match is not None:
match = re.findall('/src/(\\w+?)/', diff)
if len(match) == 2 and match[0] != match[1]:
errors = errors + 1
print('ERROR: Variant folder does not match. Should be %s but was %s in %s' % (match[0], match[1], diff))
return errors
def read_stdin():
if not sys.stdin.isatty():
diff = sys.stdin.readlines()
errors = 0
for line in diff:
errors = errors + check_moved_files(line)
return errors
print('Checking moved files...')
errors = read_stdin()
if errors > 0:
sys.exit('Found errors. See log above.')
else:
print('No errors found.')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment