Compare commits

..

2 commits

Author SHA1 Message Date
Florian Kretschmer
d67d396b88
Builder/Docker - Remove PUID and PGID ( they were not used ) (#2852) 2024-12-27 13:03:36 +01:00
MoshiMoshi0
05f54f0ce6
UI - Fix diff not starting from last viewed snapshot (#2744) (#2856) 2024-12-27 13:03:10 +01:00
17 changed files with 36 additions and 193 deletions

View file

@ -1,53 +0,0 @@
name: Build Debian Package
# Check status: systemctl status changedetection.io.service
# Get logs: journalctl -u changedetection.io.service
on: [push, pull_request]
jobs:
build-deb:
runs-on: ubuntu-latest
name: Build and Package changedetection.io
env:
PACKAGE_VERSION: 0.48.5 # or load from somewhere else
steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
path: changedetection.io-${{ env.PACKAGE_VERSION }}
- name: Set up Python 3.11
uses: actions/setup-python@v4
with:
python-version: '3.11'
- name: Install Build Dependencies
run: |
sudo apt-get update
sudo apt-get install -y \
build-essential \
devscripts \
dh-virtualenv \
dh-python \
python3-all \
python3-all-dev \
python3.10 \
python3.10-venv \
python3.10-dev \
debhelper-compat
- name: Build the Debian Package
# Build it the same as the pypi way, then use the same package tar
run: |
mkdir /tmp/changedetection.io
python3 -m build
mv dist/*gz .
debuild -us -uc
- name: Upload Debian Package Artifact
uses: actions/upload-artifact@v3
with:
name: changedetection.io-deb-package
path: ../*.deb
#@todo install and test that some basic content appears

View file

@ -10,8 +10,6 @@ recursive-include changedetectionio/tests *
prune changedetectionio/static/package-lock.json
prune changedetectionio/static/styles/node_modules
prune changedetectionio/static/styles/package-lock.json
prune changedetectionio/tests/test-datastore
include changedetection.py
include requirements.txt
include README-pip.md
@ -20,6 +18,5 @@ global-exclude node_modules
global-exclude venv
global-exclude test-datastore
global-exclude changedetectionio/tests/test-datastore
global-exclude changedetection.io*dist-info
global-exclude changedetectionio/tests/proxy_socks5/test-datastore

View file

@ -1,4 +0,0 @@
from . import main
if __name__ == '__main__':
main()

View file

@ -247,37 +247,32 @@ class model(watch_base):
bump = self.history
return self.__newest_history_key
# Given an arbitrary timestamp, find the closest next key
# For example, last_viewed = 1000 so it should return the next 1001 timestamp
#
# used for the [diff] button so it can preset a smarter from_version
# Given an arbitrary timestamp, find the best history key for the [diff] button so it can preset a smarter from_version
@property
def get_next_snapshot_key_to_last_viewed(self):
def get_from_version_based_on_last_viewed(self):
"""Unfortunately for now timestamp is stored as string key"""
keys = list(self.history.keys())
if not keys:
return None
if len(keys) == 1:
return keys[0]
last_viewed = int(self.get('last_viewed'))
prev_k = keys[0]
sorted_keys = sorted(keys, key=lambda x: int(x))
sorted_keys.reverse()
# When the 'last viewed' timestamp is greater than the newest snapshot, return second last
if last_viewed > int(sorted_keys[0]):
# When the 'last viewed' timestamp is greater than or equal the newest snapshot, return second newest
if last_viewed >= int(sorted_keys[0]):
return sorted_keys[1]
# When the 'last viewed' timestamp is between snapshots, return the older snapshot
for newer, older in list(zip(sorted_keys[0:], sorted_keys[1:])):
if last_viewed < int(newer) and last_viewed >= int(older):
return older
for k in sorted_keys:
if int(k) < last_viewed:
if prev_k == sorted_keys[0]:
# Return the second last one so we dont recommend the same version compares itself
return sorted_keys[1]
return prev_k
prev_k = k
return keys[0]
# When the 'last viewed' timestamp is less than the oldest snapshot, return oldest
return sorted_keys[-1]
def get_history_snapshot(self, timestamp):
import brotli

View file

@ -191,7 +191,7 @@
{% if watch.history_n >= 2 %}
{% if is_unviewed %}
<a href="{{ url_for('diff_history_page', uuid=watch.uuid, from_version=watch.get_next_snapshot_key_to_last_viewed) }}" target="{{watch.uuid}}" class="pure-button pure-button-primary diff-link">History</a>
<a href="{{ url_for('diff_history_page', uuid=watch.uuid, from_version=watch.get_from_version_based_on_last_viewed) }}" target="{{watch.uuid}}" class="pure-button pure-button-primary diff-link">History</a>
{% else %}
<a href="{{ url_for('diff_history_page', uuid=watch.uuid)}}" target="{{watch.uuid}}" class="pure-button pure-button-primary diff-link">History</a>
{% endif %}

View file

@ -16,7 +16,6 @@ class TestDiffBuilder(unittest.TestCase):
watch = Watch.model(datastore_path='/tmp', default={})
watch.ensure_data_dir_exists()
watch['last_viewed'] = 110
# Contents from the browser are always returned from the browser/requests/etc as str, str is basically UTF-16 in python
watch.save_history_text(contents="hello world", timestamp=100, snapshot_id=str(uuid_builder.uuid4()))
@ -25,31 +24,42 @@ class TestDiffBuilder(unittest.TestCase):
watch.save_history_text(contents="hello world", timestamp=112, snapshot_id=str(uuid_builder.uuid4()))
watch.save_history_text(contents="hello world", timestamp=115, snapshot_id=str(uuid_builder.uuid4()))
watch.save_history_text(contents="hello world", timestamp=117, snapshot_id=str(uuid_builder.uuid4()))
p = watch.get_from_version_based_on_last_viewed
assert p == "100", "Correct 'last viewed' timestamp was detected"
p = watch.get_next_snapshot_key_to_last_viewed
assert p == "112", "Correct last-viewed timestamp was detected"
watch['last_viewed'] = 110
p = watch.get_from_version_based_on_last_viewed
assert p == "109", "Correct 'last viewed' timestamp was detected"
# When there is only one step of difference from the end of the list, it should return second-last change
watch['last_viewed'] = 116
p = watch.get_next_snapshot_key_to_last_viewed
assert p == "115", "Correct 'second last' last-viewed timestamp was detected when using the last timestamp"
p = watch.get_from_version_based_on_last_viewed
assert p == "115", "Correct 'last viewed' timestamp was detected"
watch['last_viewed'] = 99
p = watch.get_next_snapshot_key_to_last_viewed
assert p == "100"
p = watch.get_from_version_based_on_last_viewed
assert p == "100", "When the 'last viewed' timestamp is less than the oldest snapshot, return oldest"
watch['last_viewed'] = 200
p = watch.get_next_snapshot_key_to_last_viewed
assert p == "115", "When the 'last viewed' timestamp is greater than the newest snapshot, return second last "
p = watch.get_from_version_based_on_last_viewed
assert p == "115", "When the 'last viewed' timestamp is greater than the newest snapshot, return second newest"
watch['last_viewed'] = 109
p = watch.get_next_snapshot_key_to_last_viewed
p = watch.get_from_version_based_on_last_viewed
assert p == "109", "Correct when its the same time"
# new empty one
watch = Watch.model(datastore_path='/tmp', default={})
p = watch.get_next_snapshot_key_to_last_viewed
p = watch.get_from_version_based_on_last_viewed
assert p == None, "None when no history available"
watch.save_history_text(contents="hello world", timestamp=100, snapshot_id=str(uuid_builder.uuid4()))
p = watch.get_from_version_based_on_last_viewed
assert p == "100", "Correct with only one history snapshot"
watch['last_viewed'] = 200
p = watch.get_from_version_based_on_last_viewed
assert p == "100", "Correct with only one history snapshot"
if __name__ == '__main__':
unittest.main()

View file

@ -1,13 +0,0 @@
[Unit]
Description=changedetection.io Service
After=network.target
[Service]
User=changedetio
Group=changedetio
WorkingDirectory=/opt/changedetection.io
ExecStart=/opt/changedetection.io/bin/python -m changedetectionio
Restart=on-failure
[Install]
WantedBy=multi-user.target

View file

@ -1,13 +0,0 @@
[Unit]
Description=changedetection.io Service
After=network.target
[Service]
User=changedetio
Group=changedetio
WorkingDirectory=/opt/changedetection.io
ExecStart=/opt/changedetection.io/bin/python -m changedetectionio
Restart=on-failure
[Install]
WantedBy=multi-user.target

5
debian/changelog vendored
View file

@ -1,5 +0,0 @@
changedetection.io (0.48.5) unstable; urgency=medium
* Initial release.
-- Your Name <your.email@example.com> Wed, 01 Nov 2023 12:00:00 +0000

14
debian/control vendored
View file

@ -1,14 +0,0 @@
Source: changedetection.io
Section: web
Priority: optional
Maintainer: Your Name <your.email@example.com>
Build-Depends: debhelper-compat (= 13), dh-virtualenv, dh-python, python3-all (>= 3.10), python3-all (<< 3.13), python3.10, python3.10-venv
Standards-Version: 4.6.0
Rules-Requires-Root: no
Homepage: https://github.com/dgtlmoon/changedetection.io
Package: python-changedetection.io
Architecture: all
Depends: ${misc:Depends}, python3 (>= 3.10), python3 (<< 3.13)
Description: Web page change detection - Python application
A web-based application for monitoring web pages for changes.

View file

@ -1 +0,0 @@
python-changedetection.io

1
debian/install vendored
View file

@ -1 +0,0 @@
debian/changedetection.io.service lib/systemd/system/

23
debian/postinst vendored
View file

@ -1,23 +0,0 @@
#!/bin/sh
set -e
# Determine Python version
PYTHON_VERSION=$(ls /usr/bin/python3.1[0-2] | head -n1 | xargs basename)
# Create 'changedetio' user if it doesn't exist
if ! id "changedetio" >/dev/null 2>&1; then
adduser --system --group --no-create-home changedetio
fi
# Set ownership of the installation directory
chown -R changedetio:changedetio /opt/changedetection.io
# Update the systemd service file if necessary
sed -i "s|ExecStart=.*|ExecStart=/opt/changedetection.io/bin/$PYTHON_VERSION -m changedetectionio|" /lib/systemd/system/changedetection.io.service
# Enable and start the service
systemctl daemon-reload
systemctl enable changedetection.io.service
systemctl start changedetection.io.service
exit 0

11
debian/postrm vendored
View file

@ -1,11 +0,0 @@
#!/bin/sh
set -e
# Remove user on purge
if [ "$1" = "purge" ]; then
deluser --system changedetio
fi
systemctl daemon-reload
exit 0

8
debian/prerm vendored
View file

@ -1,8 +0,0 @@
#!/bin/sh
set -e
# Stop and disable the service
systemctl stop changedetection.io.service
systemctl disable changedetection.io.service
exit 0

10
debian/rules vendored
View file

@ -1,10 +0,0 @@
#!/usr/bin/make -f
%:
dh $@ --with python-virtualenv --buildsystem=pybuild
override_dh_virtualenv:
dh_virtualenv --sourcedirectory=. \
--install-suffix='' \
--requirements=requirements.txt \
--python=/usr/bin/python3.11

View file

@ -12,9 +12,6 @@ services:
# environment:
# Default listening port, can also be changed with the -p option
# - PORT=5000
# - PUID=1000
# - PGID=1000
#
# Log levels are in descending order. (TRACE is the most detailed one)
# Log output levels: TRACE, DEBUG(default), INFO, SUCCESS, WARNING, ERROR, CRITICAL