def execute_update(self): f = open(os.path.join(self._user_data_dir, ".postupdate"), "w") f.close() executor = CommandExecutor() return executor.execute((self._user_data_dir, self.app_name, self._update_version.to_string()), CommandType.EXECUTE_UPDATE_FILE)
def build(self, args, extra_args): cmd = ["pyinstaller", "--distpath", os.path.join(os.getcwd(), JustUpdateConstants.REPO_FOLDER, "dist"), "--workpath", os.path.join(os.getcwd(), JustUpdateConstants.REPO_FOLDER, "work"), "-y", args] + extra_args executor = CommandExecutor() logging.info("Building.") result, stdout = executor.execute(cmd, CommandType.RAW) if result > 0: # error print(stdout) logging.error("Please correct the errors above and try again.") else: logging.info("Build completed.") return result == 0
def _cmd_make_spec(args, extra=None): cmd = ["pyi-makespec", "--name", get_platform_name_short()] + extra + [args.scriptname] executor = CommandExecutor() result, stdout = executor.execute(cmd, CommandType.RAW) if result > 0: # error print(stdout) logging.error("Please correct the errors above and try again.") else: logging.info("Spec file written.") return True
class Committer(): def __init__(self, version): self.config = Config() self.config.load( os.path.join(JustUpdateConstants.REPO_FOLDER, "config.ju")) self.version = Version(version) self.executor = CommandExecutor() def setup(self): if os.path.isdir(os.path.join(JustUpdateConstants.REPO_FOLDER, "new")) == False: os.makedirs(os.path.join(JustUpdateConstants.REPO_FOLDER, "new")) if os.path.isdir( os.path.join(JustUpdateConstants.REPO_FOLDER, "deploy")) == False: os.makedirs(os.path.join(JustUpdateConstants.REPO_FOLDER, "deploy")) def insure_build_availability(self): cmd = getattr( self, "_insure_build_availability_{}".format(get_platform_name_short())) return cmd() def produce_executable(self): cmd = getattr( self, "_produce_executable_{}".format(get_platform_name_short())) return cmd() def create_metadata(self): cmd = getattr(self, "_create_metadata_{}".format(get_platform_name_short())) return cmd() def finalize(self): cmd = getattr(self, "_finalize_{}".format(get_platform_name_short())) return cmd() def _insure_build_availability_win(self): if os.path.isdir( os.path.join(JustUpdateConstants.REPO_FOLDER, "dist", "win")) == False: return False if not os.listdir( os.path.join(JustUpdateConstants.REPO_FOLDER, "dist", "win")): return False return True def _insure_build_availability_mac(self): if not os.path.isdir( os.path.join(JustUpdateConstants.REPO_FOLDER, "dist", "{}.app".format(self.config.get("app_name")))): return False return True def _produce_executable_win(self): tmp = template.prepare_template(self.version) cmd = ["makensis", "/V1", "-"] result, stdout = self.executor.execute(cmd, CommandType.RAW, stdin=tmp) if result != 0: print(stdout) logging.error("Please correct the errors above and try again.") return False return True def _produce_executable_mac(self): logging.debug("Updating Info.plist and installation scripts.") tmp = template.prepare_template(self.version) logging.debug("Assembling pkg installer.") cmd = [ "productbuild", "--scripts", os.path.join(JustUpdateConstants.REPO_FOLDER, "templates", "mac", "scripts"), "--component", os.path.join(JustUpdateConstants.REPO_FOLDER, "dist", "{}.app".format(self.config.get("app_name"))), "/Applications", os.path.join( JustUpdateConstants.REPO_FOLDER, "new", "{0}-{1}.pkg".format(self.config.get("app_name"), self.version.to_string())) ] result, stdout = self.executor.execute(cmd, CommandType.RAW) if result != 0: print(stdout) logging.error("Please correct the errors above and try again.") return False return True def _create_metadata_win(self): logging.info("Calculating checksum.") checksum = data_manager.calculate_checksum( os.path.join( JustUpdateConstants.REPO_FOLDER, "new", "{0}-{1}.exe".format(self.config.get("app_name"), self.version.to_string()))) logging.info("Looking for existing metadata.") md = MetaData() md.apply_metadata(md.load()) md.add_metadata( "{0}-{1}.exe".format(self.config.get("app_name"), self.version.to_string()), checksum, self.version.to_string()) logging.info("Saving updated metadata.") md.save( ) # The updated metadata is saved to "ju-repo/deploy/metadata.ju". return True def _create_metadata_mac(self): logging.info("Calculating checksum.") checksum = data_manager.calculate_checksum( os.path.join( JustUpdateConstants.REPO_FOLDER, "new", "{0}-{1}.pkg".format(self.config.get("app_name"), self.version.to_string()))) logging.info("Looking for existing metadata.") md = MetaData() md.apply_metadata(md.load()) md.add_metadata( "{0}-{1}.pkg".format(self.config.get("app_name"), self.version.to_string()), checksum, self.version.to_string()) logging.info("Saving updated metadata.") md.save( ) # The updated metadata is saved to "ju-repo/deploy/metadata.ju". return True def _finalize_win(self): logging.info("Moving executable.") shutil.move( os.path.join( JustUpdateConstants.REPO_FOLDER, "new", "{0}-{1}.exe".format(self.config.get("app_name"), self.version.to_string())), os.path.join(JustUpdateConstants.REPO_FOLDER, "deploy")) #cleanup ju-repo/dist/win shutil.rmtree( os.path.join(JustUpdateConstants.REPO_FOLDER, "dist", "win")) def _finalize_mac(self): logging.info("Moving executable.") shutil.move( os.path.join( JustUpdateConstants.REPO_FOLDER, "new", "{0}-{1}.pkg".format(self.config.get("app_name"), self.version.to_string())), os.path.join(JustUpdateConstants.REPO_FOLDER, "deploy")) #cleanup ju-repo/dist/mac try: shutil.rmtree( os.path.join(JustUpdateConstants.REPO_FOLDER, "dist", "mac")) except: pass try: shutil.rmtree( os.path.join(JustUpdateConstants.REPO_FOLDER, "dist", "{}.app".format(self.config.get("app_name")))) except: pass