summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAssaf Gordon <assafgordon@gmail.com>2016-06-19 05:11:33 (GMT)
committerAssaf Gordon <assafgordon@gmail.com>2016-06-21 07:03:24 (GMT)
commitd75560697535b04c76a8451cc043876a4130e53c (patch)
tree2713baef2ddd0aebad470e76af604bbe8dd7a5a5
parent002f8f87a239c51daf0cbd991cf3e7f5a68bf80c (diff)
downloadcgi-tools-d75560697535b04c76a8451cc043876a4130e53c.zip
cgi-tools-d75560697535b04c76a8451cc043876a4130e53c.tar.gz
cgi-tools-d75560697535b04c76a8451cc043876a4130e53c.tar.bz2
system.py: new function 'save_file()'
-rw-r--r--cgi_tools/__init__.py2
-rw-r--r--cgi_tools/system.py9
2 files changed, 10 insertions, 1 deletions
diff --git a/cgi_tools/__init__.py b/cgi_tools/__init__.py
index cba2a08..3ecbb63 100644
--- a/cgi_tools/__init__.py
+++ b/cgi_tools/__init__.py
@@ -5,7 +5,7 @@ License: BSD (See LICENSE file)
"""
from .system import force_C_locale, set_resource_limits, \
- run_cmd_list, check_run_cmd_list
+ run_cmd_list, check_run_cmd_list, save_file
from .http_responses import http_bad_request_error, http_server_error, \
http_error, log, set_app_code
diff --git a/cgi_tools/system.py b/cgi_tools/system.py
index 649ceb2..24ff2e1 100644
--- a/cgi_tools/system.py
+++ b/cgi_tools/system.py
@@ -114,3 +114,12 @@ def check_run_cmd_list(cmd):
http_server_error("command '%s' returned error (exit code %d)" % \
(cmd[0],exitcode))
return (out,err)
+
+
+def save_file(filename, content):
+ try:
+ f = open(filename,'w')
+ f.write(content)
+ f.close()
+ except IOError as e:
+ http_server_error("failed to save '%s': %s'" % (filename, str(e)))