import os
import shutil
+import io
import psycopg2
import configparser
import urllib.parse
with open("{}.tmp".format(fn), "w") as f:
f.write(s)
+ os.chmod("{}.tmp".format(fn), 0o644)
os.rename("{}.tmp".format(fn), fn)
(SELECT * FROM remoterepositories WHERE remoterepositories.id=r.remoterepository_id)
THEN 1 ELSE 0 END
FROM repositories AS r WHERE approved ORDER BY name""")
- f = open("%s.tmp" % self.conf.get("paths", "gitweblist"), "w")
+
+ s = io.StringIO()
webrepos = []
# Check for publishing options here
if web:
- f.write("%s.git %s\n" % (urllib.parse.quote_plus(name), urllib.parse.quote_plus(owner)))
- df = open("%s/description" % repopath, "w")
- df.write(description)
- df.close()
+ s.write("%s.git %s\n" % (urllib.parse.quote_plus(name), urllib.parse.quote_plus(owner)))
+ replace_file_from_string(
+ "%s/description" % repopath,
+ description,
+ )
# Check if we need to change the tab width (default is 8)
repoconf = configparser.ConfigParser()
repoconf.read("%s/config" % repopath)
if os.path.isfile(anonfile):
os.remove(anonfile)
- f.close()
- os.chmod("%s.tmp" % self.conf.get("paths", "gitweblist"), 0o644)
- os.rename("%s.tmp" % self.conf.get("paths", "gitweblist"), self.conf.get("paths", "gitweblist"))
+ replace_file_from_string(
+ self.conf.get("paths", "gitweblist"),
+ s.getvalue(),
+ )
if webrepos:
changed = False