Author: deryck
Date: 2004-09-03 22:09:03 +0000 (Fri, 03 Sep 2004)
New Revision: 310

WebSVN: 
http://websvn.samba.org/websvn/changeset.php?rep=samba-web&path=/trunk/scripts&rev=310&nolog=1

Log:

Reference variables in loop statement rather than 
assigning them explicitly.  Also, change date format
to allow for correct date sort.

--deryck

Modified:
   trunk/scripts/updateNews.py


Changeset:
Modified: trunk/scripts/updateNews.py
===================================================================
--- trunk/scripts/updateNews.py 2004-09-03 21:12:32 UTC (rev 309)
+++ trunk/scripts/updateNews.py 2004-09-03 22:09:03 UTC (rev 310)
@@ -13,55 +13,51 @@
 #
 
 import os, time
-from stat import *
+from stat import ST_MTIME
 
-top_dir = '/data/httpd/html/samba/news'                # set to news directory path
+# top_dir = '/data/httpd/html/samba/news'      # set to news directory path
+top_dir = '/srv/www/htdocs/news'
 not_news = ['.svn', 'images', 'style', 'calendar', 'index.html']
 
 
 # Get list of news directories.  Then, pair up dir name with dir files.
 
 os.chdir(top_dir)
-top_dir_files = os.listdir(os.curdir)
-
 topics = []                
-for x in top_dir_files:
-    if x in not_news: continue
-    if os.path.isdir(x):
-        topics.append(x)
+
+for file in os.listdir(top_dir):
+    if file in not_news: continue
+    if os.path.isdir(file):
+        topics.append(file)
 topics.sort()
 
 topics_files = {}
-for x in topics:
-    topics_files[x] = os.listdir(x)
+for topic in topics:
+    topics_files[topic] = os.listdir(topic)
 
 
 # Loop through each directory, find all stories, and create main index.html
 
 all_stories = {}
 
-for x in topics:        
-    topic = x
-    filelist = os.listdir(topic)
-    os.chdir(topic)
-    
+for topic in topics:        
+    cur_dir = top_dir + '/' + topic
+    os.chdir(cur_dir)
     topic_stories = {}
     
-    for x in filelist:
-        if x in not_news: continue
-        f = open(x, 'r')
-        f_lines = f.readlines()
-        story = "".join(f_lines) + '<div class="reference">Link: <a 
href="/samba/news/' + topic + '/#' + x[:-5] + '">' + topic + '/</a></div>\n\n'
-        f_stats = os.stat(x)
-        f_date = time.strftime("%d %B %Y", time.localtime(f_stats[ST_MTIME]))
+    for file in os.listdir(cur_dir):
+        if file in not_news: continue
+        f_lines = open(file, 'r').readlines()
+        story = "".join(f_lines) + '<div class="reference">Link: <a 
href="/samba/news/' + topic + '/#' + file[:-5] + '">' + topic + '/</a></div>\n\n'
+        f_stats = os.stat(file)
+        f_date = time.strftime("%B %d %Y", time.localtime(f_stats[ST_MTIME]))
         # group stories on the same date under that one date
         if f_date in topic_stories.keys():
             topic_stories[f_date] += story
         else:
             topic_stories[f_date] = story
 
-    for x in topic_stories.keys():
-        h2date = x
+    for h2date in topic_stories.keys():
         # again, group stories from same date under that date
         if h2date in all_stories.keys():
             all_stories[h2date] += topic_stories[h2date]
@@ -80,8 +76,7 @@
 post_dates.sort()
 post_dates.reverse()
 
-for x in post_dates:
-    h2date = x
+for h2date in post_dates:
     news_text = all_stories[h2date]
     index = open('index.html', 'a')
     index.write('<h2>' + h2date + '</h2>\n\n')
@@ -102,11 +97,10 @@
     
     stories_by_date = {}
     
-    for x in filelist:
-        if x in not_news: continue
-        f = open(x, 'r')
-        f_lines = f.readlines()
-        f_stats = os.stat(x)
+    for file in filelist:
+        if file in not_news: continue
+        f_lines = open(file, 'r').readlines()
+        f_stats = os.stat(file)
         f_date = time.strftime("%d %B %Y", time.localtime(f_stats[ST_MTIME]))
         # group stories from same date under that one date
         if f_date in stories_by_date.keys():
@@ -126,8 +120,7 @@
     post_dates.sort()
     post_dates.reverse()
 
-    for x in post_dates:
-        h2date = x
+    for h2date in post_dates:
         news_text = "".join(stories_by_date[h2date])
         index = open('index.html', 'a')
         index.write('<h2>' + h2date + '</h2>\n\n')
@@ -143,5 +136,5 @@
 
 # Loop through each subdirectory, using function to create each index.html.
 
-for x in topics_files.keys():
-    archive(x, topics_files[x])
+for topic in topics_files.keys():
+    archive(topic, topics_files[topic])

Reply via email to