Esempio n. 1
0
 def commitChanges(self, ids):
     standard.writeLog(self, "[commitChanges]: ids=%s" % str(ids))
     standard.triggerEvent(self, 'beforeCommitRepositoryEvt')
     success = []
     failure = []
     for provider_id in list(set([x.split(':')[0] for x in ids])):
         provider = getattr(self, provider_id)
         basepath = self.get_conf_basepath(provider.id)
         for id in list(
                 set([
                     x.split(':')[1] for x in ids
                     if x.split(':')[0] == provider_id
                 ])):
             try:
                 # Read local-files from provider.
                 files = self.localFiles(provider, [id])
                 # Recreate folder.
                 if os.path.exists(basepath):
                     for name in os.listdir(basepath):
                         filepath = os.path.join(basepath, name)
                         if os.path.isdir(filepath) and name == id:
                             standard.writeLog(
                                 self,
                                 "[commitChanges]: clear dir %s" % filepath)
                             dir = [
                                 os.path.join(filepath, x)
                                 for x in os.listdir(filepath)
                             ]
                             [
                                 _fileutil.remove(x) for x in dir
                                 if os.path.isfile(x)
                             ]
                         elif os.path.isfile(
                                 filepath) and name == '%s.py' % id:
                             standard.writeLog(
                                 self, "[commitChanges]: remove file %s" %
                                 filepath)
                             _fileutil.remove(filepath)
                 # Clear folders.
                 dir = list(
                     set([
                         os.path.join(basepath, x[:x.rfind(os.path.sep)])
                         for x in files if x.endswith('__init__.py')
                     ]))
                 dir = [
                     x for x in dir if x.split(os.path.sep)[-1] in
                     [y.split(':')[-1] for y in ids]
                 ]
                 [[
                     os.remove(z)
                     for z in [os.path.join(x, y) for y in os.listdir(x)]
                     if os.path.isfile(z)
                 ] for x in dir if os.path.isdir(x)]
                 # Write files.
                 for file in files:
                     filepath = os.path.join(basepath, file)
                     folder = filepath[:filepath.rfind(os.path.sep)]
                     standard.writeLog(
                         self, "[commitChanges]: exists folder %s %s" %
                         (folder, str(os.path.exists(folder))))
                     if not os.path.exists(folder):
                         standard.writeLog(
                             self,
                             "[commitChanges]: create folder %s" % folder)
                         _fileutil.mkDir(folder)
                     standard.writeLog(
                         self, "[commitChanges]: write %s" % filepath)
                     data = files[file]['data']
                     if data is not None:
                         f = open(filepath, "wb")
                         try:
                             f.write(data.encode('utf-8'))
                         except:
                             f.write(data)
                         f.close()
                     else:
                         failure.append('%s is None' % file)
                 success.append(id)
             except:
                 standard.writeError(self, "[commitChanges]: can't %s" % id)
                 failure.append(id)
     standard.triggerEvent(self, 'afterCommitRepositoryEvt')
     return success, failure
Esempio n. 2
0
 def __init__(self, location, structure=0):
     self.id = 'acl_mediadb'
     self.setLocation(location)
     self.structure = structure
     _fileutil.mkDir(self.getLocation())