def download(self): if platform.architecture()[0] != '64bit': raise Exception("Only 64bit currently supported") makedirs(self.releases_dir) makedirs(self.tmp_dir) with LockEx(os.path.join(self.tmp_dir, self.name)): if not os.path.isfile(self.executable_path): z = self.zipfile() # use tmpdir instead or a random number extract_dir = os.path.join(self.tmp_dir, self.name) logger.debug("Extracting zipfile %s" % os.path.basename(self.url)) z.extractall(extract_dir) os.rename(extract_dir, os.path.join(self.releases_dir, self.name)) # This can be removed after migrating OSXIntel64 builds to have the AI2Thor executable if os.path.exists( self.old_executable_path) and not os.path.exists( self.executable_path): os.link(self.old_executable_path, self.executable_path) # we can lose the executable permission when unzipping a build os.chmod(self.executable_path, 0o755) else: logger.debug("%s exists - skipping download" % (self.executable_path, ))
def prune_releases(self): current_exec_path = self._build.executable_path rdir = self.releases_dir makedirs(self.tmp_dir) makedirs(self.releases_dir) # sort my mtime ascending, keeping the 3 most recent, attempt to prune anything older all_dirs = list( filter(os.path.isdir, map(lambda x: os.path.join(rdir, x), os.listdir(rdir)))) sorted_dirs = sorted(all_dirs, key=lambda x: os.stat(x).st_mtime)[:-3] for release in sorted_dirs: if current_exec_path.startswith(release): continue try: lf_path = release + ".lock" lf = os.open(lf_path, os.O_RDWR | os.O_CREAT) # we must try to get a lock here since its possible that a process could still # be running with this release fcntl.lockf(lf, fcntl.LOCK_EX | fcntl.LOCK_NB) tmp_prune_dir = os.path.join( self.tmp_dir, '-'.join([ self.build_name(release), str(time.time()), str(random.random()), 'prune' ])) os.rename(release, tmp_prune_dir) shutil.rmtree(tmp_prune_dir) fcntl.lockf(lf, fcntl.LOCK_UN) os.close(lf) os.unlink(lf_path) except Exception as e: pass
def download(self): if platform.architecture()[0] != '64bit': raise Exception("Only 64bit currently supported") makedirs(self.releases_dir) makedirs(self.tmp_dir) download_lf = os.open(os.path.join(self.tmp_dir, self.name + ".lock"), os.O_RDWR | os.O_CREAT) try: fcntl.lockf(download_lf, fcntl.LOCK_EX) if not os.path.isfile(self.executable_path): zip_data = ai2thor.downloader.download( self.url, self.sha256(), self.include_private_scenes) z = zipfile.ZipFile(io.BytesIO(zip_data)) # use tmpdir instead or a random number extract_dir = os.path.join(self.tmp_dir, self.name) logger.debug("Extracting zipfile %s" % os.path.basename(self.url)) z.extractall(extract_dir) os.rename(extract_dir, os.path.join(self.releases_dir, self.name)) # we can lose the executable permission when unzipping a build os.chmod(self.executable_path, 0o755) else: logger.debug("%s exists - skipping download" % self.executable_path) finally: fcntl.lockf(download_lf, fcntl.LOCK_UN) os.close(download_lf)
def prune_releases(self): current_exec_path = self._build.executable_path rdir = self.releases_dir makedirs(self.tmp_dir) makedirs(self.releases_dir) # sort my mtime ascending, keeping the 3 most recent, attempt to prune anything older all_dirs = list( filter(os.path.isdir, map(lambda x: os.path.join(rdir, x), os.listdir(rdir)))) sorted_dirs = sorted(all_dirs, key=lambda x: os.stat(x).st_mtime)[:-3] for release in sorted_dirs: if current_exec_path.startswith(release): continue self._prune_release(release)
def _cache_commit_history(self, branch, payload): makedirs(self.commits_cache_dir) cache_filename = self._cache_commit_filename(branch) atomic_write(cache_filename, json.dumps(payload))