예제 #1
0
 def __init__(self, sync_dir, mode, bufsize, bak_name):
     self.__Ancestor.__init__(self, sync_dir, mode, "w", bufsize, bak_name)
     name = self.sync_dir.file_name
     if sos.path.exists(name):
         if bak_name:
             name = sos.tempfile_name \
                 (Filename (name).directory or sos.curdir)
             sos.mkdir(name)
         else:
             sos.rmdir(name, deletefiles=1)
             if sos.path.exists(name):
                 raise Could_Not_Delete_Old_DB \
                     ( "Deleting %s failed without error message from "
                       "the OS. Try saving to a different database."
                     % (name, )
                     )
             try:
                 sos.mkdir(name)
             except (IOError, OSError):
                 raise Could_Not_Delete_Old_DB \
                     ( "Deleting %s failed without error message from "
                       "the OS. Try saving to a different database."
                     % (name, )
                     )
     else:
         sos.mkdir(name)
     self.name = name
     self._write_stamp_file_header(name)
예제 #2
0
파일: Sync_File.py 프로젝트: Tapyr/tapyr
 def __init__ (self, sync_dir, mode, bufsize, bak_name) :
     self.__Ancestor.__init__ (self, sync_dir, mode, "w", bufsize, bak_name)
     name = self.sync_dir.file_name
     if sos.path.exists (name) :
         if bak_name :
             name = sos.tempfile_name \
                 (Filename (name).directory or sos.curdir)
             sos.mkdir (name)
         else :
             sos.rmdir (name, deletefiles = 1)
             if sos.path.exists (name) :
                 raise Could_Not_Delete_Old_DB \
                     ( "Deleting %s failed without error message from "
                       "the OS. Try saving to a different database."
                     % (name, )
                     )
             try :
                 sos.mkdir (name)
             except (IOError, OSError) :
                 raise Could_Not_Delete_Old_DB \
                     ( "Deleting %s failed without error message from "
                       "the OS. Try saving to a different database."
                     % (name, )
                     )
     else :
         sos.mkdir (name)
     self.name = name
     self._write_stamp_file_header (name)
예제 #3
0
 def close(self):
     if self.name != self.sync_dir.file_name:
         assert self.backup_name
         if sos.path.isdir(self.backup_name):
             sos.rmdir(self.backup_name, deletefiles=1)
         sos.rename(self.sync_dir.file_name, self.backup_name)
         sos.rename(self.name, self.sync_dir.file_name)
         self.name = self.sync_dir.file_name
     self.__Ancestor.close(self)
예제 #4
0
def temp_dir(suffix="", prefix="tmp", dir="/tmp", auto_remove=True):
    """Context manager that creates a temporary directory."""
    temp_dir_path = tempfile.mkdtemp \
        (suffix = suffix, prefix = prefix, dir = dir)
    try:
        yield temp_dir_path
    finally:
        if auto_remove and sos.path.exists(temp_dir_path):
            sos.rmdir(temp_dir_path, deletefiles=True)
예제 #5
0
파일: Sync_File.py 프로젝트: Tapyr/tapyr
 def close (self) :
     if self.name != self.sync_dir.file_name :
         assert self.backup_name
         if sos.path.isdir (self.backup_name) :
             sos.rmdir (self.backup_name, deletefiles = 1)
         sos.rename (self.sync_dir.file_name, self.backup_name)
         sos.rename (self.name,               self.sync_dir.file_name)
         self.name = self.sync_dir.file_name
     self.__Ancestor.close (self)
예제 #6
0
파일: FCM.py 프로젝트: Tapyr/tapyr
def temp_dir (suffix = "", prefix = "tmp", dir = "/tmp", auto_remove = True) :
    """Context manager that creates a temporary directory."""
    temp_dir_path = tempfile.mkdtemp \
        (suffix = suffix, prefix = prefix, dir = dir)
    try :
        yield temp_dir_path
    finally :
        if auto_remove and sos.path.exists (temp_dir_path) :
            sos.rmdir (temp_dir_path, deletefiles = True)
예제 #7
0
파일: Manager.py 프로젝트: JPilarr/tapyr
 def delete_database(cls, db_url):
     uri = db_url.path
     try:
         sos.unlink(uri)
     except OSError:
         pass
     x_uri = MOM.DBW.HPS.Store.X_Uri(uri).name
     try:
         sos.rmdir(x_uri, True)
     except OSError:
         pass
예제 #8
0
파일: Manager.py 프로젝트: Tapyr/tapyr
 def delete_database (cls, db_url) :
     uri = db_url.path
     try :
         sos.unlink (uri)
     except OSError :
         pass
     x_uri = MOM.DBW.HPS.Store.X_Uri (uri).name
     try :
         sos.rmdir (x_uri, True)
     except OSError :
         pass
