Browse Source

add hook scripts to make life a little easier

Natenom/support-murmur-13-1446181288462
Michael Ziegler 15 years ago
parent
commit
e771fc11e4
  1. 60
      hg/checkexec.py
  2. 34
      hg/checkincoming.py
  3. 44
      hg/licensecheck.py

60
hg/checkexec.py

@ -0,0 +1,60 @@
# -*- coding: utf-8 -*-
"""
* Copyright (C) 2009, Michael "Svedrin" Ziegler <diese-addy@funzt-halt.net>
*
* Mumble-Django is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This package is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
"""
import os, stat
from mercurial import hg
type_whitelist = [
'application/x-executable; charset=binary',
'application/x-sharedlib; charset=binary',
];
def check_mimetype( filename ):
try:
fileproc = os.popen( 'file -ib %s' % filename );
mtype = fileproc.read().strip();
return (mtype in type_whitelist);
finally:
fileproc.close();
def check_script( filename ):
try:
f = open( filename, "rb" );
return f.read(3) == '#!/';
finally:
f.close();
def checkexec( ui, repo, **kwargs ):
modified, added, removed, deleted, unknown, ignored, clean = repo.status();
# We only care about modified and added files. Check their perms to see if +x
for curfile in (modified+added):
fullpath = os.path.join( repo.root, curfile );
statinfo = os.stat( fullpath );
mode = statinfo.st_mode;
# If executable without being an executable or a script, warn and fail
if ( (mode & stat.S_IXUSR) or (mode & stat.S_IXGRP) or (mode & stat.S_IXOTH) ) and \
not ( check_mimetype( fullpath ) or check_script( fullpath ) ):
ui.warn( "Executable bit set on file %s but not ELF or script\n" % curfile );
return True;
return False;

34
hg/checkincoming.py

@ -0,0 +1,34 @@
# -*- coding: utf-8 -*-
"""
* Copyright (C) 2009, Michael "Svedrin" Ziegler <diese-addy@funzt-halt.net>
*
* Mumble-Django is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This package is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
"""
from mercurial import hg
def checkincoming( ui, repo, **kwargs ):
url = ui.config( 'paths', 'default' );
remote = hg.repository( ui, url );
inc = repo.findincoming( remote );
if inc:
ui.status( 'Found %d incoming changesets.\n' % len(inc) );
resp = ui.prompt( 'Do you want to abort the commit and pull/update first? [y/N]', choices=('&yes', '&no'), default='n' );
return resp == 'y';
else:
ui.status( 'Found no incoming changesets, proceeding to commit.\n' );
return False;

44
hg/licensecheck.py

@ -0,0 +1,44 @@
# -*- coding: utf-8 -*-
"""
* Copyright (C) 2009, Michael "Svedrin" Ziegler <diese-addy@funzt-halt.net>
*
* Mumble-Django is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This package is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
"""
import os
from mercurial import hg
def checkfile( filename ):
try:
fileproc = os.popen( 'licensecheck %s' % filename );
result = fileproc.read().strip();
return not result.endswith( "*No copyright* UNKNOWN" );
finally:
fileproc.close();
def licensecheck( ui, repo, **kwargs ):
modified, added, removed, deleted, unknown, ignored, clean = repo.status();
# We only care about modified and added files.
for curfile in (modified+added):
fullpath = os.path.join( repo.root, curfile );
if not checkfile( fullpath ):
ui.warn( "License check failed for %s\n" % curfile );
return True;
return False;
Loading…
Cancel
Save