diff options
author | Arturo FilastoĢ <hellais@torproject.org> | 2011-08-19 15:05:07 +0200 |
---|---|---|
committer | Arturo FilastoĢ <hellais@torproject.org> | 2011-08-19 15:05:07 +0200 |
commit | 406ad86833f44167cf3719d7d052bdca0c0da0d7 (patch) | |
tree | a9d0a239915f78c16a64606354cb4cd6858733b6 /packages/torouter-web/src/tui/utils/fileio.py | |
parent | 89a84c8bd8ebad59388b180dc1f8a7e497f3ba58 (diff) | |
download | torouter-406ad86833f44167cf3719d7d052bdca0c0da0d7.tar.gz torouter-406ad86833f44167cf3719d7d052bdca0c0da0d7.zip |
Add support for torrc file read and write
Diffstat (limited to 'packages/torouter-web/src/tui/utils/fileio.py')
-rw-r--r-- | packages/torouter-web/src/tui/utils/fileio.py | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/packages/torouter-web/src/tui/utils/fileio.py b/packages/torouter-web/src/tui/utils/fileio.py new file mode 100644 index 0000000..3234f1e --- /dev/null +++ b/packages/torouter-web/src/tui/utils/fileio.py @@ -0,0 +1,21 @@ +import os + +def write(files): + tmpfiles = [] + for file in files: + tmpfile = "/tmp/" + file[0].split("/")[-1:][0] + ".tmp" + tmpfiles.append((tmpfile,file[0])) + # open the tmp file for write + f = open(tmpfile, 'w') + # write the data (file[1]) to the temp file + f.write(file[1]) + f.close() + + # rename all the file. This operation is atomic + for file in tmpfiles: + os.rename(file[0], file[1]) + +files = [('/tmp/file1','blablbal'),('/tmp/file2','The content'),('/tmp/file3','The content 3')] + +write(files) + |