@@ -53,13 +53,35 @@ def deploy(ctx):
53
53
raise Exit (f"Deployment failed: { str (e )} " )
54
54
55
55
@task
56
- def rollback (ctx ):
56
+ def upload (ctx , filename , target_dir = None ):
57
57
"""
58
- Rollback to the previous version if something goes wrong
58
+ Upload file to the server
59
+ Usage: fab upload file1 [target_dir=path]
60
+ Example: fab upload .env
61
+ fab upload .env target_dir=configs
59
62
"""
60
- conn = Connection (host = HOST , user = USER )
61
- with conn .cd (PROJECT_DIR ):
62
- conn .run ('git reset --hard HEAD^' )
63
- with conn .prefix ('source ../venv/bin/activate' ):
64
- conn .run ('python manage.py migrate' )
65
- conn .sudo ('systemctl restart gunicorn' )
63
+ conn = Connection (
64
+ HOST ,
65
+ user = USER ,
66
+ connect_kwargs = {
67
+ "password" : PASSWORD
68
+ }
69
+ )
70
+
71
+ try :
72
+ # Default target directory if none specified
73
+ if target_dir is None :
74
+ target_dir = f'{ PROJECT_DIR } /src'
75
+ else :
76
+ target_dir = f'{ PROJECT_DIR } /{ target_dir } '
77
+
78
+ with conn .cd (target_dir ):
79
+ print (f"Uploading { filename } to { target_dir } ..." )
80
+ if os .path .exists (filename ):
81
+ conn .put (filename , target_dir )
82
+ print (f"Successfully uploaded { filename } " )
83
+ else :
84
+ print (f"Error: { filename } not found in local directory" )
85
+
86
+ except Exception as e :
87
+ print (f"Upload failed: { str (e )} " )
0 commit comments