#!/usr/bin/python
from __future__ import print_function

import sys

from automation_tools import get_branchname, run_pylint

from hooksettings import requires_pylint_pass

if __name__ == '__main__':
    branchname = get_branchname()
    if branchname in requires_pylint_pass:
        # Compare current pylint score against that in pylint/config.yml
        passes = run_pylint(['./lint.py', '--score']) 
        sys.exit(int(passes))

    '''
    subprocess.call(['git', 'checkout', 'HEAD', '--', 'hooks/etc/permissions.yml'])
    subprocess.call(['git', 'reset', 'HEAD', 'hooks/etc/permissions.yml'])

    subprocess.call(['git', 'fetch'])
    SHA = subprocess.check_output(['git', 'rev-parse', 'origin/%s' % branchname]).decode('utf-8')
    SHA = SHA.replace('\n', '')
    print('Getting update permissions file from SHA:(%s)' % SHA)

    # Force update the permissions file!
    # git checkout -m <revision> <yourfilepath>
    subprocess.call(['git', 'checkout', '--theirs', SHA, 'hooks/etc/permissions.yml'])
    subprocess.call(['git', 'add', 'hooks/etc/permissions.yml'])
    subprocess.call(['git', 'commit', '--no-verify', 'hooks/etc/permissions.yml', 
                                      '-m', '"Update permissions"'])

    # Check branch permissions
    #LOAD PERMISSIONS
    allowed     = permissions[branchname]
    if allowed != 'all' and 'all' not in allowed:
        print('(%s) are allowed to commit to current branch %s' % (', '.join(allowed), branchname))
        author, _   = get_author()
        print('You are: %s' % author)
        if author in allowed:
            print('Please continue..')
        else:
            print('You don\'t have correct permissions on %s' % branchname)
            sys.exit(1)
    else:
        print('No permissions restrictions on %s' % branchname)
    '''


    sys.exit(0)

