def __call__(self): show_status_message('Launching a Mask Script...') if os.path.isfile(as_human_readable(self.pane.get_path()) + os.path.sep + 'package.json'): npmPackagePath = as_human_readable(self.pane.get_path()) + os.path.sep + 'maskfile.md' npmPackagePtr = open(npmPackagePath,"r") npmPackage = json.loads(npmPackagePtr.read()) npmPackagePtr.close() result = show_quicksearch(self._suggest_script) if result: # # Launch the script given. Show the output. # query, script = result # # Get the variables for this plugin # scriptVars = _GetScriptVars() # # Run the script. # saveDir = os.getcwd() os.chdir(as_human_readable(self.pane.get_path()) + os.path.sep) Output = run("source " + scriptVars['local_shell'] + "; mask " + script,stdout=PIPE,shell=True) os.chdir(saveDir) if Output.returncode == 0: if scriptVars['show_output']: show_alert(Output.stdout.decode("utf-8")) else: show_alert("Command line error.") else: show_alert("Not a Mask project directory.") clear_status_message()
def __call__(self): show_status_message('Regular Expressions Selection') result = show_quicksearch(self._suggest_projects) if result: query, regexp = result try: pattern = re.compile(regexp) except Exception as e: show_alert('Your Regular Expression statement is not valid.' + str(e)) self.__call__() return used = False lines = [""] if os.path.isfile(REGULAREXPRESSIONHIST): with open(REGULAREXPRESSIONHIST, "r") as f: lines = f.readlines() for line in lines: if line.strip() == regexp: used = True if not used: with open(REGULAREXPRESSIONHIST, "a") as f: f.write(regexp + "\n") scheme, currentDir = splitscheme(self.pane.get_path()) for filep in iterdir(self.pane.get_path()): if pattern.search(filep): self.pane.toggle_selection( as_url(currentDir + os.sep + filep, scheme)) clear_status_message()
def __call__(self): show_status_message('Creating a Script...') scriptVars = _GetScriptVars() script, flags = show_prompt("New Script Name?") newScript = scriptVars['directory'] + os.sep + script if os.path.isdir(newScript): show_alert("This is a directory.") else: if os.path.isfile(newScript): show_alert("Script already exists.") else: # # Create the script file. # fp = open(newScript,"w+") fp.write("#!/bin/sh\n\n") fp.write("#\n# The following variable are usable:\n#\n") fp.write("# $FILES_SELECTED - The currently selected file\n") fp.write("# $LEFT_PANE - The directory of the left pane\n") fp.write("# $RIGHT_PANE - The directory of the right pane\n") fp.write("# $CURRENT_DIRECTORY - The currently selected directory\n") fp.write("# $LEFT_PANE_SELECTED_FILE - The currently selected file in the left pane\n") fp.write("# $RIGHT_PANE_SELECTED_FILE - The currently selected file in the right pane\n") fp.close() os.chmod(newScript,0o755) # # Edit the script file. # if self.pane.is_command_visible('open_with_editor'): self.pane.run_command('open_with_editor',{'url': as_url(newScript)}) clear_status_message()
def __call__(self): show_status_message('Launching a Script...') result = show_quicksearch(self._suggest_script) if result: # # Launch the script given. Show the output. # query, script = result # # Get the variables for this plugin # scriptVars = _GetScriptVars() # # Get a list of selected files. # selected_files = self.pane.get_selected_files() if len(selected_files) >= 1 or (len(selected_files) == 0 and self.get_chosen_files()): if len(selected_files) == 0 and self.get_chosen_files(): selected_files.append(self.get_chosen_files()[0]) fileList = '' first = True for file in selected_files: if first: fileList += as_human_readable(file) else: fileList += ',' + as_human_readable(file) # # Set the environment variables for the scripts to use. # os.putenv('CURRENT_DIRECTORY', as_human_readable(self.pane.get_path())) panes = self.pane.window.get_panes() os.putenv('LEFT_PANE', as_human_readable(panes[0].get_path())) path = panes[0].get_file_under_cursor() if path is not None: os.putenv('LEFT_PANE_SELECTED_FILE',as_human_readable(path)) else: os.putenv('LEFT_PANE_SELECTED_FILE',"") os.putenv('RIGHT_PANE', as_human_readable(panes[1].get_path())) path = panes[1].get_file_under_cursor() if path is not None: os.putenv('RIGHT_PANE_SELECTED_FILE',as_human_readable(path)) else: os.putenv('RIGHT_PANE_SELECTED_FILE',"") os.putenv('FILES_SELECTED',fileList) # # Run the script. # Output = run("source " + scriptVars['local_shell'] + "; '" + scriptVars['directory'] + "/" + script + "'",stdout=PIPE,shell=True) if Output.returncode == 0: if scriptVars['show_output']: show_alert(Output.stdout.decode("utf-8")) else: show_alert("Command line error.") clear_status_message()
def __call__(self): show_status_message('Project Selection') result = show_quicksearch(self._suggest_projects) if result: query, projectName = result if os.path.isfile(PROJECTSLIST): with open(PROJECTSLIST, "r") as f: projects = f.readlines() for projectTuple in projects: parts = projectTuple.split('|') if parts[0].strip() == projectName: self.pane.set_path(as_url(parts[1].strip())) clear_status_message()
def __call__(self): show_status_message('Remove Regular Expressions Selection') result = show_quicksearch(self._suggest_projects) if result: query, regexp = result lines = [""] if os.path.isfile(REGULAREXPRESSIONHIST): with open(REGULAREXPRESSIONHIST, "r") as f: lines = f.readlines() with open(REGULAREXPRESSIONHIST, "w") as f: for line in lines: if line.strip() != regexp: f.write(line + "\n") clear_status_message()
def __call__(self): show_status_message('Remove Project Selection') result = show_quicksearch(self._suggest_projects) if result: query, projectName = result if os.path.isfile(PROJECTSLIST): with open(PROJECTSLIST, "r") as f: projects = f.readlines() with open(PROJECTSLIST, "w") as f: for projectTuple in projects: parts = projectTuple.split('|') if parts[0].strip() != projectName: f.write(projectTuple) clear_status_message()
def __call__(self): show_status_message('Remove Favorite Directory') result = show_quicksearch(self._suggest_favorite) if result: query, dirName = result if os.path.isfile(FAVORITELIST): with open(FAVORITELIST, "r") as f: directories = f.readlines() with open(FAVORITELIST, "w") as f: for dirTuple in directories: favName = dirTuple.split('|')[0] if favName != dirName: f.write(dirTuple) clear_status_message()
def __call__(self): show_status_message('Launching a Command Line...') result = show_quicksearch(self._suggest_script) if result: # # Launch the script given. Show the output. # query, script = result if query != '': script = query # # Get the variables for this plugin # scriptVars = _GetScriptVars() # # Save the command line. # scriptVars['command_line_history'].append(script) # # Set the environment variables for the scripts to use. # os.putenv('cd', as_human_readable(self.pane.get_path())) panes = self.pane.window.get_panes() os.putenv('lp', as_human_readable(panes[0].get_path())) os.putenv('lpf',as_human_readable(panes[0].get_file_under_cursor())) os.putenv('rp', as_human_readable(panes[1].get_path())) os.putenv('rpf',as_human_readable(panes[1].get_file_under_cursor())) os.putenv('cf', os.path.basename(as_human_readable(self.pane.get_file_under_cursor()))) # # Run the script. # saveDir = os.getcwd() os.chdir(as_human_readable(self.pane.get_path()) + os.path.sep) scriptLine = "source " + scriptVars['local_shell'] + "; " + script Output = run(scriptLine,stdout=PIPE,shell=True) os.chdir(saveDir) if Output.returncode == 0: if scriptVars['show_output']: show_alert(Output.stdout.decode("utf-8")) scriptVars['command_line_history'] = CleanCommandLineHistory(scriptVars['command_line_history']) _SaveScriptVars(scriptVars) else: show_alert("Command line error.") clear_status_message()
def run(self): _, ext = path.splitext(self.filename) try: mime_type = types_map[ext] except KeyError: mime_type = "application/octet-stream" with open(self.filepath, 'rb') as f: data = f.read() headers = { "Accept": "*/*", "Accept-Encoding": "gzip,deflate", "Accept-Language": "en-US,en;q=0.8", "Connection": "keep-alive", "Content-Length": len(data), "Content-Type": mime_type, "Host": "transfer.sh", "Origin": "https://transfer.sh", "Referer": "https://transfer.sh/", "User-Agent": "Mozilla/5.0", "X_FILENAME": self.filename } url = "https://transfer.sh/" + self.filename req = request.Request(url, data=data, headers=headers, method="PUT") try: show_status_message("ShareFile: uploading file...") with request.urlopen(req, timeout=84600) as resp: if resp.status == 200: body = resp.read() share_link = body.decode('utf-8').strip('\n') msg = template.format(share_link, "") set_text(share_link) else: msg = template.format("Could not upload file", str(resp.status) + " " + resp.reason) clear_status_message() show_alert(msg) except URLError as e: msg = template.format(e.reason, "") show_alert(msg)
def __call__(self): show_status_message('Favorite Selection') result = show_quicksearch(self._suggest_directory) if result: query, dirName = result directories = ["Home|~"] if os.path.isfile(FAVORITELIST): with open(FAVORITELIST, "r") as f: directories = f.readlines() for dirTuple in directories: if '|' in dirTuple: favName, favPath = dirTuple.strip().split('|')[0:2] if favName == dirName: if '://' in favPath: self.pane.set_path(expandDirPath(favPath + os.sep)) else: self.pane.set_path(as_url(expandDirPath(favPath + os.sep))) clear_status_message()
def __call__(self): global DBDATA show_status_message('NotePad (A)ppend or Over(w)rite') npdata = load_json('CopyToNotePad.json') if npdata is None: npdata = dict() npdata['number'] = 3 npdata['save'] = 'a' npappend, result = show_prompt( "The 'a'ppend or 'w'rite:") if not npappend: npappend = 'a' npappend = npappend.lower() if (npappend != 'a') and (npappend != 'w'): npappend = 'a' npdata['save'] = npappend save_json('CopyToNotePad.json', npdata) clear_status_message()
def __call__(self): show_status_message('Getting Services...') result = show_quicksearch(self._suggest_script) if result: # # Launch the script given. Show the output. # query, script = result # # Run the script. # Output = run('', stdout=PIPE, shell=True) if Output.returncode == 0: show_alert(Output.stdout.decode("utf-8")) else: show_alert("Command line error.") clear_status_message()
def __call__(self): show_status_message('Setting the Scripts Directory') selected_files = self.pane.get_selected_files() if len(selected_files) >= 1 or (len(selected_files) == 0 and self.get_chosen_files()): if len(selected_files) == 0 and self.get_chosen_files(): selected_files.append(self.get_chosen_files()[0]) dirName = as_human_readable(selected_files[0]) if os.path.isfile(dirName): # # It's a file, not a directory. Get the directory # name for this file's parent directory. # dirName = os.path.dirname(dirName) scriptDir = _GetScriptVars() scriptDir['directory'] = dirName _SaveScriptVars(scriptDir) else: show_alert("Directory not selected.") clear_status_message()
def __call__(self): global DBDATA show_status_message('NotePad Number') npdata = load_json('CopyToNotePad.json') if npdata is None: npdata = dict() npdata['number'] = 3 npdata['save'] = 'a' npnum, result = show_prompt( "The NotePad Number to use:") if not npnum: npnum = 3 else: npnum = int(npnum) if npnum < 1: npnum = 1 elif npnum > 9: npnum = 9 npdata['number'] = npnum save_json('CopyToNotePad.json', npdata) clear_status_message()
def __call__(self): show_status_message('Editing a Script...') result = show_quicksearch(self._suggest_script) if result: # # Launch the script given. Show the output. # query, script = result # # Get the variables for this plugin # scriptVars = _GetScriptVars() # # Edit the script file. # if self.pane.is_command_visible('open_with_editor'): self.pane.run_command('open_with_editor',{'url': as_url(scriptVars['directory'] + os.sep + script)}) else: show_alert("OpenWithEditor command not found.") clear_status_message()
def __call__(self): show_status_message('Remove Shortener Directory') result = show_quicksearch(self._suggest_shortener) if result: # # Remove the shortener from the list of # shorteners. # query, shortName = result shortenDir = '' if os.path.isfile(SHORTENERLIST): with open(SHORTENERLIST, "r") as f: directories = f.readlines() with open(SHORTENERLIST, "w") as f: for dirTuple in directories: if '|' in dirTuple: shortenerName, shortDir = dirTuple.strip().split('|')[0:2] if shortenerName != shortName: f.write(dirTuple + '\n') else: shortenDir = shortDir # # Remove the shortener from all favorites. # if os.path.isfile(FAVORITELIST): favorties = ["Home|~"] with open(FAVORITELIST, "r") as f: favorties = f.readlines() pattern = re.compile("\{\{" + shortName + "\}\}(.*)$") with open(FAVORITELIST, "w") as f: for fav in favorties: if '|' in fav: favName, favPath = fav.strip().split('|')[0:2] match = pattern.search(favPath) if match: favPath = shortenDir + match.group(1) f.write(favName + "|" + favPath + "\n") clear_status_message()