def _do_load_plugin_cb(self, widget): file_path, loaddir = get_load_name('.tar.gz') if file_path is None: return try: # Copy to tmp file since some systems had trouble # with gunzip directly from datastore datapath = get_path(None, 'instance') if not os.path.exists(datapath): os.makedirs(datapath) tmpfile = os.path.join(datapath, 'tmpfile.tar.gz') subprocess.call(['cp', file_path, tmpfile]) status = subprocess.call(['gunzip', tmpfile]) if status == 0: tar_fd = tarfile.open(tmpfile[:-3], 'r') else: tar_fd = tarfile.open(tmpfile, 'r') except: tar_fd = tarfile.open(file_path, 'r') tmp_dir = tempfile.mkdtemp() try: tar_fd.extractall(tmp_dir) load_a_plugin(self, tmp_dir) self.restore_cursor() except: self.restore_cursor() finally: tar_fd.close() # Remove tmpfile.tar subprocess.call(['rm', os.path.join(datapath, 'tmpfile.tar')])
def _do_load_plugin_cb(self, widget): self.tw.load_save_folder = self._get_execution_dir() file_path, loaddir = get_load_name('.tar.gz', self.tw.load_save_folder) if file_path is None: return try: # Copy to tmp file since some systems had trouble # with gunzip directly from datastore datapath = get_path(None, 'instance') if not os.path.exists(datapath): os.makedirs(datapath) tmpfile = os.path.join(datapath, 'tmpfile.tar.gz') subprocess.call(['cp', file_path, tmpfile]) status = subprocess.call(['gunzip', tmpfile]) if status == 0: tar_fd = tarfile.open(tmpfile[:-3], 'r') else: tar_fd = tarfile.open(tmpfile, 'r') except: tar_fd = tarfile.open(file_path, 'r') tmp_dir = tempfile.mkdtemp() try: tar_fd.extractall(tmp_dir) load_a_plugin(self, tmp_dir) self.restore_cursor() except: self.restore_cursor() finally: tar_fd.close() # Remove tmpfile.tar subprocess.call(['rm', os.path.join(datapath, 'tmpfile.tar')])
def myblock(tw, path): ''' Load heap from file (GNOME only) ''' import os from TurtleArt.tautils import get_load_name, data_from_file if type(path) == float: path = '' if not os.path.exists(path): path, tw.load_save_folder = get_load_name('.*', tw.load_save_folder) if path is None: return data = data_from_file(path) if data is not None: for val in data: tw.lc.heap.append(val) tw.lc.update_label_value('pop', tw.lc.heap[-1])