File tree Expand file tree Collapse file tree 3 files changed +27
-11
lines changed
templates/netbox_script_manager Expand file tree Collapse file tree 3 files changed +27
-11
lines changed Original file line number Diff line number Diff line change 3
3
{% load static %}
4
4
5
5
{% block extra_controls %}
6
+ {% if perms.netbox_script_manager.sync_scriptinstance %}
7
+ < a href ="{% url 'plugins:netbox_script_manager:scriptinstance_sync' %}{% querystring request %} " class ="btn btn-sm btn-primary ">
8
+ < i class ="mdi mdi-refresh "> </ i > Git Sync
9
+ </ a >
10
+ {% endif %}
6
11
{% if perms.netbox_script_manager.add_scriptinstance %}
7
12
< a href ="{% url 'plugins:netbox_script_manager:scriptinstance_load' %}{% querystring request %} " class ="btn btn-sm btn-primary ">
8
13
< i class ="mdi mdi-refresh "> </ i > Load Scripts
Original file line number Diff line number Diff line change 1
1
import inspect
2
+ import io
2
3
import logging
3
4
import pkgutil
4
5
import sys
@@ -105,3 +106,15 @@ def prepare_post_data(request):
105
106
post_data .pop (field , None )
106
107
107
108
return post_data
109
+
110
+
111
+ def git_pull (path ):
112
+ try :
113
+ from dulwich import porcelain
114
+ except ImportError as e :
115
+ raise ImportError ("The dulwich must be installed for git sync functionality to work." )
116
+
117
+ output_io = io .BytesIO ()
118
+ porcelain .pull (path , outstream = output_io , errstream = output_io )
119
+
120
+ return output_io
Original file line number Diff line number Diff line change @@ -176,22 +176,20 @@ def get_required_permission(self):
176
176
return "netbox_script_manager.sync_scriptinstance"
177
177
178
178
def get (self , request ):
179
+ script_root = plugin_config .get ("SCRIPT_ROOT" )
180
+
179
181
try :
180
- from dulwich import porcelain
181
- except ImportError :
182
- messages .error (request , "Dulwich is not installed " )
182
+ output_io = util . git_pull ( script_root )
183
+ except Exception as e :
184
+ messages .error (request , f"Failed to pull git repository: { e } " )
183
185
return redirect ("plugins:netbox_script_manager:scriptinstance_list" )
184
186
185
- script_root = plugin_config .get ("SCRIPT_ROOT" )
186
-
187
- output_io = io .StringIO ()
188
- output = porcelain .pull (script_root , outstream = output_io )
189
- message = [f"Pulled git repository: { script_root } { output_io .getvalue ()} " ]
187
+ message = [f"Pulled git repository: { script_root } " ]
188
+ if output_text := output_io .getvalue ():
189
+ message .append (f"<pre>{ output_text .decode ('utf-8' )} </pre>" )
190
190
191
- if output_io :
192
- message .append (output_io .getvalue ())
191
+ messages .info (request , mark_safe ("\n " .join (message )))
193
192
194
- messages .info (request , "\n " .join (message ))
195
193
return redirect ("plugins:netbox_script_manager:scriptinstance_list" )
196
194
197
195
You can’t perform that action at this time.
0 commit comments