Commits

Jannis Leidel committed 29cc7d2

Make use of os.path.join for increased robustness.

Comments (0)

Files changed (1)

pep381client/__init__.py

                 setattr(self, field, value)
 
     def store(self):
-        with open(self.homedir+"/status", "wb") as f:
+        with open(os.path.join(self.homedir, "status"), "wb") as f:
             cPickle.dump(self, f, cPickle.HIGHEST_PROTOCOL)
             self.conn.commit()
 
     @staticmethod
     def load(homedir):
-        res = cPickle.load(open(homedir+"/status", "rb"))
-        res.conn = sqlite.open(homedir+"/files")
+        res = cPickle.load(open(os.path.join(homedir, "status"), "rb"))
+        res.conn = sqlite.open(os.path.join(homedir, "files"))
         res.cursor = res.conn.cursor()
         res.defaults()
         return res
             os.makedirs(targetdir)
         else:
             assert not os.listdir(targetdir)
-        for d in ('/web/simple', '/web/packages', '/web/serversig', 
-                  '/web/local-stats/days'):
-            os.makedirs(targetdir+d)
+        for d in ('simple', 'packages', 'serversig',
+                  'local-stats/days'):
+            os.makedirs(os.path.join(targetdir, 'web', d))
         status = Synchronization()
         status.homedir = targetdir
         status.last_started = now()
         status.projects_to_do = set(xmlrpc().list_packages())
-        status.conn = sqlite.open(status.homedir+"/files")
+        status.conn = sqlite.open(os.path.join(status.homedir, "files"))
         status.cursor = status.conn.cursor()
         status.store()
         return status
         self.store()
 
     def update_timestamp(self, when):
-        with open(self.homedir+"/web/last-modified", "wb") as f:
+        with open(os.path.join(self.homedir, "web", "last-modified"), "wb") as f:
             f.write(time.strftime("%Y%m%dT%H:%M:%S\n", time.gmtime(when)))
 
     def copy_simple_page(self, project):
             return None
         if r.status != 200:
             raise ValueError, "Status %d on %s" % (r.status, project)
-        if not os.path.exists(self.homedir+'/web/simple/'+project):
-            os.mkdir(self.homedir+'/web/simple/'+project)
-        with open(self.homedir + "/web/simple/" + project + '/index.html', "wb") as f:
+        project_simple_dir = os.path.join(self.homedir, 'web', 'simple', project)
+        if not os.path.exists(project_simple_dir):
+            os.mkdir(project_simple_dir)
+        with open(os.path.join(project_simple_dir, 'index.html'), "wb") as f:
             f.write(html)
         h.putrequest('GET', '/serversig/'+urllib2.quote(project)+'/')
         h.putheader('User-Agent', UA)
                 # index page is unsigned
                 return
             raise ValueError, "Status %d on signature for %s" % (r.status, project)
-        with open(self.homedir + "/web/serversig/" + project, "wb") as f:
+        with open(os.path.join(self.homedir, "web", "serversig", project), "wb") as f:
             f.write(sig)
         return html
 
             # not modified, discard data
             r.read()
             return
-        lpath = self.homedir + "/web" + path
+        lpath = os.path.join(self.homedir, "web", path)
         if r.status == 200:
             sqlite.remove_file(self.cursor, path) # readd when done downloading
             data = r.read()
 
     def remove_file(self, path):
         sqlite.remove_file(self.cursor, path)
-        lpath = self.homedir + "/web" + path
+        lpath = os.path.join(self.homedir, "web", path)
         if os.path.exists(lpath):
             os.unlink(lpath)
 
     def delete_project(self, project):
         for f in sqlite.files(self.cursor, project):
             self.remove_file(f)
-        if os.path.exists(self.homedir+"/web/simple/"+project):
-            if os.path.exists(self.homedir+"/web/simple/"+project+"/index.html"):
-                os.unlink(self.homedir+"/web/simple/"+project+"/index.html")
-            os.rmdir(self.homedir+"/web/simple/"+project)
-        if os.path.exists(self.homedir+"/web/serversig/"+project):
-            os.unlink(self.homedir+"/web/serversig/"+project)
+        project_simple_dir = os.path.join(self.homedir, "web", "simple", project)
+        if os.path.exists(project_simple_dir):
+            index_file = os.path.join(project_simple_dir, "index.html")
+            if os.path.exists(index_file):
+                os.unlink(index_file)
+            os.rmdir(project_simple_dir)
+        project_serversig_dir = os.path.join(self.homedir, "web", "serversig", project)
+        if os.path.exists(project_serversig_dir):
+            os.unlink(project_serversig_dir)
         if project in self.projects_to_do:
             self.projects_to_do.remove(project)
         if project in self.complete_projects: