diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index e74c499..0000000 --- a/.travis.yml +++ /dev/null @@ -1,8 +0,0 @@ -language: python -python: - - "3.6" - -install: - - "pip install -r requirements.txt" -script: - - "pylint proxstar" diff --git a/proxstar/mail.py b/proxstar/mail.py index 4e3c741..c06c562 100644 --- a/proxstar/mail.py +++ b/proxstar/mail.py @@ -11,7 +11,6 @@ def send_email(toaddr, subject, body): msg['To'] = toaddr msg['Subject'] = subject msg['Date'] = formatdate(localtime=True) - body = body msg.attach(MIMEText(body, 'plain')) server = smtplib.SMTP('mail.csh.rit.edu', 25) server.starttls() @@ -27,18 +26,20 @@ def send_vm_expire_email(user, vms): for vm in vms: if vm[2] == -6: body += ' - {} ({}) has expired (VM has been stopped and will be deleted in 1 day)\n'.format( - vm[1], vm[0]) + vm[1], vm[0] + ) elif vm[2] < 0: body += ' - {} ({}) has expired (VM has been stopped and will be deleted in {} days)\n'.format( - vm[1], vm[0], (7 + int(vm[2]))) + vm[1], vm[0], (7 + int(vm[2])) + ) elif vm[2] == 0: body += ' - {} ({}) expires today (VM has been stopped and will be deleted in 7 days)\n'.format( - vm[1], vm[0]) + vm[1], vm[0] + ) elif vm[2] == 1: body += ' - {} ({}) expires in 1 day\n'.format(vm[1], vm[0]) else: - body += ' - {} ({}) expires in {} days\n'.format( - vm[1], vm[0], vm[2]) + body += ' - {} ({}) expires in {} days\n'.format(vm[1], vm[0], vm[2]) body += '\nPlease login to Proxstar (https://proxstar.csh.rit.edu/) and renew any VMs you would like to keep.' send_email(toaddr, subject, body) @@ -49,10 +50,10 @@ def send_rtp_vm_delete_email(vms): body = 'The following VMs in Proxstar have expired and will be deleted soon:\n\n' for vm in vms: if vm[2] == -6: - body += ' - {} ({}) will be deleted in 1 day\n'.format( - vm[1], vm[0]) + body += ' - {} ({}) will be deleted in 1 day\n'.format(vm[1], vm[0]) else: body += ' - {} ({}) will be deleted in {} days\n'.format( - vm[1], vm[0], (7 + int(vm[2]))) + vm[1], vm[0], (7 + int(vm[2])) + ) body += "\nPlease verify this list to ensure there aren't any pools included in Proxstar that shouldn't be." send_email(toaddr, subject, body) diff --git a/proxstar/vnc.py b/proxstar/vnc.py index 3dd196e..0bcbd06 100644 --- a/proxstar/vnc.py +++ b/proxstar/vnc.py @@ -11,18 +11,16 @@ from proxstar.util import gen_password def stop_websockify(): - result = subprocess.run(['pgrep', 'websockify'], stdout=subprocess.PIPE) + result = subprocess.run(['pgrep', 'websockify'], stdout=subprocess.PIPE, check=False) if result.stdout: pid = result.stdout.strip() - subprocess.run(['kill', pid], stdout=subprocess.PIPE) + subprocess.run(['kill', pid], stdout=subprocess.PIPE, check=False) time.sleep(3) - if subprocess.run(['pgrep', 'websockify'], - stdout=subprocess.PIPE).stdout: + if subprocess.run(['pgrep', 'websockify'], stdout=subprocess.PIPE, check=False).stdout: time.sleep(10) - if subprocess.run(['pgrep', 'websockify'], - stdout=subprocess.PIPE).stdout: + if subprocess.run(['pgrep', 'websockify'], stdout=subprocess.PIPE, check=False).stdout: logging.info("websockify didn't stop, killing forcefully") - subprocess.run(['kill', '-9', pid], stdout=subprocess.PIPE) + subprocess.run(['kill', '-9', pid], stdout=subprocess.PIPE, check=False) def get_vnc_targets(): @@ -41,8 +39,7 @@ def get_vnc_targets(): def add_vnc_target(port): targets = get_vnc_targets() - target = next((target for target in targets if target['port'] == port), - None) + target = next((target for target in targets if target['port'] == port), None) if target: return target['token'] else: @@ -55,14 +52,12 @@ def add_vnc_target(port): def delete_vnc_target(port): targets = get_vnc_targets() - target = next( - (target for target in targets if target['port'] == str(port)), None) + target = next((target for target in targets if target['port'] == str(port)), None) if target: targets.remove(target) target_file = open(app.config['WEBSOCKIFY_TARGET_FILE'], 'w') for target in targets: - target_file.write('{}: 127.0.0.1:{}\n'.format( - target['token'], target['port'])) + target_file.write('{}: 127.0.0.1:{}\n'.format(target['token'], target['port'])) target_file.close() @@ -74,7 +69,8 @@ def start_ssh_tunnel(node, port): ssh_pkey='proxmox_ssh_key', ssh_private_key_password=app.config['PROXMOX_SSH_KEY_PASS'], remote_bind_address=('127.0.0.1', port), - local_bind_address=('127.0.0.1', port)) + local_bind_address=('127.0.0.1', port), + ) server.start() return server @@ -82,9 +78,7 @@ def start_ssh_tunnel(node, port): def stop_ssh_tunnel(vmid, ssh_tunnels): # Tear down the SSH tunnel and VNC target entry for a given VM port = 5900 + int(vmid) - tunnel = next( - (tunnel for tunnel in ssh_tunnels if tunnel.local_bind_port == port), - None) + tunnel = next((tunnel for tunnel in ssh_tunnels if tunnel.local_bind_port == port), None) if tunnel: logging.info('tearing down SSH tunnel for VM %s', vmid) try: @@ -97,7 +91,7 @@ def stop_ssh_tunnel(vmid, ssh_tunnels): def send_stop_ssh_tunnel(vmid): requests.post( - 'https://{}/console/vm/{}/stop'.format(app.config['SERVER_NAME'], - vmid), + 'https://{}/console/vm/{}/stop'.format(app.config['SERVER_NAME'], vmid), data={'token': app.config['VNC_CLEANUP_TOKEN']}, - verify=False) + verify=False, + ) diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..b8ad7e2 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,7 @@ +[tool.black] +# default is 88 +line-length = 100 +skip-string-normalization = true +# default is per-file auto-detection +target-version = ['py38'] +include = '\.py$' \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index 687df64..7eaa98d 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,4 @@ +black~=20.8b1 csh-ldap~=2.2.0 flask==1.0.2 flask-pyoidc==1.3.0 @@ -16,7 +17,7 @@ sqlalchemy==1.3.20 sshtunnel==0.2.2 tenacity==5.0.2 websockify==0.8.0 -pylint==2.3.1 +pylint==2.6.0 pylint-quotes==0.2.1 sentry-sdk[flask] -sentry-sdk~=0.18.0 +sentry-sdk~=0.19.5