Compare commits
No commits in common. "46b534d4478e05581c9679c72ea25453346c8306" and "2b45eea9377437ec0a9cdb76760c2e07acbdbae8" have entirely different histories.
46b534d447
...
2b45eea937
@ -2,7 +2,6 @@
|
|||||||
import asyncio
|
import asyncio
|
||||||
import enum
|
import enum
|
||||||
import threading
|
import threading
|
||||||
import shutil
|
|
||||||
import collections
|
import collections
|
||||||
import datetime
|
import datetime
|
||||||
import functools
|
import functools
|
||||||
@ -23,9 +22,6 @@ import time
|
|||||||
import traceback
|
import traceback
|
||||||
|
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
|
||||||
|
|
||||||
|
|
||||||
def custom_notify(
|
def custom_notify(
|
||||||
title=None,
|
title=None,
|
||||||
msg=None,
|
msg=None,
|
||||||
@ -1060,37 +1056,12 @@ def http_server(argv):
|
|||||||
action='store_true',
|
action='store_true',
|
||||||
default=False,
|
default=False,
|
||||||
)
|
)
|
||||||
parser.add_option(
|
|
||||||
'--force',
|
|
||||||
dest='force',
|
|
||||||
action='store_true',
|
|
||||||
default=False,
|
|
||||||
)
|
|
||||||
parser.add_option(
|
|
||||||
'--token',
|
|
||||||
dest='token',
|
|
||||||
type=str,
|
|
||||||
default=None,
|
|
||||||
)
|
|
||||||
parser.add_option(
|
parser.add_option(
|
||||||
'--port',
|
'--port',
|
||||||
dest='port',
|
dest='port',
|
||||||
type='int',
|
type='int',
|
||||||
default=80,
|
default=80,
|
||||||
)
|
)
|
||||||
parser.add_option(
|
|
||||||
'--no_docker',
|
|
||||||
dest='docker',
|
|
||||||
action='store_false',
|
|
||||||
default=None,
|
|
||||||
)
|
|
||||||
parser.add_option(
|
|
||||||
'-H', '--header',
|
|
||||||
dest='response_headers',
|
|
||||||
type='str',
|
|
||||||
action='append',
|
|
||||||
default=[],
|
|
||||||
)
|
|
||||||
parser.add_option(
|
parser.add_option(
|
||||||
'--host',
|
'--host',
|
||||||
dest='host',
|
dest='host',
|
||||||
@ -1117,185 +1088,46 @@ def http_server(argv):
|
|||||||
raise RuntimeError('invalid ip address %s' % options.host)
|
raise RuntimeError('invalid ip address %s' % options.host)
|
||||||
|
|
||||||
|
|
||||||
if options.docker is None:
|
|
||||||
options.docker = True
|
|
||||||
|
|
||||||
index_section = 'autoindex on;'
|
index_section = 'autoindex on;'
|
||||||
|
|
||||||
if options.public:
|
if options.public:
|
||||||
options.token = 'public'
|
|
||||||
|
|
||||||
location_section = 'location / {%s}' % index_section
|
location_section = 'location / {%s}' % index_section
|
||||||
else:
|
else:
|
||||||
if options.token is None:
|
token = os.urandom(16).hex()
|
||||||
options.token = os.urandom(16).hex()
|
|
||||||
|
|
||||||
if options.docker:
|
|
||||||
DATA_DIR = '/usr/share/nginx'
|
|
||||||
APP_DIR = '/app'
|
|
||||||
CONF_DIR = '/etc/nginx'
|
|
||||||
else:
|
|
||||||
DATA_DIR = '/opt/nginx/%s/data/' % options.token
|
|
||||||
CONF_DIR = '/opt/nginx/%s/conf/' % options.token
|
|
||||||
APP_DIR = os.path.abspath(os.path.curdir)
|
|
||||||
|
|
||||||
if not options.public:
|
|
||||||
if not options.prefix is None:
|
if not options.prefix is None:
|
||||||
path = options.prefix + options.token
|
token = options.prefix + token
|
||||||
else:
|
print(
|
||||||
path = options.token
|
|
||||||
|
|
||||||
logger.info(
|
|
||||||
'access url is http://%s:%d/%s/' % (
|
'access url is http://%s:%d/%s/' % (
|
||||||
options.host,
|
options.host,
|
||||||
options.port,
|
options.port,
|
||||||
path,
|
token,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
assert all([
|
|
||||||
not re.compile(
|
|
||||||
r'^[A-Za-z-]+ [a-z0-9A-Z-\.]+$'
|
|
||||||
).match(o) is None
|
|
||||||
for o in options.response_headers
|
|
||||||
])
|
|
||||||
|
|
||||||
location_section = (
|
location_section = (
|
||||||
'location / {'
|
'location / {'
|
||||||
'deny all;'
|
'deny all;'
|
||||||
'}'
|
'}'
|
||||||
'location /%s/ {'
|
'location /%s/ {'
|
||||||
'alias %s/;'
|
'alias /app/;'
|
||||||
'%s'
|
|
||||||
'%s'
|
'%s'
|
||||||
'}'
|
'}'
|
||||||
) % (
|
) % (token, index_section)
|
||||||
path,
|
subprocess.check_call(
|
||||||
APP_DIR,
|
r'''
|
||||||
'\n'.join([
|
sudo docker run \
|
||||||
'add_header %s;' % o
|
-p %s:%d:80 \
|
||||||
for o in options.response_headers
|
-u root \
|
||||||
]),
|
-it --entrypoint=/bin/bash \
|
||||||
index_section
|
-v $PWD:/app:ro \
|
||||||
)
|
--log-driver none \
|
||||||
|
nginx:latest \
|
||||||
if options.docker:
|
-c 'echo "server{listen 80; charset UTF-8; root /app; %s}" > /etc/nginx/conf.d/default.conf; nginx -g "daemon off;"'
|
||||||
subprocess.check_call(
|
''' % (
|
||||||
r'''
|
options.host,
|
||||||
sudo docker run \
|
options.port,
|
||||||
-p %s:%d:80 \
|
location_section,
|
||||||
-u root \
|
),
|
||||||
-it --entrypoint=/bin/bash \
|
shell=True)
|
||||||
-v $PWD:%s:ro \
|
|
||||||
--log-driver none \
|
|
||||||
nginx:latest \
|
|
||||||
-c 'echo "server{listen 80; charset UTF-8; root /app; %s}" > /etc/nginx/conf.d/default.conf; nginx -g "daemon off;"'
|
|
||||||
''' % (
|
|
||||||
options.host,
|
|
||||||
options.port,
|
|
||||||
APP_DIR,
|
|
||||||
location_section,
|
|
||||||
),
|
|
||||||
shell=True
|
|
||||||
)
|
|
||||||
else:
|
|
||||||
if os.path.exists(CONF_DIR):
|
|
||||||
assert options.force
|
|
||||||
shutil.rmtree(CONF_DIR)
|
|
||||||
|
|
||||||
if os.path.exists(DATA_DIR):
|
|
||||||
assert options.force
|
|
||||||
shutil.rmtree(DATA_DIR)
|
|
||||||
|
|
||||||
os.makedirs(CONF_DIR, exist_ok=True)
|
|
||||||
os.makedirs(
|
|
||||||
os.path.join(
|
|
||||||
CONF_DIR,
|
|
||||||
'conf.d',
|
|
||||||
),
|
|
||||||
exist_ok=True
|
|
||||||
)
|
|
||||||
os.makedirs(DATA_DIR, exist_ok=True)
|
|
||||||
|
|
||||||
with io.open(
|
|
||||||
os.path.join(CONF_DIR, 'nginx.conf'),
|
|
||||||
'w'
|
|
||||||
) as f:
|
|
||||||
f.write(r'''
|
|
||||||
|
|
||||||
events {
|
|
||||||
multi_accept on;
|
|
||||||
worker_connections 32;
|
|
||||||
}
|
|
||||||
|
|
||||||
http {
|
|
||||||
include /etc/nginx/mime.types;
|
|
||||||
default_type application/octet-stream;
|
|
||||||
expires off;
|
|
||||||
open_file_cache off;
|
|
||||||
|
|
||||||
log_format main
|
|
||||||
'[$time_local][$remote_addr, $http_x_forwarded_for, $t1, $server_name]'
|
|
||||||
'[$request_length,$bytes_sent,$request_time]'
|
|
||||||
'[$status][$request]'
|
|
||||||
'[$http_user_agent][$http_referer]';
|
|
||||||
|
|
||||||
access_log /dev/null combined;
|
|
||||||
access_log /dev/stderr main;
|
|
||||||
|
|
||||||
include %s/conf.d/*.conf;
|
|
||||||
|
|
||||||
map $http_upgrade $connection_upgrade {
|
|
||||||
default upgrade;
|
|
||||||
'' close;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
''' % CONF_DIR)
|
|
||||||
|
|
||||||
with io.open(
|
|
||||||
os.path.join(
|
|
||||||
CONF_DIR,
|
|
||||||
'conf.d',
|
|
||||||
'default.conf',
|
|
||||||
),
|
|
||||||
'w',
|
|
||||||
) as f:
|
|
||||||
f.write(r'''
|
|
||||||
server {
|
|
||||||
server_name %s;
|
|
||||||
listen %d;
|
|
||||||
charset UTF-8;
|
|
||||||
client_max_body_size 2K;
|
|
||||||
|
|
||||||
set $t1 $remote_addr;
|
|
||||||
if ($http_x_forwarded_for)
|
|
||||||
{
|
|
||||||
set $t1 $http_x_forwarded_for;
|
|
||||||
}
|
|
||||||
|
|
||||||
root %s;
|
|
||||||
%s
|
|
||||||
}
|
|
||||||
''' % (
|
|
||||||
options.host,
|
|
||||||
options.port,
|
|
||||||
DATA_DIR,
|
|
||||||
location_section,
|
|
||||||
))
|
|
||||||
|
|
||||||
sys.stderr.flush()
|
|
||||||
sys.stdout.flush()
|
|
||||||
|
|
||||||
os.execv(
|
|
||||||
'/usr/sbin/nginx',
|
|
||||||
[
|
|
||||||
'/usr/sbin/nginx',
|
|
||||||
'-c',
|
|
||||||
os.path.join(CONF_DIR, 'nginx.conf'),
|
|
||||||
'-p', DATA_DIR,
|
|
||||||
'-g', 'daemon off;',
|
|
||||||
],
|
|
||||||
)
|
|
||||||
|
|
||||||
def pass_ssh_osx(argv):
|
def pass_ssh_osx(argv):
|
||||||
assert isinstance(argv, list) and all([isinstance(o, str) for o in argv])
|
assert isinstance(argv, list) and all([isinstance(o, str) for o in argv])
|
||||||
@ -3364,7 +3196,6 @@ def media_keys(argv):
|
|||||||
|
|
||||||
def commands_cli():
|
def commands_cli():
|
||||||
logging.getLogger().setLevel(logging.INFO)
|
logging.getLogger().setLevel(logging.INFO)
|
||||||
logger.setLevel(logging.INFO)
|
|
||||||
|
|
||||||
msg = None
|
msg = None
|
||||||
|
|
||||||
|
@ -33,50 +33,10 @@ def f5_1(pattern, flags, info):
|
|||||||
#print([pattern, flags, info])
|
#print([pattern, flags, info])
|
||||||
completed_process = None
|
completed_process = None
|
||||||
|
|
||||||
options = dict(
|
|
||||||
recursive=False,
|
|
||||||
ext=[],
|
|
||||||
)
|
|
||||||
|
|
||||||
#print('fuck')
|
|
||||||
if b'r' in flags:
|
|
||||||
while True:
|
|
||||||
ext_m = re.compile('^.([^\,]+),(.*)$').match(pattern)
|
|
||||||
|
|
||||||
if pattern[:3] in [r'\r,']:
|
|
||||||
options['recursive'] = True
|
|
||||||
pattern = pattern[3:]
|
|
||||||
elif not ext_m is None:
|
|
||||||
options['ext'].append(
|
|
||||||
ext_m[1]
|
|
||||||
)
|
|
||||||
pattern = ext_m[2]
|
|
||||||
else:
|
|
||||||
break
|
|
||||||
|
|
||||||
print([flags, pattern, options,])
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
git_cmd = [
|
completed_process = subprocess.run([
|
||||||
'git', 'grep',
|
'git', 'grep', '-n', '-P', pattern,
|
||||||
'-n',
|
], capture_output=True,)
|
||||||
]
|
|
||||||
|
|
||||||
if options['recursive']:
|
|
||||||
git_cmd.append('--recurse-submodules')
|
|
||||||
|
|
||||||
git_cmd.extend(['-P', pattern])
|
|
||||||
|
|
||||||
if len(options['ext']) > 0:
|
|
||||||
git_cmd.extend(['--', *[
|
|
||||||
'**/*%s' % o
|
|
||||||
for o in options['ext']
|
|
||||||
]])
|
|
||||||
|
|
||||||
completed_process = subprocess.run(
|
|
||||||
git_cmd,
|
|
||||||
capture_output=True,
|
|
||||||
)
|
|
||||||
assert (
|
assert (
|
||||||
completed_process.returncode == 0 or
|
completed_process.returncode == 0 or
|
||||||
(
|
(
|
||||||
|
@ -19,7 +19,6 @@ set backspace=indent,eol,start
|
|||||||
|
|
||||||
set mouse=a
|
set mouse=a
|
||||||
au FileType netrw nmap <buffer> <LeftMouse> <LeftMouse> <CR>
|
au FileType netrw nmap <buffer> <LeftMouse> <LeftMouse> <CR>
|
||||||
au FocusLost * silent! wa
|
|
||||||
|
|
||||||
set term=xterm-256color
|
set term=xterm-256color
|
||||||
|
|
||||||
@ -29,34 +28,12 @@ set hls
|
|||||||
colorscheme morning
|
colorscheme morning
|
||||||
hi MatchParen guifg=white guibg=black gui=NONE ctermfg=1 ctermbg=0
|
hi MatchParen guifg=white guibg=black gui=NONE ctermfg=1 ctermbg=0
|
||||||
|
|
||||||
function! MakeSession()
|
|
||||||
let b:sessiondir = '.vim/'
|
|
||||||
if (filewritable(b:sessiondir) != 2)
|
|
||||||
exe 'silent !mkdir -p ' b:sessiondir
|
|
||||||
redraw!
|
|
||||||
endif
|
|
||||||
let b:filename = b:sessiondir . '/session.vim'
|
|
||||||
exe "mksession! " . b:filename
|
|
||||||
endfunction
|
|
||||||
|
|
||||||
function! LoadSession()
|
|
||||||
let b:sessiondir = '.vim/'
|
|
||||||
let b:sessionfile = b:sessiondir . "/session.vim"
|
|
||||||
if (filereadable(b:sessionfile))
|
|
||||||
exe 'source ' b:sessionfile
|
|
||||||
else
|
|
||||||
echo "No session loaded."
|
|
||||||
endif
|
|
||||||
endfunction
|
|
||||||
|
|
||||||
|
|
||||||
map <Leader>w <C-w>
|
map <Leader>w <C-w>
|
||||||
map <Leader>wo :py3 print('fuck')<CR>
|
map <Leader>wo :py3 print('fuck')<CR>
|
||||||
map <Leader>z :wqa<CR>
|
map <Leader>z :wqa<CR>
|
||||||
map <Leader>m :py3 f1()<CR>
|
map <Leader>m :py3 f1()<CR>
|
||||||
map <Leader>r :redraw!<CR>
|
map <Leader>r :redraw!<CR>
|
||||||
map <Leader>s :call MakeSession()<CR>
|
|
||||||
map <Leader>l :call LoadSession()
|
|
||||||
map <Leader>cq :cq<CR>
|
map <Leader>cq :cq<CR>
|
||||||
map <Leader>f2 :py3 f2()<CR>
|
map <Leader>f2 :py3 f2()<CR>
|
||||||
map <Leader>f3 :source ~/.vimrc<CR>:echo 'reloaded'<CR>
|
map <Leader>f3 :source ~/.vimrc<CR>:echo 'reloaded'<CR>
|
||||||
|
Loading…
Reference in New Issue
Block a user