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

Fix issue with set_server_config #65

Merged
merged 4 commits into from
Mar 17, 2024
Merged
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ $(VENV_BIN_ACTIVATE): requirements.remote.txt requirements.txt

test: $(VENV_BIN_ACTIVATE) .venv/${FW_VERSION}_reMarkable2-${FW_DATA}.signed
@echo "[info] Running test"
. $(VENV_BIN_ACTIVATE); \
python test.py
if [ -d .venv/mnt ] && mountpoint -q .venv/mnt; then \
umount -ql .venv/mnt; \
fi
Expand Down
8 changes: 4 additions & 4 deletions codexctl/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,11 +142,11 @@ def set_server_config(contents, server_host_name):
data_attributes = contents.split("\n")
line = 0

logger.debug(f"Contents are: {contents}")
logger.debug(f"Contents are:\n{contents}")

for i in range(0, len(data_attributes)):
if data_attributes[i].startswith("[GENERAL]"):
logger.debug("Found GENERAL= line")
if data_attributes[i].startswith("[General]"):
logger.debug("Found [General] line")
line = i + 1
if not data_attributes[i].startswith("SERVER="):
continue
Expand All @@ -157,7 +157,7 @@ def set_server_config(contents, server_host_name):
data_attributes.insert(line, f"SERVER={server_host_name}")
converted = "\n".join(data_attributes)

logger.debug("Converted contents are: {converted}")
logger.debug(f"Converted contents are:\n{converted}")

return converted

Expand Down
12 changes: 7 additions & 5 deletions codexctl/updates.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,13 +255,15 @@ def download_file(
for data in response.iter_content(chunk_size=4096):
dl += len(data)
f.write(data)
done = int(50 * dl / total_length)
sys.stdout.write("\r[%s%s]" % ("=" * done, " " * (50 - done)))
sys.stdout.flush()
if sys.stdout.isatty():
done = int(50 * dl / total_length)
sys.stdout.write("\r[%s%s]" % ("=" * done, " " * (50 - done)))
sys.stdout.flush()

print(end="\r\n")
if sys.stdout.isatty():
print(end="\r\n")

self.logger.debug(f"Downloaded filename")
self.logger.debug("Downloaded filename")

if os.path.getsize(filename) != total_length:
os.remove(filename)
Expand Down
66 changes: 66 additions & 0 deletions test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import sys
import difflib
import codexctl

FAILED = False


def test_set_server_config(original, expected):
global FAILED
print("Testing set_server_config: ", end="")
result = codexctl.set_server_config(original, "test")
if result == expected:
print("pass")
return

FAILED = True
print("fail")
for diff in difflib.ndiff(expected.splitlines(), result.splitlines()):
print(f" {diff}")


test_set_server_config(
"",
"SERVER=test\n",
)

test_set_server_config(
"""[General]
#REMARKABLE_RELEASE_APPID={98DA7DF2-4E3E-4744-9DE6-EC931886ABAB}
#SERVER=https://updates.cloud.remarkable.engineering/service/update2
#GROUP=Prod
#PLATFORM=reMarkable2
REMARKABLE_RELEASE_VERSION=3.9.5.2026
""",
"""[General]
SERVER=test
#REMARKABLE_RELEASE_APPID={98DA7DF2-4E3E-4744-9DE6-EC931886ABAB}
#SERVER=https://updates.cloud.remarkable.engineering/service/update2
#GROUP=Prod
#PLATFORM=reMarkable2
REMARKABLE_RELEASE_VERSION=3.9.5.2026
""",
)

test_set_server_config(
"""[General]
SERVER=testing
#REMARKABLE_RELEASE_APPID={98DA7DF2-4E3E-4744-9DE6-EC931886ABAB}
#SERVER=https://updates.cloud.remarkable.engineering/service/update2
#GROUP=Prod
#PLATFORM=reMarkable2
REMARKABLE_RELEASE_VERSION=3.9.5.2026
""",
"""[General]
SERVER=test
#SERVER=testing
#REMARKABLE_RELEASE_APPID={98DA7DF2-4E3E-4744-9DE6-EC931886ABAB}
#SERVER=https://updates.cloud.remarkable.engineering/service/update2
#GROUP=Prod
#PLATFORM=reMarkable2
REMARKABLE_RELEASE_VERSION=3.9.5.2026
""",
)

if FAILED:
sys.exit(1)
Loading