def main(): api = gogs.GogsAPI(config.api_base_url, config.admin_username, config.admin_password) key = paramiko.RSAKey.from_private_key_file(config.pkey_file) client = paramiko.SSHClient() client.get_host_keys().add('git.door43.org', 'ssh-rsa', key) client.set_missing_host_key_policy(paramiko.AutoAddPolicy()) print "connecting" client.connect(hostname="us.door43.org", username="******", port=9299, pkey=key) print "connected" stdin, stdout, stderr = client.exec_command('info -json') json_data = json.load(stdout) sys.setrecursionlimit(2000) for repo_path in json_data['repos']: parts = repo_path.split('/') if len(parts) == 3: org = parts[0] username = parts[1] repo_name = parts[2] if org == 'tS' and repo_name.startswith( 'uw-') and len(username) >= 10: os.system('rm -rf /tmp/{0}'.format(repo_path)) os.system( 'git clone [email protected]:{0} /tmp/{0}'.format( repo_path)) push_repo.push('/tmp/{0}'.format(repo_path), username)
# http://creativecommons.org/licenses/MIT/ # See LICENSE file for details. # # Contributors: # Richard Mahn <*****@*****.**> # ''' Deletes a user in Gogs through the API ''' import sys import gogs import config api = gogs.GogsAPI(config.api_base_url, config.admin_username, config.admin_password, config.admin_token) def delete(username): user = gogs.GogsUser(username, config.new_user_password) api.populateUser(user) if user.id: if len(user.repos) > 0: for repo in user.repos: api.deleteRepo(repo) return api.deleteUser(user, True) if __name__ == '__main__': if len(sys.argv) != 2: print "Usage: delete_user.py <username>" exit(1)