Skip to content

Commit 890149e

Browse files
committed
Improve logging
1 parent 1db17ed commit 890149e

File tree

1 file changed

+25
-14
lines changed

1 file changed

+25
-14
lines changed

examples/export_all_sites_plugin.py

+25-14
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ def main():
150150
os.chdir(export_folder)
151151

152152
# this will get changed later:
153-
result = "Interrupted"
153+
result = None
154154

155155
try:
156156
if args.repo_subfolder:
@@ -161,18 +161,24 @@ def main():
161161
logging.info("Using this path to git: %s", git_path)
162162

163163
result = subprocess.run(
164-
[git_path, "fetch", "origin"], check=True, capture_output=True
164+
[git_path, "fetch", "origin"],
165+
check=True,
166+
capture_output=True,
167+
text=True,
165168
)
166-
logging.debug(result)
169+
logging.debug(result.stdout)
167170
result = subprocess.run(
168171
[git_path, "reset", "--hard", "origin/main"],
169172
check=True,
170173
capture_output=True,
174+
text=True,
171175
)
172-
logging.debug(result)
176+
logging.debug(result.stdout)
173177
logging.info("Now attempting to git pull repo.")
174-
result = subprocess.run([git_path, "pull"], check=True, capture_output=True)
175-
logging.debug(result)
178+
result = subprocess.run(
179+
[git_path, "pull"], check=True, capture_output=True, text=True
180+
)
181+
logging.debug(result.stdout)
176182

177183
# if --delete arg used, delete export folder:
178184
if args.delete:
@@ -187,25 +193,30 @@ def main():
187193
[git_path, "add", "."],
188194
check=True,
189195
stdout=subprocess.PIPE,
196+
text=True,
190197
)
191-
logging.debug(result)
198+
logging.debug(result.stdout)
192199
result = subprocess.run(
193200
[git_path, "commit", "-m", "add changes from export"],
194201
check=True,
195-
text=True,
196202
capture_output=True,
203+
text=True,
197204
)
198-
logging.debug(result)
205+
logging.debug(result.stdout)
199206
result = subprocess.run(
200207
[git_path, "push"],
201208
check=True,
202-
text=True,
203209
capture_output=True,
210+
text=True,
204211
)
205-
logging.debug(result)
206-
except BaseException as err:
207-
logging.error(err)
208-
logging.debug(result)
212+
logging.debug(result.stdout)
213+
except subprocess.CalledProcessError as err:
214+
logging.error("Subprocess error: %s", err)
215+
logging.debug(result.stdout)
216+
raise
217+
except Exception as err:
218+
logging.error("An error occurred: %s", err)
219+
logging.debug(result.stdout)
209220
raise
210221

211222
logging.info("----- Session Ended ------")

0 commit comments

Comments
 (0)