diff options
Diffstat (limited to 'core')
-rw-r--r-- | core/utils.py | 44 | ||||
-rw-r--r-- | core/views/editor_helpers.py | 3 |
2 files changed, 36 insertions, 11 deletions
diff --git a/core/utils.py b/core/utils.py index 36f0982..83e2c5b 100644 --- a/core/utils.py +++ b/core/utils.py @@ -102,7 +102,9 @@ def write_and_commit(files, message): These need refactoring """ + print(files) git = settings.GIT + commands = [] try: for filepath, content, encoding in files: cwd = filepath.parent @@ -126,10 +128,13 @@ def write_and_commit(files, message): raise WriteAndCommitError( f"CANNOT save this file.\nPERMISSIONS incorrectly set on server for this file {filename}. Ask a nerd to fix this." ) - - cp_diff = subprocess.run([git, "diff", filename], cwd=cwd, capture_output=True, text=True) + cmd_diff = [git, "diff", filename] + cp_diff = subprocess.run(cmd_diff, cwd=cwd, capture_output=True, text=True) + commands.append(cmd_diff) if cp_diff.returncode == 0: - cp_add = subprocess.run([git, "add", filename], cwd=cwd, capture_output=True, text=True) + cmd_add = [git, "add", filename] + cp_add = subprocess.run(cmd_add, cwd=cwd, capture_output=True, text=True) + commands.append(cmd_add) if cp_add.returncode != 0: msgdata = ( "Ask a nerd to fix this.\n\n" @@ -145,18 +150,35 @@ def write_and_commit(files, message): ) else: print(f"No change {filepath}") - filenames = [filepath.name for filepath, content, encoding in files] - subprocess.run([git, "commit"] + filenames + ["-m", message], cwd=cwd, capture_output=True, text=True) - cp_status = subprocess.run([git, "status"] + filenames, cwd=cwd, capture_output=True, text=True) + filepaths = [filepath for filepath, content, encoding in files] + cmd_commit = [git, "commit"] + filepaths + ["-m", message] + cm_status = subprocess.run(cmd_commit, cwd=cwd, capture_output=True, text=True) + commands.append(cmd_commit) + if cm_status == 0: + msgdata = ( + "Commands: " + str(commands) + + "Ask a nerd to fix this.\n\n" + + "Stderr: " + cp_status.stderr + + "\n\n" + + "Stdout: " + cp_status.stdout + + "\n\nreturn code: " + str(cp_status.returncode) + ) + raise WriteAndCommitError( + f"Error committing. Edits saved, added to git, but NOT committed.\n\n" + + msgdata + ) + cmd_status = [git, "status"] + filepaths + cp_status = subprocess.run(cmd_status, cwd=cwd, capture_output=True, text=True) + commands.append(cp_status) #This produces return code = 1 if it commits OK, but when the repo still needs to be pushed to origin/expoweb - if not cp_status.stdout or len(cp_status.stdout) < 2 or cp_status.stdout.split("\n")[-2] != "nothing to commit, working tree clean": + if (not cp_status.stdout) or len(cp_status.stdout) < 2 or cp_status.stdout.split("\n")[-2] != "nothing to commit, working tree clean": msgdata = ( + str(commands) + "Ask a nerd to fix this.\n\n" - + cp_status.stderr + + "Stderr: " + cp_status.stderr + "\n\n" - + cp_status.stdout - + "\n\nreturn code: " - + str(cp_status.returncode) + + "Stdout: " + cp_status.stdout + + "\n\nreturn code: " + str(cp_status.returncode) ) raise WriteAndCommitError( f"Error code with git on server for this file {filename}. Edits saved, added to git, but NOT committed.\n\n" diff --git a/core/views/editor_helpers.py b/core/views/editor_helpers.py index 47660b6..17ae04b 100644 --- a/core/views/editor_helpers.py +++ b/core/views/editor_helpers.py @@ -73,9 +73,12 @@ def new_image_form(request, path): i = i.resize((int(width / scale), int(height / scale)), Image.ANTIALIAS) tscale = max(width / THUMBNAIL_WIDTH, height / THUMBNAIL_HEIGHT) thumbnail = i.resize((int(width / tscale), int(height / tscale)), Image.ANTIALIAS) + ib = io.BytesIO() + i = i.convert('RGB') i.save(ib, format="jpeg", quality = 75) tb = io.BytesIO() + thumbnail = thumbnail.convert('RGB') thumbnail.save(tb, format="jpeg", quality = 70) image_rel_path, thumb_rel_path, desc_rel_path = form.get_rel_paths() image_page_template = loader.get_template("image_page_template.html") |