def replicate_data(self): # distros print _("----- Copying Distros") local_distros = self.api.distros() try: remote_distros = self.remote.get_distros() except: raise CX(_("Failed to contact remote server")) if self.sync_all or self.sync_trees: print _("----- Rsyncing Distribution Trees") self.rsync_it(os.path.join(self.settings.webdir,"ks_mirror"),self.settings.webdir) for distro in remote_distros: print _("Importing remote distro %s.") % distro['name'] if os.path.exists(distro['kernel']): new_distro = self.api.new_distro() new_distro.from_datastruct(distro) self.link_distro(new_distro) try: self.api.add_distro(new_distro) print _("Copied distro %s.") % distro['name'] except Exception, e: utils.print_exc(e) print _("Failed to copy distro %s") % distro['name'] else: print _("Failed to copy distro %s, content not here yet.") % distro['name']
def getClassMD5(self): utils.logger.info("https://files.pymcl.net/client/" + self.currentInstanceVersion + "/classmd5.json") try: with requests.get("https://files.pymcl.net/client/" + self.currentInstanceVersion + "/classmd5.json") as response: classMD5 = json.loads(response.content) except: utils.print_exc() classMD5 = None return classMD5
def main(): """ CLI entry point """ try: run_upgrade_checks() rc = BootCLI().run(sys.argv) if rc == True or rc is None: return 0 elif rc == False: return 1 return rc except Exception, exc: if sys.exc_type==SystemExit: return exc.code else: utils.print_exc(exc,full=True) return 1
def create_fb2(data): if not check_xml(data): return None try: fb2 = etree.XML(data) except: #print_exc() if not options.nofix: try: data = str(FB2Parser(data, convertEntities='xml')) options.file_fixed = True fb2 = etree.XML(data) except: print_exc() return None else: stats.fixed += 1 else: return None return fb2
self.status.move(5, 27) self.status.resize(self.width()-10, self.height()-32) font = QFont() font.setStyleHint(QFont().Monospace) font.setFamily("monospace") self.status.setFont(font) def closeEvent(self, event, *args, **kwargs): if not self.iWantToDie: event.ignore() else: self.status.clear() try: # sys.stdout = open(config.MC_DIR + "/" + str(time.time()) + ".log", "w") signal.signal(signal.SIGTERM, lambda num, frame: utils.logger.close()) threadingEvent = threading.Event() app = QApplication([]) mainWin = mainWindow() sys.exit(app.exec_()) except Exception as e: try: utils.print_exc() except: pass with open(config.MC_DIR + "/crash.log", "w") as file: file.write(str(e)) sys.exit(1)
def createModpack(self): utils.logger.info("Copying instance to ~/tmp") shutil.copytree(config.MC_DIR + "/instances/" + self.currentInstance, config.MC_DIR + "/tmp/" + self.currentInstance) utils.logger.info("Copied.") binpath = config.MC_DIR + "/tmp/" + self.currentInstance + "/.minecraft/bin/" mcpath = config.MC_DIR + "/tmp/" + self.currentInstance + "/.minecraft/" if self.doSoundRemoval or self.makePyMCLModpack: utils.logger.info("Getting sound MD5") try: soundsMD5 = self.getSoundMD5() utils.logger.info("MD5 retrieved.\nCulling vanilla resources") self.cull("resources", soundsMD5) utils.logger.info("Vanilla resources removed.") except: utils.print_exc() utils.logger.info( "An error occurred when trying to remove vanilla resources." ) if self.doClassRemoval or self.makePyMCLModpack: utils.logger.info("Extracting minecraft.jar") try: shutil.unpack_archive(binpath + "minecraft.jar", binpath + "minecraft", "zip") utils.logger.info("Extracted.\nGetting class md5") classMD5 = self.getClassMD5() utils.logger.info("MD5 Retrieved.\nCulling vanilla classes") self.cull("bin/minecraft", classMD5) utils.logger.info("Vanilla classes removed.\nRepacking jar") shutil.make_archive(binpath + "minecraft", "zip", binpath + "minecraft") try: os.unlink(binpath + "minecraft.jar") except: utils.print_exc() os.rename(binpath + "minecraft.zip", binpath + "minecraft.jar") shutil.rmtree(binpath + "minecraft") except: utils.print_exc() utils.logger.info( "An error occurred when trying to remove vanilla resources." ) if self.doLWJGLRemoval or self.makePyMCLModpack: utils.logger.info("Removing LWJGL files.") try: os.unlink(binpath + "lwjgl.jar") except: pass try: os.unlink(binpath + "lwjgl_util.jar") except: pass try: os.unlink(binpath + "jinput.jar") except: pass try: os.unlink(binpath + "license.txt") except: pass try: shutil.rmtree(binpath + "natives") except: pass utils.logger.info("LWJGL files removed, if any existed.") utils.logger.info("Creating modpack.") shutil.make_archive(config.MC_DIR + "/tmp/" + self.currentInstance, "zip", config.MC_DIR + "/tmp/" + self.currentInstance) utils.logger.info("Modpack created.\nMoving to export folder.") utils.areYouThere(config.MC_DIR + "/modpackzips/export/") if os.path.exists(config.MC_DIR + "/modpackzips/export/" + self.currentInstance + ".zip"): os.unlink(config.MC_DIR + "/modpackzips/export/" + self.currentInstance + ".zip") shutil.move(config.MC_DIR + "/tmp/" + self.currentInstance + ".zip", config.MC_DIR + "/modpackzips/export") utils.logger.info( "Modpack created.\nBe sure to make a modpack.json file for the modpack!" )
def process_file(fn, ftype, z_filename, data): # 0. logging LogOptions.filename = os.path.abspath(fn) stats.total += 1 options.file_fixed = False if options.log_file and (stats.total % 10) == 0: # progress tm = time.time() - stats.starttime eta = stats.total_files * tm / stats.total - tm h = int(eta / 3600) m = (eta - h * 3600) / 60 s = eta % 60 sys.stdout.write('\r%d out of %d (ETA: %02dh %02dm %02ds)' % (stats.total, stats.total_files, h, m, s)) sys.stdout.flush() if ftype == 'error': # unzip error print_log('ERROR:', z_filename, level=3) stats.errors += 1 return False filename = fn if z_filename: LogOptions.z_filename = z_filename filename = z_filename # 1. search bookid f = base_name(filename) if f is None: # filename does not ends with 'fb2' stats.errors += 1 print_log('ERROR: bad filename:', z_filename, level=3) copy_fb2('unknown-id-' + str(stats.errors), data) return False if options.search_id: fb2 = create_fb2(data) bookid = get_bookid(f, fb2) else: bookid = get_bookid(f, None) if bookid is None: stats.errors += 1 print_log('ERROR: unknown bookid', level=3) copy_fb2('unknown-id-' + str(stats.errors), data) return False print_log('bookid =', str(bookid)) # 2. check is deleted if not options.nodel and bookid not in not_deleted_list: print_log('deleted, skip') if options.save_deleted: copy_fb2(bookid, data, options.save_deleted, 'save deleted file:') return False # 3. update not_deleted_list if bookid in not_deleted_list: not_deleted_list.remove(bookid) else: print 'INTERNAL ERROR:', bookid, 'not in not_deleted_list' # 4. create fb2 (dom) if not if not options.search_id: fb2 = create_fb2(data) if fb2 is None: stats.errors += 1 copy_fb2(bookid, data) return False # 5. update if not options.noup: try: d, book_info = update_fb2(fb2, bookid) except: print_exc() stats.errors += 1 copy_fb2(bookid, data) return False data = d # 6. save result out_fn = str(bookid) + '.fb2' if options.fn_format: out_file = get_filename(book_info) if not out_file: out_file = os.path.join(options.out_dir, out_fn) else: out_file = out_file + '.fb2' d = os.path.dirname(out_file) if os.path.isdir(d): pass elif os.path.exists(d): print_log('ERROR: file exists:', d, level=3) return False else: os.makedirs(d) else: out_file = os.path.join(options.out_dir, out_fn) if options.nozip: open(out_file, 'w').write(data) else: try: save_zip(out_file, out_fn, data) except: print print '>>', len(out_file), out_file raise stats.passed += 1 return True
def process_file(fn, ftype, z_filename, data): # 0. logging LogOptions.filename = os.path.abspath(fn) stats.total += 1 options.file_fixed = False if options.log_file and (stats.total % 10) == 0: # progress tm = time.time() - stats.starttime eta = stats.total_files * tm / stats.total - tm h = int(eta / 3600) m = (eta - h * 3600) / 60 s = eta % 60 sys.stdout.write('\r%d out of %d (ETA: %02dh %02dm %02ds)' % (stats.total, stats.total_files, h, m, s)) sys.stdout.flush() if ftype == 'error': # unzip error print_log('ERROR:', z_filename, level=3) stats.errors += 1 return False filename = fn if z_filename: LogOptions.z_filename = z_filename filename = z_filename # 1. search bookid f = base_name(filename) if f is None: # filename does not ends with 'fb2' stats.errors += 1 print_log('ERROR: bad filename:', z_filename, level=3) copy_fb2('unknown-id-'+str(stats.errors), data) return False if options.search_id: fb2 = create_fb2(data) bookid = get_bookid(f, fb2) else: bookid = get_bookid(f, None) if bookid is None: stats.errors += 1 print_log('ERROR: unknown bookid', level=3) copy_fb2('unknown-id-'+str(stats.errors), data) return False print_log('bookid =', str(bookid)) # 2. check is deleted if not options.nodel and bookid not in not_deleted_list: print_log('deleted, skip') if options.save_deleted: copy_fb2(bookid, data, options.save_deleted, 'save deleted file:') return False # 3. update not_deleted_list if bookid in not_deleted_list: not_deleted_list.remove(bookid) else: print 'INTERNAL ERROR:', bookid, 'not in not_deleted_list' # 4. create fb2 (dom) if not if not options.search_id: fb2 = create_fb2(data) if fb2 is None: stats.errors += 1 copy_fb2(bookid, data) return False # 5. update if not options.noup: try: d, book_info = update_fb2(fb2, bookid) except: print_exc() stats.errors += 1 copy_fb2(bookid, data) return False data = d # 6. save result out_fn = str(bookid)+'.fb2' if options.fn_format: out_file = get_filename(book_info) if not out_file: out_file = os.path.join(options.out_dir, out_fn) else: out_file = out_file+'.fb2' d = os.path.dirname(out_file) if os.path.isdir(d): pass elif os.path.exists(d): print_log('ERROR: file exists:', d, level=3) return False else: os.makedirs(d) else: out_file = os.path.join(options.out_dir, out_fn) if options.nozip: open(out_file, 'w').write(data) else: try: save_zip(out_file, out_fn, data) except: print print '>>', len(out_file), out_file raise stats.passed += 1 return True
remote_profiles = self.remote.get_profiles() # workaround for profile inheritance, must load in order def __depth_sort(a,b): return cmp(a["depth"],b["depth"]) remote_profiles.sort(__depth_sort) for profile in remote_profiles: print _("Importing remote profile %s" % profile['name']) new_profile = self.api.new_profile() new_profile.from_datastruct(profile) try: self.api.add_profile(new_profile) print _("Copyied profile %s.") % profile['name'] except Exception, e: utils.print_exc(e) print _("Failed to copy profile %s.") % profile['name'] # images print _("----- Copying Images") remote_images = self.remote.get_images() for image in remote_images: print _("Importing remote image %s" % image['name']) new_image = self.api.new_image() new_image.from_datastruct(image) try: self.api.add_image(new_image) print _("Copyied image %s.") % image['name'] except Exception, e: utils.print_exc(e) print _("Failed to copy image %s.") % profile['image']