From 35fe0faaf065d96a53f87a6831e144924fde4cd7 Mon Sep 17 00:00:00 2001 From: gravel Date: Thu, 1 Jun 2023 10:25:15 +0000 Subject: [PATCH] Add dry-run flag & makefile target --- .phpenv | 8 ++++---- Makefile | 4 ++++ php/fetch-servers.php | 4 ++-- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/.phpenv b/.phpenv index b7de114..ea4ce88 100644 --- a/.phpenv +++ b/.phpenv @@ -16,14 +16,14 @@ include_once "$PROJECT_ROOT/php/utils/logging.php"; // Read the -v|--verbose option increasing logging verbosity to debug. - $options = getopt("v", ["verbose", "fast", "no-color"]); + $options = getopt("vn", ["verbose", "fast", "no-color", "dry-run"]); if (isset($options["v"]) or isset($options["verbose"])) { $LOGGING_VERBOSITY = LoggingVerbosity::Debug; } - if (isset($options["fast"])) { - $FAST_FETCH_MODE = true; - } + $FAST_FETCH_MODE = (isset($options["fast"])); + + $DO_DRY_RUN = (isset($options["n"]) || isset($options["dry-run"])); if (isset($options["no-color"])) { LoggingVerbosity::$showColor = false; diff --git a/Makefile b/Makefile index 7926096..64e1b40 100644 --- a/Makefile +++ b/Makefile @@ -18,6 +18,10 @@ all: fetch html fetch: /bin/php php/fetch-servers.php $(FLAGS) +# Fetch room listing without writing to disk. +fetch-dry: + /bin/php php/fetch-servers.php $(FLAGS) --dry-run + # Generate HTML from data. html: /bin/php php/generate-html.php $(FLAGS) diff --git a/php/fetch-servers.php b/php/fetch-servers.php index 0bdcfb8..fcd4c33 100644 --- a/php/fetch-servers.php +++ b/php/fetch-servers.php @@ -22,7 +22,7 @@ * 6. De-dupe servers based on pubkey */ function main() { - global $CACHE_ROOT, $ROOMS_FILE, $KNOWN_SERVERS, $KNOWN_PUBKEYS; + global $CACHE_ROOT, $ROOMS_FILE, $KNOWN_SERVERS, $KNOWN_PUBKEYS, $DO_DRY_RUN; // Create default directories.. file_exists($CACHE_ROOT) or mkdir($CACHE_ROOT, 0700); @@ -61,7 +61,7 @@ ); // Output fetching results to file. - file_put_contents($ROOMS_FILE, json_encode($servers)); + if (!$DO_DRY_RUN) file_put_contents($ROOMS_FILE, json_encode($servers)); } /**