Skip to content

Commit

Permalink
Review control panel details and fix FTP issue with images numbering
Browse files Browse the repository at this point in the history
  • Loading branch information
ZanSara committed Mar 5, 2021
1 parent da933b1 commit 5fb8c3d
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 37 deletions.
23 changes: 13 additions & 10 deletions remote-server/control-panel/index.html
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
<html>
<!DOCTYPE html>
<html lang="it">
<head>
<meta charset="UTF-8">
<meta content="text/html">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="Pannello di controllo ZANZOCAM">

<title>ZANZOCAM - Impostazioni</title>

<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta content="text/html; charset=ISO-8859-1">
<link href="milligram.css" rel="stylesheet">
<script type="text/javascript" src="jszip.js"></script>
<link rel="shortcut icon" type="image/png" href="logos/favicon.png"/>


Expand Down Expand Up @@ -895,7 +898,7 @@ <h4>In alto a destra</h4>
<div class="row">
<div class="column">
<label>Immagine Attuale: <span id="overlays__top_right__path_current"></span></label>
<img id="overlays__top_right__path" height="200"></img>
<img id="overlays__top_right__path" alt="top_right_overlay_image" height="150"></img>
</div>
<div class="column vertical-center">
<label>Cambia immagine</label>
Expand Down Expand Up @@ -1010,7 +1013,7 @@ <h4>In alto al centro</h4>
<div id="top_center_image-vars" class="overlay-fields" style="display: none;">
<div class="column">
<label>Immagine Attuale: <span id="overlays__top_center__path_current"></span></label>
<img id="overlays__top_center__path" height="200"></img>
<img id="overlays__top_center__path" alt="top_center_overlay_image" height="150"></img>
</div>
<div class="column vertical-center">
<label>Cambia immagine</label>
Expand Down Expand Up @@ -1123,7 +1126,7 @@ <h4>In alto a sinistra</h4>
<div id="top_left_image-vars" class="overlay-fields" style="display: none;">
<div class="column">
<label>Immagine Attuale: <span id="overlays__top_left__path_current"></span></label>
<img id="overlays__top_left__path" height="200"></img>
<img id="overlays__top_left__path" alt="top_left_overlay_image" height="150"></img>
</div>
<div class="column vertical-center">
<label>Cambia immagine</label>
Expand Down Expand Up @@ -1235,7 +1238,7 @@ <h4>In basso a destra</h4>
<div id="bottom_right_image-vars" class="overlay-fields" style="display: none;">
<div class="column">
<label>Immagine Attuale: <span id="overlays__bottom_right__path_current"></span></label>
<img id="overlays__bottom_right__path" height="200"></img>
<img id="overlays__bottom_right__path" alt="bottom_right_overlay_image" height="150"></img>
</div>
<div class="column vertical-center">
<label>Cambia immagine</label>
Expand Down Expand Up @@ -1347,7 +1350,7 @@ <h4>In basso al centro</h4>
<div id="bottom_center_image-vars" class="overlay-fields" style="display: none;">
<div class="column">
<label>Immagine Attuale: <span id="overlays__bottom_center__path_current"></span></label>
<img id="overlays__bottom_center__path" height="200"></img>
<img id="overlays__bottom_center__path" alt="bottom_center_overlay_image" height="150"></img>
</div>
<div class="column vertical-center">
<label>Cambia immagine</label>
Expand Down Expand Up @@ -1459,7 +1462,7 @@ <h4>In basso a sinistra</h4>
<div id="bottom_left_image-vars" class="overlay-fields" style="display: none;">
<div class="column">
<label>Immagine Attuale: <span id="overlays__bottom_left__path_current"></span></label>
<img id="overlays__bottom_left__path" height="200"></img>
<img id="overlays__bottom_left__path" alt="bottom_left_overlay_image" height="150"></img>
</div>
<div class="column vertical-center">
<label>Cambia immagine</label>
Expand Down
7 changes: 6 additions & 1 deletion remote-server/control-panel/milligram.css
Original file line number Diff line number Diff line change
Expand Up @@ -762,11 +762,16 @@ label {
}

.color-selector select{
color: white;
color: white; /* to hide the selected value in case of semitransparency */
position: absolute;
max-width: 270px;
}

.color-selector select * {
background-color: white;
color: black; /* to hide the selected value in case of semitransparency */
}

.color-selector input{
position: absolute;
max-width: 220px;
Expand Down
53 changes: 27 additions & 26 deletions webcam/webcam/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -468,49 +468,50 @@ def upload_picture(self, image_path: Path, image_name: str, image_extension: str
Returns the final image path (for cleanup operations)
"""
# NOTE: Errors from here must escalate

# Rename the picture according to max_photos
modifier = ""
if self.max_photos == 0:
modifier = datetime.datetime.now().strftime("_%Y-%m-%d_%H:%M:%S")
elif self.max_photos > 1:
modifier = "__1"
final_image_name = image_name + modifier + "." + image_extension
final_image_name = image_name + modifier + "." + image_extension
final_image_path = image_path.parent / final_image_name
os.rename(image_path, final_image_path)

# If the server is supposed to contain only a fixed amount of pictures,
# If the server is supposed to contain only a fixed amount of pictures,
# apply the prefix to this one and scale the other pictures' prefixes.
# NOTE that in the HTTP version this is done by the PHP script
if self.max_photos > 1:

try:
server_images = [image.lstrip("pictures/") for image in self._ftp_client.nlst("pictures/")]
server_images = [image.lstrip("pictures") for image in self._ftp_client.nlst("pictures/")]
log(f"Pictures already present on the server: {server_images}")
server_images.reverse() # Sort backwards to make the renaming work properly!

log("Renaming pictures....")
for server_image_name in server_images:
split_name = server_image_name.split("__")

if len(split_name) == 2:

# Increase the image index and rename it
name_without_position = "__".join(split_name[:-2])
try:
position = int(split_name[-1]) + 1
except ValueError as e:
if "invalid literal for int() with base 10" in str(e):
log(f"Image with double underscore in the name could not be parsed: {server_image_name} . Ignoring it.")
continue

new_name = f"{name_without_position}__{position}"
self._ftp_client.rename(f"pictures/{server_image_name}", f"pictures/{new_name}")

# If position is above max_photos, delete that picture
if position > self.max_photos:
log(f"Deleting old picture on the server: {new_name} (only {self.max_photos} pictures are allowed)")
self._ftp_client.delete(f"pictures/{new_name}")
log("Renaming pictures....")
for server_image_name in server_images:

extensionless_name = ".".join(server_image_name.split(".")[:-1])
extension = server_image_name.split(".")[-1]
split_name = extensionless_name.split("__")

# Increase the image index and rename it
try:
name_without_position = "__".join(split_name[:-1])
position = int(split_name[-1]) + 1
except ValueError as e:
if "invalid literal for int() with base 10" in str(e):
log(f"Image with double underscore in the name could not be parsed: {server_image_name} . Ignoring it.")
continue

new_name = f"{name_without_position}__{position}.{extension}"
self._ftp_client.rename(f"pictures/{server_image_name}", f"pictures/{new_name}")

# If position is above max_photos, delete that picture
if position > self.max_photos:
log(f"Deleting old picture on the server: {new_name} (only {self.max_photos} pictures are allowed)")
self._ftp_client.delete(f"pictures/{new_name}")

except error_perm as resp:
if '550' in str(resp):
Expand Down

0 comments on commit 5fb8c3d

Please sign in to comment.