Scripts:ModifiedDemoRotator

From BF2 Technical Information Wiki
Revision as of 15:38, 22 June 2018 by Pireax (talk | contribs) (Created page with "__TOC__ == What It Does == * Checks to see if your demo path and demo target path are the same before moving. This is mainly only useful if you don't want your demos moved,...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

What It Does

  • Checks to see if your demo path and demo target path are the same before moving. This is mainly only useful if you don't want your demos moved, but you still want them regularly pruned. (Or if you have your demo path symlinked to your web directory.)
  • chmods all demo files 0644 so they can be downloaded through the web or in-game.

Installation

  1. Browser to adminutils/demo/ in your bf2 server directory
  2. Backup rotate_demo.py. (cp rotate_demo.py rotate_demo.py.bak.)
  3. Download rotate_demo.py.patch or copy the below text into a file manually.
  4. Patch rotate_demo.py: patch -p0 rotate_demo.py < rotate_demo.py.patch.

Code

Downloadable

http://dackz.net/misc/code/rotate_demo/rotate_demo.py.patch


Readable

--- rotate_demo.py.orig    2005-06-26 16:02:51.000000000 -0400
+++ rotate_demo.py    2005-06-26 16:06:34.000000000 -0400
@@ -79,13 +79,14 @@
     ensure_exists(os.path.join(options['target_root'], 'demos'))
 
 
-    # try to move the fail, or fail miserably
-    try:
-        # NOTE: this requires atleast Python 2.3
-        print "moving '%s' to '%s'" % (path, target_demo_dir)
-        shutil.move(path, target_demo_dir)
-    except IOError:
-        sys.exit(1)
+    # don't move if path and target are the same
+    if os.path.abspath(os.path.dirname(path)) != os.path.abspath(target_demo_dir):
+        try:
+            # NOTE: this requires atleast Python 2.3
+            print "moving '%s' to '%s'" % (path, target_demo_dir)
+            shutil.move(path, target_demo_dir)
+        except IOError:
+            sys.exit(1)
 
     timestamped = []
 
@@ -93,6 +94,7 @@
     for pf in filter(lambda x: x.endswith('.bf2demo'), os.listdir(target_demo_dir)):
         try:
             ppath = os.path.join(target_demo_dir, pf)
+            os.chmod(ppath, 0644) # make web-readable
             timestamped.append((os.stat(ppath).st_mtime, ppath))
         except IOError:
             pass # don't let I/O errors stop us</code>