This repository was archived by the owner on Nov 2, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 41
Expand file tree
/
Copy pathscan_open_tab.py
More file actions
67 lines (59 loc) · 2.25 KB
/
scan_open_tab.py
File metadata and controls
67 lines (59 loc) · 2.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import subprocess
from os import path, makedirs
from platform import system
import sublime_plugin
import sublime
from ..setting import get_setting, SettingObject
from .scan import scan_popen_arg_parser
class ScanOpenTabCommand(sublime_plugin.TextCommand):
def run(self, edit):
"""Command to scan open tab RF file and create db table
Purpose of the command is scan and create the db table
from the currently open tab.
"""
log_file = get_setting(SettingObject.log_file)
makedirs(path.dirname(log_file), exist_ok=True)
open_tab = self.view.file_name()
if self.file_in_workspace(open_tab):
file_ = open(log_file, 'a')
sublime.set_timeout_async(
self.run_single_scan(
open_tab,
file_
),
0
)
file_.close()
else:
message = 'Not able to scan file: {0}'.format(open_tab)
sublime.status_message(message)
def run_single_scan(self, open_tab, log_file):
startupinfo = None
if system() == 'Windows':
startupinfo = subprocess.STARTUPINFO()
startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
p_args = scan_popen_arg_parser('single')
p_args.append('--path_to_file')
p_args.append(open_tab)
p = subprocess.Popen(
p_args,
stderr=subprocess.STDOUT,
stdout=log_file,
startupinfo=startupinfo
)
rc = p.wait()
if not rc == 0:
print('See log file from database directory for details')
raise ValueError('Error in scanning result code: {0}'.format(rc))
message = 'Scaning done with rc: {0}'.format(rc)
sublime.status_message(message)
print(message)
def file_in_workspace(self, open_tab):
workspace = get_setting(SettingObject.workspace)
workspace = path.normcase(workspace)
open_tab = path.normcase(open_tab)
extension = get_setting(SettingObject.extension)
if open_tab.endswith(extension):
return open_tab.startswith(workspace)
else:
return False