def copy_release(self, release, srclang, dstlang): # copy images & variables #srcsubdirs = [d['name'] for d in self.get_directory('%s/sources/%s'%(path, srclang)) if d['name'] != 'assembly'] #for subdir in srcsubdirs: srcpath = '/releases/%s/sources/%s'%(release, srclang) dstpath = '/releases/%s/sources/%s'%(release, dstlang) self.copyDirs(srcpath,dstpath) try: syncMgr = SynchroManager(*self.args) syncMgr.post_save(dstpath) except: logger.debug("no post save") # replace variable files with translations in sources if available top = self.getOsPath('/releases/%s/sources/%s/variables'%(release, dstlang)) for root, dirs, files in os.walk(top): rroot = root[len(top):] for f in files: srcf = '/sources/%s/variables%s/%s'%(dstlang, rroot, f) if self.exists(srcf): dstf = '/releases/%s/sources/%s/variables%s/%s'%(release, dstlang, rroot, f) self.copy_resource(srcf, dstf) # remplace pictures files with translations in sources if available top = '/release/%s/sources/%s/pictures'%(release, dstlang) for root, dirs, files in os.walk(top): rroot = root[len(top):] for f in files: srcf = '/sources/%s/pictures%s/%s'%(dstlang, rroot, f) if self.exists(srcf): dstf = '/releases/%s/sources/%s/pictures%s/%s'%(release, dstlang, rroot, f) self.copy_resource(srcf, dstf) # copy assembly / change language in references to images # src_assembly_path = '/'.join([path,'sources',srclang,'assembly',assembly_name+'_asm.html']) assembly_path = '/'.join([dstpath, 'assembly', release+'_asm.html']) try: refdir = "/".join([dstpath,'assembly']) self.makedirs(refdir) except OSError: logger.debug('makedir failed') # self.copy_resource(src_assembly_path, assembly_path) xassembly = self.parse( assembly_path) self.update_assembly_lang(xassembly, dstlang) self.xwrite(xassembly, assembly_path) # try: # self.syncMgr.commit(path,"Revision Copy %s to %s"%(srclang, dstlang)) # except: # pass yield assembly_path return
def move_resource(self, src, dest): try: syncMgr = SynchroManager(*self.args) syncMgr.move_resource(src, dest) except: shutil.move(self.__makepath(src), self.__makepath(dest)) try: self.indexMgr.move_resource(src, dest) except: pass
def post_save(self, path): try: syncMgr = SynchroManager(*self.args) syncMgr.post_save(path) except: pass # logger.debug('Synchro unavailable') try: self.indexMgr.post_save(path) except: pass
def copy_resource(self, src, dest): try: syncMgr = SynchroManager(*self.args) syncMgr.copy_resource(src, dest) except: shutil.copy(self.__makepath(src), self.__makepath(dest)) try: self.indexMgr.copy_resource(src, dest) except: pass logger.exception('Search index unavailable')
def delete_resource(self, path, sync = True): if sync: try: syncMgr = SynchroManager(*self.args) syncMgr.delete_resource(path) except: if os.path.isdir(self.__makepath(path)): shutil.rmtree(self.__makepath(path)) else: os.unlink(self.__makepath(path)) else: if os.path.isdir(self.__makepath(path)): shutil.rmtree(self.__makepath(path)) else: os.unlink(self.__makepath(path)) try: self.indexMgr.delete_resource(path) except: pass
def rename(self, newname, newindex): newrelease = newname + '_' + newindex src = '/releases/%s'%(self._release,) dst = '/releases/%s'%(newrelease,) try: syncMgr = SynchroManager(*self.args) os.makedirs(os.path.join(self._basepath, self._username, self._project) + dst) syncMgr.add_resource(dst) syncMgr.move_resource(src +'/sources', dst+ '/sources' ) syncMgr.move_resource(src +'/kolekti', dst + '/kolekti') syncMgr.move_resource(src +'/release_info.json', dst +'/release_info.json') syncMgr.delete_resource(src) except: logger.exception('unable to get sync') raise shutil.move( self._syspath(src), self._syspath(dst) ) # logger.debug(os.listdir(self._syspath('{}/sources'.format(dst)))) for lang in os.listdir(self._syspath('{}/sources'.format(dst))): src_assembly_path = '/sources/%s/assembly/%s_asm.html'%(lang,self._release) if os.path.exists(self._syspath("%s%s"%(dst, src_assembly_path))): assembly_path = ('/sources/%s/assembly/%s_asm.html'%(lang, newrelease)) try: syncMgr.move_resource( "%s%s"%(dst, src_assembly_path), "%s%s"%(dst, assembly_path) ) except: shutil.move( self._syspath("%s%s"%(dst, src_assembly_path)), self._syspath("%s%s"%(dst, assembly_path)) ) ospath = self._syspath("%s%s"%(dst, assembly_path)) assembly = ET.parse(ospath, self._xmlparser) head = assembly.xpath('/h:html/h:head', **ns)[0] self._set_meta(head, "kolekti.project", self._project) self._set_meta(head, "kolekti.releasedir", newrelease) self._set_meta(head, "kolekti.releasename", newname) self._set_meta(head, "kolekti.releaseindex", newindex) with open(ospath, "w") as f: f.write(ET.tostring( assembly, encoding = "utf-8", pretty_print = True, xml_declaration = True )) # handle publication parameters src_job_path = '/kolekti/publication-parameters/%s_asm.xml'%(self._release) job_path = '/kolekti/publication-parameters/%s_asm.xml'%(newrelease) try: syncMgr.move_resource( "%s%s"%(dst, src_job_path), "%s%s"%(dst, job_path) ) except: shutil.move( self._syspath("%s%s"%(dst, src_job_path)), self._syspath("%s%s"%(dst, job_path)) ) # process publication parameters ospath = self._syspath("%s%s"%(dst, job_path)) pp = ET.parse(ospath, self._xmlparser) job = pp.getroot() job.set('pubdir',newrelease) job.set('id',newrelease+"_asm") with open(ospath, "w") as f: f.write(ET.tostring( pp, encoding = "utf-8", pretty_print = True, xml_declaration = True )) # process json info file infofile = self._syspath('{}/release_info.json'.format(dst)) try: mf = json.load(open(infofile)) except: logger.exception('info unreadable') mf = copy.copy(release_info) date = int(time.time()) mf.update({ "assembly_dir" : '/releases/{}'.format(newrelease), "datetime" : date, "releaseindex" : newindex, "releasename" : newname, "releasedir" : newrelease, }) json.dump(mf, open(infofile,'w'))
def _syncstate(self): try: syncMgr = SynchroManager(*self.args) return syncMgr.rev_state() except: return "?"
def _syncnumber(self): try: syncMgr = SynchroManager(*self.args) return syncMgr.rev_number() except: return "?"