]> git.openstreetmap.org Git - chef.git/commitdiff
Port apache-latest-planet-filename to python
authorGrant Slater <github@firefishy.com>
Mon, 25 Sep 2023 17:14:50 +0000 (18:14 +0100)
committerGrant <github@firefishy.com>
Tue, 26 Sep 2023 00:17:30 +0000 (01:17 +0100)
cookbooks/planet/templates/default/apache-latest-planet-filename.erb

index 9107436b3d38cbfddfcd0114393c5a059791a222..283e0d5a8cce8b7d52416e43ce5201a3ff0c2fcb 100644 (file)
@@ -1,26 +1,28 @@
-#!/usr/bin/perl
+#!/usr/bin/python3
 
 # DO NOT EDIT - This file is being maintained by Chef
 
-use strict;
-use warnings;
+import os
+import sys
 
-use Cwd qw(abs_path);
+def main():
+    for line in sys.stdin:
+        path = line.strip()
 
-$| = 1;
+        # Construct the file path and resolve its real path,
+        # which will consider any symbolic links
+        file = os.path.realpath(f"/store/planet{path}")
 
-while (my $path = <STDIN>)
-{
-    chomp $path;
+        # Check if the constructed file path starts with '/store/planet'
+        # and if the file actually exists
+        if file.startswith('/store/planet') and os.path.isfile(file):
+            # Print the portion of the path after '/store/planet'
+            # and immediately flush the output
+            print(file[len('/store/planet'):], flush=True)
+        else:
+            # If the file does not exist or the path does not start with
+            # the expected prefix, print "NULL" and flush the output
+            print("NULL", flush=True)
 
-    my $file = abs_path("/store/planet${path}");
-
-    if ($file && $file =~ m|^/store/planet(/.*)$| && -f $file)
-    {
-        print "$1\n";
-    }
-    else
-    {
-        print "NULL\n";
-    }
-}
+if __name__ == "__main__":
+    main()