Browse Source

time to work on opener.py

master
Raphael Roberts 7 years ago
parent
commit
8eba4a58f5
  1. 25
      ext_open/opener.py
  2. 4
      ext_open/searcher.py
  3. 12
      ext_open/update.py

25
ext_open/opener.py

@ -1,11 +1,11 @@
import subprocess
from binaryornot.check import is_binary
from config import config
import os
import re
import shlex
if __name__ == "__main__":
__file__ = os.getcwd()
EDITOR_PATH = os.path.expandvars(r'%programfiles%\Notepad++\notepad++.exe')
import subprocess
EDITOR_PATH = config.getpath('global','editor')
EXT = re.compile(r'\.\w+$')
def get_ext(file):
match = EXT.search(file)
@ -13,32 +13,35 @@ def get_ext(file):
return match.group(0)
def edit(path,params=[]):
call_chain = [EDITOR_PATH] + params
params = list(map(os.path.expandvars,params))
call_chain = shlex.split(EDITOR_PATH)
if not is_binary(path):
call_chain.append(path)
subprocess.call(call_chain)
def standalone(path,params=[],windowless =False,cwd = None):
path2windowless = os.path.join(os.path.dirname(__file__),'windowless.vbs')
if __name__ == "__main__":
path2windowless = 'windowless.vbs'
else:
path2windowless = os.path.join(os.path.dirname(__file__),'windowless.vbs')
params = list(map(os.path.expandvars,params))
if not cwd:
cwd = os.path.dirname(path)
else:
cwd = os.path.expandvars(cwd)
if windowless:
cmd = subprocess.list2cmdline([path]+params).replace('"','~')
print(cmd)
cmd = cmd = subprocess.list2cmdline([path]+params).replace('"','~')
subprocess.check_output(['cscript.exe',path2windowless,cmd,cwd])
else:
subprocess.Popen([path]+params,cwd=cwd)
def dependant(path,params=[],mode = 'execute'):
params = list(map(os.path.expandvars,params))
ext = get_ext(path)
if ext:
handler = config.getpath(ext,mode)
handler = shlex.split(handler)
ext = ext[1:]
handler = shlex.split(config.getpath(ext,mode))
args = handler+[path]+params
subprocess.Popen(args)

4
ext_open/searcher.py

@ -23,7 +23,7 @@ def regexp(expr, item,case):
return (1 if re.search(expr,item) is not None else 0)
else:
return (1 if re.search(expr,item,flags=re.I) is not None else 0)
def _in(expr,item,case):
if case:
return (1 if expr in item else 0)
@ -56,7 +56,7 @@ class Searcher:
@property
def updating(self):
return update.get_updating(self.ext,self.cur)
def update(self,update_mtimes=False):
if not self.updating:
args = ['python',UPDATE_PY,self.ext]

12
ext_open/update.py

@ -60,7 +60,7 @@ def set_updating(ext,con,updating=True):
def get_updating(ext,cur):
cur.execute('SELECT status FROM update_status WHERE ext=?;',[ext])
return cur.fetchone()[0] == 1
def update(ext,do_update_mtimes):
set_updating(ext,ext_database)
cur = ext_database.cursor()
@ -69,28 +69,28 @@ def update(ext,do_update_mtimes):
cur.execute('SELECT MAX(update_time) FROM updates WHERE ext=?;',[ext])
last_update = cur.fetchone()[0]
_time = int(time.time())
params = (
'.'+ext,
config.getpaths(ext,'paths'),
last_update,
do_update_mtimes
)
files = _update(*params)
count = 0
for count,row in enumerate(files):
row.append(_time)
cur.execute('INSERT OR IGNORE INTO {} VALUES (?,?,?);'.format(ext),row)
count += 1
if count % c == 0:
ext_database.commit()
cur.execute('INSERT INTO updates VALUES (?, ?, ?);',[ext,_time,count+1])
ext_database.commit()
set_updating(ext,ext_database,False)
except Exception as e:
set_updating(ext,ext_database,False)
traceback.print_exc()

Loading…
Cancel
Save