def status(): active = False git_root_dir = get_git_root_dir() if git_root_dir is not None: local_hooks_path = os.path.join(git_root_dir, '.git', 'hooks') database_path = os.path.join(local_hooks_path, DATABASE_FILE) hook_path = os.path.join(local_hooks_path, HOOK_FILENAME) if os.path.exists(database_path) and os.path.exists(hook_path): _note('podmena is activated for current repository!') active = True global_hooks_path = os.path.expanduser('~/.podmena/hooks') global_database_path = os.path.join(global_hooks_path, DATABASE_FILE) global_hook_path = os.path.join(global_hooks_path, HOOK_FILENAME) git_global_hooks_config = get_git_config_hooks_value() if (os.path.exists(global_database_path) and os.path.exists(global_hook_path) and git_global_hooks_config == global_hooks_path): _note('podmena is activated globally!') active = True if not active: _warn('podmena is not activated neither for current repository ' 'nor globally!')
def global_uninstall(): rc = unset_git_global_hooks_path() if rc == 0: _info('Deactivated podmena globally') elif rc == 5: _warn('podmena is not installed globally!') sys.exit(1) else: _warn('Failed to deactivate') sys.exit(rc)
def local_uninstall(): git_local_root = os.path.join(os.getcwd(), '.git') hook_filepath = os.path.join(git_local_root, 'hooks', HOOK_FILENAME) db_link = os.path.join(git_local_root, 'hooks', DATABASE_FILE) if os.path.exists(hook_filepath): os.remove(hook_filepath) os.remove(db_link) _note('Uninstalled for current repository') else: _warn('podmena is not installed for current repository!') sys.exit(1)
def local_install(): git_local_root = os.path.join(os.getcwd(), '.git') local_hooks_path = os.path.join(git_local_root, 'hooks') if os.path.exists(git_local_root) and os.path.isdir(git_local_root): src_file = os.path.join(RESOURCES_DIR, HOOK_FILENAME) dst_file = os.path.join(local_hooks_path, HOOK_FILENAME) shutil.copyfile(src_file, dst_file) os.chmod(dst_file, 0o0775) db_file = os.path.join(RESOURCES_DIR, DATABASE_FILE) db_link = os.path.join(local_hooks_path, DATABASE_FILE) force_symlink(db_file, db_link) _note('Successfully installed for current repository!') else: _warn('Not a git repository') sys.exit(1)