Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tweak the fabfile so it works only w/ Fabric 2.6 dependency #1525

Merged
merged 1 commit into from
Oct 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions fabfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

from fabric import task
from invoke import run as local
from patchwork import files

deploys_dir = "/opt/docview/deploys"
target_link = "/opt/docview/target"
Expand Down Expand Up @@ -78,7 +77,7 @@ def whitelist(ctx, ip=None):
"""Toggle the IP whitelist"""
filename = "/opt/docview/IP_WHITELIST"
if ip is None:
if files.exists(ctx, filename):
if check_file_exists(ctx, filename):
ctx.run(f"rm -f {filename}")
print("IP_WHITELIST mode is OFF")
else:
Expand Down Expand Up @@ -120,9 +119,21 @@ def maintenance(ctx):

def toggle_mode(ctx, mode):
filename = f"/opt/docview/{mode}"
if files.exists(ctx, filename):
if check_file_exists(ctx, filename):
ctx.run(f"rm {filename}")
print(f"{mode} mode is OFF")
else:
ctx.run(f"touch {filename}")
print(f"{mode} mode is ON")


def check_file_exists(ctx, remote_path):
"""
Check if a file exists on the remote server.
"""
try:
# Using test command with -f flag to check for regular file
result = ctx.run(f'test -f {remote_path} && echo "EXISTS" || echo "NOT_FOUND"', hide=True)
return result.stdout.strip() == "EXISTS"
except Exception as e:
return False
Loading