We work in members.csv.new file then rename it in the unlikely event that some script...
authorJean-Michel Nirgal Vourgère <jmv@nirgal.com>
Mon, 28 May 2012 15:01:52 +0000 (15:01 +0000)
committerJean-Michel Nirgal Vourgère <jmv@nirgal.com>
Mon, 28 May 2012 15:01:52 +0000 (15:01 +0000)
members.py

index 4923a4878b7c24b3e77b0b72174456de812c17d2..438413ad94c6d12fbf79009fb03f8e4a7a6c714b 100755 (executable)
@@ -496,8 +496,12 @@ if __name__ == '__main__':
         f.truncate()
         f.close()
 
+        # We work in members.csv.new file then rename it
+        # In the unlikely event that some script is reading it
+        # while we updated it
         members_csvfilename = os.path.join(BASE_DIRECTORY, "members.csv")
-        f = open(members_csvfilename, mode='w', encoding='utf-8')
+        members_csvfilename_new = members_csvfilename + '.new'
+        f = open(members_csvfilename_new, mode='w', encoding='utf-8')
         f.write('grade,nick,field,techno,anthill,active,colonized\n')
         for nick, data in newmembers.items():
             data = [
@@ -512,3 +516,4 @@ if __name__ == '__main__':
             data = [ str(x) for x in data ]
             f.write(','.join(data) + '\n')
         f.close()
+        os.rename(members_csvfilename_new, members_csvfilename)