예제 #9
0
 def close (self) :
     assert sos.path.exists (self.x_uri), self.x_uri.name
     db_uri = self.db_uri
     x_uri  = self.x_uri
     bak    = TFL.Filename (".bak", db_uri)
     with TFL.lock_file (x_uri) :
         info = self.info
         self._check_sync (info)
         with TFL.open_to_replace \
                  (db_uri, mode = "wb", backup_name = bak) as file:
             sos.fchmod (file.fileno (), stat.S_IRUSR | stat.S_IWUSR)
             with contextlib.closing (self.ZF.ZipFile (file, "w")) as zf :
                 for abs, rel in info.FILES (self.x_uri, self.info_uri) :
                     zf.write (abs, rel)
     sos.rmdir (x_uri, deletefiles = True)
예제 #10
0
파일: Store.py 프로젝트: Tapyr/tapyr
 def close (self) :
     assert sos.path.exists (self.x_uri.name), self.x_uri.name
     db_uri = self.db_uri
     x_name = self.x_uri.name
     bak    = TFL.Filename (".bak", db_uri).name
     with TFL.lock_file (x_name) :
         info = self.info
         self._check_sync (info)
         with TFL.open_to_replace \
                  (db_uri.name, mode = "wb", backup_name = bak) as file:
             sos.fchmod (file.fileno (), stat.S_IRUSR | stat.S_IWUSR)
             with contextlib.closing (self.ZF.ZipFile (file, "w")) as zf :
                 for abs, rel in info.FILES (self.x_uri, self.info_uri) :
                     zf.write (abs, rel)
     sos.rmdir (x_name, deletefiles = True)
예제 #11
0
 def _handle_generate_static_pages (self, cao) :
     app  = self._wsgi_app \
         (cao, dynamic_p = False, dynamic_nav_p = cao.dynamic_nav)
     root = cao.static_root
     urls = cao.argv
     if not urls :
         urls = ["/"]
         if sos.path.isdir (root) :
             sos.rmdir (root, deletefiles = True)
     robots = app.resource_from_href ("robots")
     if robots is not None :
         robots.hidden = robots.static_p
     def _generate (cao, p, root, tail = None) :
         name = pjoin (root, tail or p.href_static.lstrip ("/"))
         dir  = sos.path.dirname (name)
         if not sos.path.exists (dir) :
             sos.mkdir_p  (dir)
         if cao.verbose :
             print (name, "...", end = " ")
         asp = p.as_static_page ()
         if asp is not None :
             with open (name, "wb") as f :
                 f.write (pyk.encoded (asp))
         if cao.verbose :
             print ("done")
     for url in urls :
         resource = app.resource_from_href (url)
         if resource.static_p and not resource.auth_required :
             _generate (cao, resource, root)
         for p in resource.static_pages :
             _generate (cao, p, root)
     if not cao.argv :
         for r, url in sorted (pyk.iteritems (app.redirects)) :
             p = app.resource_from_href (url)
             if p.static_p and not p.auth_required :
                 _generate (cao, p, root, r + p.static_page_suffix)
예제 #12
0
 def _handle_generate_static_pages (self, cao) :
     app  = self._wsgi_app \
         (cao, dynamic_p = False, dynamic_nav_p = cao.dynamic_nav)
     root = cao.static_root
     urls = cao.argv
     if not urls :
         urls = ["/"]
         if sos.path.isdir (root) :
             sos.rmdir (root, deletefiles = True)
     robots = app.resource_from_href ("robots")
     if robots is not None :
         robots.hidden = robots.static_p
     def _generate (cao, p, root, tail = None) :
         name = pjoin (root, tail or p.href_static.lstrip ("/"))
         dir  = sos.path.dirname (name)
         if not sos.path.exists (dir) :
             sos.mkdir_p  (dir)
         if cao.verbose :
             print (name, "...", end = " ")
         asp = p.as_static_page ()
         if asp is not None :
             with open (name, "wb") as f :
                 f.write (pyk.encoded (asp))
         if cao.verbose :
             print ("done")
     for url in urls :
         resource = app.resource_from_href (url)
         if resource.static_p and not resource.auth_required :
             _generate (cao, resource, root)
         for p in resource.static_pages :
             _generate (cao, p, root)
     if not cao.argv :
         for r, url in sorted (pyk.iteritems (app.redirects)) :
             p = app.resource_from_href (url)
             if p.static_p and not p.auth_required :
                 _generate (cao, p, root, r + p.static_page_suffix)
예제 #13
0
 def delete_subbox (self, subbox) :
     self.__super.delete_subbox (subbox)
     sos.rmdir                  (subbox.path)
예제 #14
0
 def _clear_dir (self) :
     for fod in sos.listdir_full (self.media_dir) :
         if sos.path.isdir (fod) :
             sos.rmdir  (fod, True)
         else :
             sos.unlink (fod)
예제 #15
0
 def _clear_dir (self) :
     for fod in sos.listdir_full (self.media_dir) :
         if sos.path.isdir (fod) :
             sos.rmdir  (fod, True)
         else :
             sos.unlink (fod)
예제 #16
0
파일: Mailbox.py 프로젝트: Tapyr/tapyr
 def delete_subbox (self, subbox) :
     self.__super.delete_subbox (subbox)
     sos.rmdir                  (subbox.path)