Merge branch 'master' of ssh://bitbucket.org/MoonQ/q-tools
This commit is contained in:
@@ -22,7 +22,7 @@ Many of the tools use common unix tools. Some extra tools are required. Here are
|
|||||||
the installation commands.
|
the installation commands.
|
||||||
|
|
||||||
```
|
```
|
||||||
sudo apt-get install git sqlite3 python python-magic python-pip python-gtk2 sc \
|
sudo apt-get install git sqlite3 python3 python3-magic python3-pip python3-gtk2 sc \
|
||||||
gnuplot wget vim rsync curl pv
|
gnuplot wget vim rsync curl pv
|
||||||
pip2 install csvkit ncsv
|
pip2 install csvkit ncsv
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
import sys,os
|
import sys,os
|
||||||
sys.path.append(os.path.realpath(os.path.join(os.path.dirname(__file__),
|
sys.path.append(os.path.realpath(os.path.join(os.path.dirname(__file__),
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python3
|
||||||
import curses
|
import curses
|
||||||
import os,sys
|
import os,sys
|
||||||
import time,datetime
|
import time,datetime
|
||||||
|
|||||||
@@ -190,8 +190,9 @@ if method == "regexp":
|
|||||||
(outFolders, uniqlabel, matcher) = regexmatches(inFiles, options)
|
(outFolders, uniqlabel, matcher) = regexmatches(inFiles, options)
|
||||||
input("correct?")
|
input("correct?")
|
||||||
else:
|
else:
|
||||||
|
padding = "{:0" + str(len(str(options.n))) + "d}"
|
||||||
for x in range(options.n):
|
for x in range(options.n):
|
||||||
outFolders.append(os.path.join(options.path, "folder" + str(x + 1)))
|
outFolders.append(os.path.join(options.path, ("folder-" + padding).format(x + 1)))
|
||||||
|
|
||||||
for x in outFolders:
|
for x in outFolders:
|
||||||
if not os.path.isdir(x):
|
if not os.path.isdir(x):
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ function listfiles() {
|
|||||||
}
|
}
|
||||||
function count_size() {
|
function count_size() {
|
||||||
|
|
||||||
cat - | python -c "import sys
|
cat - | python3 -c "import sys
|
||||||
def sizeof_fmt(num, suffix='B'):
|
def sizeof_fmt(num, suffix='B'):
|
||||||
for unit in ['','K','M','G','T','P','E','Z']:
|
for unit in ['','K','M','G','T','P','E','Z']:
|
||||||
if num < 1024.0:
|
if num < 1024.0:
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ function listfolders() {
|
|||||||
}
|
}
|
||||||
function count_size() {
|
function count_size() {
|
||||||
|
|
||||||
cat - | python -c "import sys
|
cat - | python3 -c "import sys
|
||||||
def sizeof_fmt(num, suffix='B'):
|
def sizeof_fmt(num, suffix='B'):
|
||||||
for unit in ['','K','M','G','T','P','E','Z']:
|
for unit in ['','K','M','G','T','P','E','Z']:
|
||||||
if num < 1024.0:
|
if num < 1024.0:
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python3
|
||||||
import sys
|
import sys
|
||||||
import scipy.misc
|
import scipy.misc
|
||||||
import numpy as n
|
import numpy as n
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ Usage: file-enumerate [-k] [-p #] [-o folder]
|
|||||||
-p Pad numbers, defaults to 4
|
-p Pad numbers, defaults to 4
|
||||||
-o Output folder name, default: enumerated
|
-o Output folder name, default: enumerated
|
||||||
-c Copy instead of hard link
|
-c Copy instead of hard link
|
||||||
|
-i Offset. start from number (default 1)
|
||||||
'
|
'
|
||||||
exit
|
exit
|
||||||
}
|
}
|
||||||
@@ -18,6 +19,7 @@ keep=false
|
|||||||
pad=4
|
pad=4
|
||||||
output=enumerated
|
output=enumerated
|
||||||
hardlink="-l"
|
hardlink="-l"
|
||||||
|
offset=1
|
||||||
for (( i=1; i<=$#; i++ )); do
|
for (( i=1; i<=$#; i++ )); do
|
||||||
j=$(( i + 1 ))
|
j=$(( i + 1 ))
|
||||||
[[ "${!i}" = "-h" ]] && _help
|
[[ "${!i}" = "-h" ]] && _help
|
||||||
@@ -26,12 +28,14 @@ for (( i=1; i<=$#; i++ )); do
|
|||||||
[[ "${!i}" = "-k" ]] && keep=true
|
[[ "${!i}" = "-k" ]] && keep=true
|
||||||
[[ "${!i}" = "-p" ]] && { pad=${!j}; i=$(( i + 1 )); }
|
[[ "${!i}" = "-p" ]] && { pad=${!j}; i=$(( i + 1 )); }
|
||||||
[[ "${!i}" = "-o" ]] && { output=${!j}; i=$(( i + 1 )); }
|
[[ "${!i}" = "-o" ]] && { output=${!j}; i=$(( i + 1 )); }
|
||||||
|
[[ "${!i}" = "-i" ]] && { offset=${!j}; i=$(( i + 1 )); }
|
||||||
done
|
done
|
||||||
|
|
||||||
printf -v padstr "%%0%dd" $pad
|
printf -v padstr "%%0%dd" $pad
|
||||||
|
|
||||||
_drive() {
|
_drive() {
|
||||||
ls -1p | grep -v "/$" | sort -V | cat -n | while read n f; do
|
ls -1p | grep -v "/$" | sort -V | cat -n | while read n f; do
|
||||||
|
n=$(( n + $offset - 1 ))
|
||||||
printf -v padded $padstr $n
|
printf -v padded $padstr $n
|
||||||
if [[ $keep = true ]]; then
|
if [[ $keep = true ]]; then
|
||||||
printf -v outname "%s.%s" "$padded" "$f"
|
printf -v outname "%s.%s" "$padded" "$f"
|
||||||
|
|||||||
@@ -1,5 +1,12 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python3
|
||||||
# -*- coding: latin-1 -*-
|
# -*- coding: latin-1 -*-
|
||||||
|
from __future__ import division
|
||||||
|
from __future__ import print_function
|
||||||
|
from future import standard_library
|
||||||
|
standard_library.install_aliases()
|
||||||
|
from builtins import zip
|
||||||
|
from builtins import str
|
||||||
|
from past.utils import old_div
|
||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
@@ -8,7 +15,8 @@ import subprocess
|
|||||||
import hashlib
|
import hashlib
|
||||||
import magic
|
import magic
|
||||||
from argparse import ArgumentParser
|
from argparse import ArgumentParser
|
||||||
import ConfigParser,StringIO,io
|
import configparser
|
||||||
|
import io
|
||||||
import datetime
|
import datetime
|
||||||
|
|
||||||
SQLFILE='list_of_files.sqlite'
|
SQLFILE='list_of_files.sqlite'
|
||||||
@@ -67,7 +75,7 @@ def setup_options():
|
|||||||
BADDIRS.extend(options.exclude)
|
BADDIRS.extend(options.exclude)
|
||||||
if options.duplicate:
|
if options.duplicate:
|
||||||
options.add=not options.add
|
options.add=not options.add
|
||||||
options.startpath=unicode(options.startpath, "UTF-8")
|
|
||||||
options.sqlpath=os.path.dirname(os.path.realpath(options.sqlfile))
|
options.sqlpath=os.path.dirname(os.path.realpath(options.sqlfile))
|
||||||
return options
|
return options
|
||||||
|
|
||||||
@@ -78,7 +86,7 @@ def add_recurse(options):
|
|||||||
db=conn.cursor()
|
db=conn.cursor()
|
||||||
prev_path_len=0
|
prev_path_len=0
|
||||||
for path,dirs,files in os.walk(options.startpath,followlinks=options.symlinks):
|
for path,dirs,files in os.walk(options.startpath,followlinks=options.symlinks):
|
||||||
sys.stdout.write(("\r%s%s"%(filename_join(path,".",options),(prev_path_len-len(path))*' ')).encode('utf-8'))
|
sys.stdout.write(("\r%s%s"%(filename_join(path,".",options),(prev_path_len-len(path))*' ')))
|
||||||
prev_path_len=len(path)
|
prev_path_len=len(path)
|
||||||
dirs=clean_dirs(dirs)
|
dirs=clean_dirs(dirs)
|
||||||
dirs.sort()
|
dirs.sort()
|
||||||
@@ -218,11 +226,11 @@ def createdb(options):
|
|||||||
object TEXT)')
|
object TEXT)')
|
||||||
conn.commit()
|
conn.commit()
|
||||||
|
|
||||||
config = ConfigParser.RawConfigParser()
|
config = configparser.RawConfigParser()
|
||||||
config.add_section("General")
|
config.add_section("General")
|
||||||
config.set("General","Relative",str(options.relative))
|
config.set("General","Relative",str(options.relative))
|
||||||
config.set("General","FullFile",str(options.fullfile))
|
config.set("General","FullFile",str(options.fullfile))
|
||||||
store=StringIO.StringIO()
|
store=io.StringIO()
|
||||||
config.write(store)
|
config.write(store)
|
||||||
db.execute("INSERT INTO config (object) values (?)",(store.getvalue(),))
|
db.execute("INSERT INTO config (object) values (?)",(store.getvalue(),))
|
||||||
conn.commit()
|
conn.commit()
|
||||||
@@ -317,7 +325,7 @@ def get_folder_contents(db,path):
|
|||||||
db.execute("SELECT file FROM list where file LIKE ?",(path+'%',))
|
db.execute("SELECT file FROM list where file LIKE ?",(path+'%',))
|
||||||
for row in db:
|
for row in db:
|
||||||
try:
|
try:
|
||||||
base=row[0].decode('utf-8').replace(path,'',1)
|
base=row[0].replace(path,'',1)
|
||||||
except UnicodeDecodeError:
|
except UnicodeDecodeError:
|
||||||
print(row[0]+" is giving me trouble.")
|
print(row[0]+" is giving me trouble.")
|
||||||
try:
|
try:
|
||||||
@@ -337,7 +345,7 @@ def get_md5(filename,fullfile=False):
|
|||||||
anim_i=0
|
anim_i=0
|
||||||
anim_len=len(ANIM)
|
anim_len=len(ANIM)
|
||||||
block_size=2**24
|
block_size=2**24
|
||||||
percents_per_block=100/(float(fsize)/block_size)
|
percents_per_block=old_div(100,(old_div(float(fsize),block_size)))
|
||||||
md5 = hashlib.md5()
|
md5 = hashlib.md5()
|
||||||
with open(filename,'rb') as f:
|
with open(filename,'rb') as f:
|
||||||
for chunk in iter(lambda: f.read(block_size), b''):
|
for chunk in iter(lambda: f.read(block_size), b''):
|
||||||
@@ -425,7 +433,7 @@ def humanize_size(size,precision=1):
|
|||||||
defPrecision=0
|
defPrecision=0
|
||||||
while size > 1024:
|
while size > 1024:
|
||||||
suffixIndex += 1 #increment the index of the suffix
|
suffixIndex += 1 #increment the index of the suffix
|
||||||
size = size/1024.0 #apply the division
|
size = old_div(size,1024.0) #apply the division
|
||||||
defPrecision=precision
|
defPrecision=precision
|
||||||
return "%.*f%s"%(defPrecision,size,suffixes[suffixIndex])
|
return "%.*f%s"%(defPrecision,size,suffixes[suffixIndex])
|
||||||
|
|
||||||
@@ -510,7 +518,7 @@ def stored_options(options):
|
|||||||
store=""
|
store=""
|
||||||
for row in db:
|
for row in db:
|
||||||
store+=row[0]+'\n'
|
store+=row[0]+'\n'
|
||||||
config = ConfigParser.RawConfigParser()
|
config = configparser.RawConfigParser()
|
||||||
config.readfp(io.BytesIO(store))
|
config.readfp(io.BytesIO(store))
|
||||||
options.relative=config.getboolean("General","Relative")
|
options.relative=config.getboolean("General","Relative")
|
||||||
options.fullfile=config.getboolean("General","FullFile")
|
options.fullfile=config.getboolean("General","FullFile")
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python3
|
||||||
import sys,os
|
import sys,os
|
||||||
from Tkinter import *
|
from Tkinter import *
|
||||||
from PIL import Image,ImageTk, ImageDraw
|
from PIL import Image,ImageTk, ImageDraw
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python3
|
||||||
# coding=UTF-8
|
# coding=UTF-8
|
||||||
|
from __future__ import print_function
|
||||||
import sys
|
import sys
|
||||||
import os,time,datetime
|
import os,time,datetime
|
||||||
import sqlite3
|
import sqlite3
|
||||||
@@ -105,9 +106,9 @@ def list_URLs(options):
|
|||||||
db.execute("SELECT * FROM list ORDER BY id")
|
db.execute("SELECT * FROM list ORDER BY id")
|
||||||
else:
|
else:
|
||||||
db.execute("SELECT * FROM list WHERE exitcode > 0 ORDER BY id")
|
db.execute("SELECT * FROM list WHERE exitcode > 0 ORDER BY id")
|
||||||
print "EC\tSRC\tTGT"
|
print("EC\tSRC\tTGT")
|
||||||
for row in db:
|
for row in db:
|
||||||
print "%s\t%s\t%s" % (row[3],row[1],row[2])
|
print("%s\t%s\t%s" % (row[3],row[1],row[2]))
|
||||||
return
|
return
|
||||||
|
|
||||||
def start_sync(options):
|
def start_sync(options):
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
from argparse import ArgumentParser
|
from argparse import ArgumentParser
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ function gcd() {
|
|||||||
darwin*) QCDPATH=$( dirname $( realpath ${BASH_SOURCE[0]} ) ) ;;
|
darwin*) QCDPATH=$( dirname $( realpath ${BASH_SOURCE[0]} ) ) ;;
|
||||||
*) QCDPATH=$( dirname $( readlink -f ${BASH_SOURCE[0]} ) ) ;;
|
*) QCDPATH=$( dirname $( readlink -f ${BASH_SOURCE[0]} ) ) ;;
|
||||||
esac
|
esac
|
||||||
cdto=$( python "$QCDPATH"/files/gcd-findmatch.py "$@" )
|
cdto=$( python3 "$QCDPATH"/files/gcd-findmatch.py "$@" )
|
||||||
[[ -z "$cdto" ]] && return
|
[[ -z "$cdto" ]] && return
|
||||||
\cd "$cdto"
|
\cd "$cdto"
|
||||||
} # gcd ends
|
} # gcd ends
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python3
|
||||||
#
|
#
|
||||||
# Copyright 2015 Ville Rantanen
|
# Copyright 2015 Ville Rantanen
|
||||||
#
|
#
|
||||||
@@ -17,6 +17,7 @@
|
|||||||
#
|
#
|
||||||
|
|
||||||
'''simple head for tsv/csv files.'''
|
'''simple head for tsv/csv files.'''
|
||||||
|
from __future__ import print_function
|
||||||
|
|
||||||
__author__ = "Ville Rantanen <ville.q.rantanen@gmail.com>"
|
__author__ = "Ville Rantanen <ville.q.rantanen@gmail.com>"
|
||||||
|
|
||||||
@@ -82,12 +83,13 @@ def main():
|
|||||||
behead(sys.stdin, opts)
|
behead(sys.stdin, opts)
|
||||||
for fi in opts.file:
|
for fi in opts.file:
|
||||||
behead(open(fi,'r'), opts)
|
behead(open(fi,'r'), opts)
|
||||||
except IOError as (n,e):
|
except IOError as xxx_todo_changeme:
|
||||||
|
(n,e) = xxx_todo_changeme.args
|
||||||
if n==32:
|
if n==32:
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
import traceback
|
import traceback
|
||||||
print traceback.format_exc()
|
print(traceback.format_exc())
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python3
|
||||||
#
|
#
|
||||||
# Copyright 2015 Ville Rantanen
|
# Copyright 2015 Ville Rantanen
|
||||||
#
|
#
|
||||||
@@ -17,6 +17,7 @@
|
|||||||
#
|
#
|
||||||
|
|
||||||
'''simple tail for tsv/csv files.'''
|
'''simple tail for tsv/csv files.'''
|
||||||
|
from __future__ import print_function
|
||||||
|
|
||||||
__author__ = "Ville Rantanen <ville.q.rantanen@gmail.com>"
|
__author__ = "Ville Rantanen <ville.q.rantanen@gmail.com>"
|
||||||
|
|
||||||
@@ -86,12 +87,13 @@ def main():
|
|||||||
tail(sys.stdin, opts)
|
tail(sys.stdin, opts)
|
||||||
for fi in opts.file:
|
for fi in opts.file:
|
||||||
tail(open(fi,'r'), opts)
|
tail(open(fi,'r'), opts)
|
||||||
except IOError as (n,e):
|
except IOError as xxx_todo_changeme:
|
||||||
|
(n,e) = xxx_todo_changeme.args
|
||||||
if n==32:
|
if n==32:
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
import traceback
|
import traceback
|
||||||
print traceback.format_exc()
|
print(traceback.format_exc())
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python3
|
||||||
#
|
#
|
||||||
# Copyright 2017 Ville Rantanen
|
# Copyright 2017 Ville Rantanen
|
||||||
#
|
#
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ sqlfile="$1"
|
|||||||
}
|
}
|
||||||
VIEWER=ncsv
|
VIEWER=ncsv
|
||||||
which ncsv > /dev/null || {
|
which ncsv > /dev/null || {
|
||||||
VIEWER="tabview -"
|
VIEWER="tabview -w max -"
|
||||||
which tabview > /dev/null || VIEWER="cat -"
|
which tabview > /dev/null || VIEWER="cat -"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python3
|
||||||
#
|
#
|
||||||
# Copyright 2017 Ville Rantanen
|
# Copyright 2017 Ville Rantanen
|
||||||
#
|
#
|
||||||
@@ -17,7 +17,14 @@
|
|||||||
#
|
#
|
||||||
|
|
||||||
'''TSV 2 SC convert.'''
|
'''TSV 2 SC convert.'''
|
||||||
|
from __future__ import division
|
||||||
|
from __future__ import print_function
|
||||||
|
|
||||||
|
from builtins import chr
|
||||||
|
from builtins import str
|
||||||
|
from builtins import range
|
||||||
|
from builtins import object
|
||||||
|
from past.utils import old_div
|
||||||
__author__ = "Ville Rantanen"
|
__author__ = "Ville Rantanen"
|
||||||
|
|
||||||
__version__ = "0.2"
|
__version__ = "0.2"
|
||||||
@@ -45,7 +52,7 @@ def which(program):
|
|||||||
|
|
||||||
return None
|
return None
|
||||||
|
|
||||||
class SCWriter:
|
class SCWriter(object):
|
||||||
""" Class for writing SC files.
|
""" Class for writing SC files.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
@@ -93,7 +100,7 @@ class SCWriter:
|
|||||||
''' Returns a column alphabet from column number '''
|
''' Returns a column alphabet from column number '''
|
||||||
o=chr(column+64+1)
|
o=chr(column+64+1)
|
||||||
if column>25:
|
if column>25:
|
||||||
return self.column_to_alpha((column / 26) -1) + self.column_to_alpha(column % 26);
|
return self.column_to_alpha((old_div(column, 26)) -1) + self.column_to_alpha(column % 26);
|
||||||
return o
|
return o
|
||||||
|
|
||||||
def write_row(self,row):
|
def write_row(self,row):
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python3
|
||||||
#
|
#
|
||||||
# Copyright 2014 Ville Rantanen
|
# Copyright 2014 Ville Rantanen
|
||||||
#
|
#
|
||||||
@@ -17,7 +17,6 @@
|
|||||||
#
|
#
|
||||||
|
|
||||||
'''SC based CSV editor.'''
|
'''SC based CSV editor.'''
|
||||||
|
|
||||||
__author__ = "Ville Rantanen"
|
__author__ = "Ville Rantanen"
|
||||||
|
|
||||||
__version__ = "0.2"
|
__version__ = "0.2"
|
||||||
@@ -46,7 +45,7 @@ def which(program):
|
|||||||
|
|
||||||
return None
|
return None
|
||||||
|
|
||||||
class SCReader:
|
class SCReader(object):
|
||||||
""" Class for reading SC files.
|
""" Class for reading SC files.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
@@ -82,15 +81,15 @@ class SCReader:
|
|||||||
return int(o-1)
|
return int(o-1)
|
||||||
|
|
||||||
|
|
||||||
def next(self):
|
def __next__(self):
|
||||||
''' Returns the next row in the table, three items: column, row, content'''
|
''' Returns the next row in the table, three items: column, row, content'''
|
||||||
return self._parse_row(self.reader.next())
|
return self._parse_row(next(self.reader))
|
||||||
|
|
||||||
def __iter__(self):
|
def __iter__(self):
|
||||||
for row in self.file:
|
for row in self.file:
|
||||||
yield self._parse_row(row)
|
yield self._parse_row(row)
|
||||||
|
|
||||||
class SCWriter:
|
class SCWriter(object):
|
||||||
""" Class for writing SC files.
|
""" Class for writing SC files.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
@@ -127,7 +126,7 @@ class SCWriter:
|
|||||||
''' Returns a column alphabet from column number '''
|
''' Returns a column alphabet from column number '''
|
||||||
o=chr(column+64+1)
|
o=chr(column+64+1)
|
||||||
if column>25:
|
if column>25:
|
||||||
return self.column_to_alpha((column / 26) -1) + self.column_to_alpha(column % 26);
|
return self.column_to_alpha((column // 26) -1) + self.column_to_alpha(column % 26)
|
||||||
return o
|
return o
|
||||||
|
|
||||||
def write_row(self,row):
|
def write_row(self,row):
|
||||||
@@ -250,7 +249,7 @@ subprocess.call(['sc',f_sc])
|
|||||||
process = subprocess.Popen(['sc','-v','-P','%',f_sc], shell=False, stdout=subprocess.PIPE)
|
process = subprocess.Popen(['sc','-v','-P','%',f_sc], shell=False, stdout=subprocess.PIPE)
|
||||||
f_cs_tmp_w=open(f_sc_tmp,'wt')
|
f_cs_tmp_w=open(f_sc_tmp,'wt')
|
||||||
for l in process.stdout.readlines():
|
for l in process.stdout.readlines():
|
||||||
f_cs_tmp_w.write(l)
|
f_cs_tmp_w.write(l.decode('utf8'))
|
||||||
f_cs_tmp_w.close()
|
f_cs_tmp_w.close()
|
||||||
|
|
||||||
# Convert SC -> CSV
|
# Convert SC -> CSV
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ function c2t {
|
|||||||
# Convert comma separated stream in to tab separated stream
|
# Convert comma separated stream in to tab separated stream
|
||||||
# Usage: echo "foo,bar" | c2t
|
# Usage: echo "foo,bar" | c2t
|
||||||
|
|
||||||
python -c 'import sys,csv
|
python3 -c 'import sys,csv
|
||||||
try:
|
try:
|
||||||
csv.writer(sys.stdout, dialect=csv.excel_tab, lineterminator="\n").writerows(csv.reader(sys.stdin, dialect=csv.excel))
|
csv.writer(sys.stdout, dialect=csv.excel_tab, lineterminator="\n").writerows(csv.reader(sys.stdin, dialect=csv.excel))
|
||||||
except IOError:
|
except IOError:
|
||||||
@@ -48,7 +48,7 @@ function tsvstrip {
|
|||||||
# Strip tsv of quotes
|
# Strip tsv of quotes
|
||||||
# Usage: cat file.csv | tsvstrip
|
# Usage: cat file.csv | tsvstrip
|
||||||
|
|
||||||
python -c 'import sys,csv
|
python3 -c 'import sys,csv
|
||||||
try:
|
try:
|
||||||
csv.writer(sys.stdout, dialect=csv.excel_tab, quoting=csv.QUOTE_NONE).writerows(csv.reader(sys.stdin, dialect=csv.excel_tab))
|
csv.writer(sys.stdout, dialect=csv.excel_tab, quoting=csv.QUOTE_NONE).writerows(csv.reader(sys.stdin, dialect=csv.excel_tab))
|
||||||
except IOError:
|
except IOError:
|
||||||
@@ -59,7 +59,7 @@ function tsvtranspose {
|
|||||||
# Transpose a tsv file
|
# Transpose a tsv file
|
||||||
# Usage: cat file.csv | tsvtranspose
|
# Usage: cat file.csv | tsvtranspose
|
||||||
|
|
||||||
python -c 'import sys,csv
|
python3 -c 'import sys,csv
|
||||||
try:
|
try:
|
||||||
csv.writer(sys.stdout, dialect=csv.excel_tab, quoting=csv.QUOTE_NONE).writerows(map(None,*csv.reader(sys.stdin, dialect=csv.excel_tab)))
|
csv.writer(sys.stdout, dialect=csv.excel_tab, quoting=csv.QUOTE_NONE).writerows(map(None,*csv.reader(sys.stdin, dialect=csv.excel_tab)))
|
||||||
except IOError:
|
except IOError:
|
||||||
@@ -71,9 +71,9 @@ function tsvhead {
|
|||||||
# Usage: cat file | tsvhead -n 30
|
# Usage: cat file | tsvhead -n 30
|
||||||
|
|
||||||
if [ -t 0 ]; then
|
if [ -t 0 ]; then
|
||||||
python "${TSVDIR}"/lib/tsvhead "$@"
|
python3 "${TSVDIR}"/lib/tsvhead "$@"
|
||||||
else
|
else
|
||||||
cat - | python "${TSVDIR}"/lib/tsvhead "$@"
|
cat - | python3 "${TSVDIR}"/lib/tsvhead "$@"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -82,9 +82,9 @@ function tsvtail {
|
|||||||
# Usage: cat file | tsvtail -n 30
|
# Usage: cat file | tsvtail -n 30
|
||||||
|
|
||||||
if [ -t 0 ]; then
|
if [ -t 0 ]; then
|
||||||
python "${TSVDIR}"/lib/tsvtail "$@"
|
python3 "${TSVDIR}"/lib/tsvtail "$@"
|
||||||
else
|
else
|
||||||
cat - | python "${TSVDIR}"/lib/tsvtail "$@"
|
cat - | python3 "${TSVDIR}"/lib/tsvtail "$@"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -242,7 +242,7 @@ function tsvdims {
|
|||||||
# Usage: tsvdims file.txt
|
# Usage: tsvdims file.txt
|
||||||
# Usage: cat file.txt | tsvdims
|
# Usage: cat file.txt | tsvdims
|
||||||
|
|
||||||
python -c 'import sys,csv
|
python3 -c 'import sys,csv
|
||||||
if sys.argv[1]=="":
|
if sys.argv[1]=="":
|
||||||
input=sys.stdin
|
input=sys.stdin
|
||||||
else:
|
else:
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python3
|
||||||
#
|
#
|
||||||
# Copyright 2016 Ville Rantanen
|
# Copyright 2016 Ville Rantanen
|
||||||
#
|
#
|
||||||
@@ -16,6 +16,8 @@
|
|||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
#
|
#
|
||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
|
from __future__ import division
|
||||||
|
from past.utils import old_div
|
||||||
import sys, os, math, csv, subprocess
|
import sys, os, math, csv, subprocess
|
||||||
from argparse import ArgumentParser
|
from argparse import ArgumentParser
|
||||||
|
|
||||||
@@ -29,7 +31,7 @@ def get_data_scatter(opts):
|
|||||||
try:
|
try:
|
||||||
for row in reader:
|
for row in reader:
|
||||||
data.append(",".join([row[c] for c in opts.columns]))
|
data.append(",".join([row[c] for c in opts.columns]))
|
||||||
except KeyError,ME:
|
except KeyError as ME:
|
||||||
print("Column {} not found.".format(ME),file=sys.stderr)
|
print("Column {} not found.".format(ME),file=sys.stderr)
|
||||||
print("Columns in the file:"+",".join(reader.fieldnames),file=sys.stderr)
|
print("Columns in the file:"+",".join(reader.fieldnames),file=sys.stderr)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
@@ -45,7 +47,7 @@ def get_data_histogram(opts):
|
|||||||
data.append(row[opts.columns[0]])
|
data.append(row[opts.columns[0]])
|
||||||
except ValueError:
|
except ValueError:
|
||||||
continue
|
continue
|
||||||
except KeyError,ME:
|
except KeyError as ME:
|
||||||
print("Column {} not found.".format(ME),file=sys.stderr)
|
print("Column {} not found.".format(ME),file=sys.stderr)
|
||||||
print("Columns in the file:"+",".join(reader.fieldnames),file=sys.stderr)
|
print("Columns in the file:"+",".join(reader.fieldnames),file=sys.stderr)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
@@ -65,7 +67,7 @@ def get_stats(opts):
|
|||||||
values_n+=1
|
values_n+=1
|
||||||
values_min=min(f,values_min)
|
values_min=min(f,values_min)
|
||||||
values_max=max(f,values_max)
|
values_max=max(f,values_max)
|
||||||
except KeyError,ME:
|
except KeyError as ME:
|
||||||
print("Column {} not found.".format(ME),file=sys.stderr)
|
print("Column {} not found.".format(ME),file=sys.stderr)
|
||||||
print("Columns in the file:"+",".join(reader.fieldnames),file=sys.stderr)
|
print("Columns in the file:"+",".join(reader.fieldnames),file=sys.stderr)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
@@ -95,7 +97,7 @@ def get_histogram_template(opts):
|
|||||||
(height,width)=termsize()
|
(height,width)=termsize()
|
||||||
if opts.width:
|
if opts.width:
|
||||||
width=opts.width
|
width=opts.width
|
||||||
bins=min(int(float(width)/4),bins)
|
bins=min(int(old_div(float(width),4)),bins)
|
||||||
template='''{}
|
template='''{}
|
||||||
set datafile separator ",";
|
set datafile separator ",";
|
||||||
set xlabel '{}';
|
set xlabel '{}';
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
|||||||
@@ -199,6 +199,7 @@ def generate_index(opts):
|
|||||||
files = [f for f in files if f != opts.filename]
|
files = [f for f in files if f != opts.filename]
|
||||||
files = [f for f in files if f != opts.password_filename]
|
files = [f for f in files if f != opts.password_filename]
|
||||||
files = match_files(files, opts.includes)
|
files = match_files(files, opts.includes)
|
||||||
|
dirs = match_files(dirs, opts.includes)
|
||||||
dirs.sort()
|
dirs.sort()
|
||||||
files.sort()
|
files.sort()
|
||||||
files.sort(key=lambda x: x.find("/") > 0)
|
files.sort(key=lambda x: x.find("/") > 0)
|
||||||
@@ -270,7 +271,7 @@ def get_filelink(path, fname, images=False, media=False):
|
|||||||
if media and is_videofile(fname):
|
if media and is_videofile(fname):
|
||||||
fname_str = get_videostr(fname)
|
fname_str = get_videostr(fname)
|
||||||
return (
|
return (
|
||||||
'<tr><td><a class="link_file" href="%s">%s</a><td class="right">%s</td><td class="right bytes">%s</td><td class="right">%s</td></tr>\n'
|
'<tr class="row_file"><td><a class="link_file" href="%s"> %s</a><td class="right">%s</td><td class="right bytes">%s</td><td class="right">%s</td></tr>\n'
|
||||||
% (urllib.parse.quote(fname), fname_str, fsstr, fsstrb, fdstr)
|
% (urllib.parse.quote(fname), fname_str, fsstr, fsstrb, fdstr)
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -306,7 +307,7 @@ def get_pathlink(path, dname):
|
|||||||
fdate = time.localtime(os.path.getmtime(os.path.join(path, dname)))
|
fdate = time.localtime(os.path.getmtime(os.path.join(path, dname)))
|
||||||
fdstr = time.strftime("%Y/%m/%d %H:%M:%S", fdate)
|
fdstr = time.strftime("%Y/%m/%d %H:%M:%S", fdate)
|
||||||
return (
|
return (
|
||||||
'<tr><td><a class="link_dir" href="%s">↳ %s/</a><td class="right">[DIR]</td><td class="right bytes">0</td><td class="right">%s</td></tr>\n'
|
'<tr class="row_dir"><td><a class="link_dir" href="%s">↳ %s/</a><td class="right">[DIR]</td><td class="right bytes">0</td><td class="right">%s</td></tr>\n'
|
||||||
% (urllib.parse.quote(dname), dname, fdstr)
|
% (urllib.parse.quote(dname), dname, fdstr)
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -318,7 +319,7 @@ def get_password_page(secret, target_base, target_ext):
|
|||||||
<head>
|
<head>
|
||||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
|
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
|
||||||
<link rel="shortcut icon" href="data:image/x-icon;," type="image/x-icon">
|
<link rel="shortcut icon" href="data:image/x-icon;," type="image/x-icon">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
<meta name="viewport" content="width=device-width, initial-scale=1, height=device-height, viewport-fit=cover">
|
||||||
<title>Password required</title>
|
<title>Password required</title>
|
||||||
<script language="JavaScript">
|
<script language="JavaScript">
|
||||||
Object.defineProperty(String.prototype, 'hashCode', {
|
Object.defineProperty(String.prototype, 'hashCode', {
|
||||||
@@ -332,6 +333,9 @@ Object.defineProperty(String.prototype, 'hashCode', {
|
|||||||
return hash;
|
return hash;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
function isMobile () {
|
||||||
|
return /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);
|
||||||
|
}
|
||||||
function scramble(p,t) {
|
function scramble(p,t) {
|
||||||
p += t;
|
p += t;
|
||||||
var sstr = '';
|
var sstr = '';
|
||||||
@@ -360,7 +364,15 @@ function pw(element) {
|
|||||||
if (element.value) {
|
if (element.value) {
|
||||||
pw = pw.split(':',2);
|
pw = pw.split(':',2);
|
||||||
if (element.value.hashCode() == parseInt(pw[0])) {
|
if (element.value.hashCode() == parseInt(pw[0])) {
|
||||||
this.location.href = "TARGET_BASE." + unscramble(element.value, atob(pw[1])) + "TARGET_EXT";
|
let unscrambled = "TARGET_BASE." + unscramble(element.value, atob(pw[1])) + "TARGET_EXT"
|
||||||
|
if (isMobile()) {
|
||||||
|
document.location.replace(unscrambled);
|
||||||
|
return
|
||||||
|
}
|
||||||
|
document.getElementById("body").innerHTML = '';
|
||||||
|
var frame = document.createElement("iframe");
|
||||||
|
frame.src = unscrambled;
|
||||||
|
document.getElementById("body").appendChild(frame);
|
||||||
} else {
|
} else {
|
||||||
document.getElementById("message").innerHTML = "No match";
|
document.getElementById("message").innerHTML = "No match";
|
||||||
setTimeout(clear_message, 5000);
|
setTimeout(clear_message, 5000);
|
||||||
@@ -379,6 +391,15 @@ function newPass(password, target) {
|
|||||||
//console.log("Use newPass('pass','page.html'); to get a new hash");
|
//console.log("Use newPass('pass','page.html'); to get a new hash");
|
||||||
</script>
|
</script>
|
||||||
<style>
|
<style>
|
||||||
|
iframe {
|
||||||
|
width: 100vw;
|
||||||
|
height: 100vh;
|
||||||
|
}
|
||||||
|
#body {
|
||||||
|
margin: 0;
|
||||||
|
overflow-x: hidden;
|
||||||
|
overflow-y: hidden;
|
||||||
|
}
|
||||||
#content {
|
#content {
|
||||||
text-align: center;
|
text-align: center;
|
||||||
padding-top: 4rem;
|
padding-top: 4rem;
|
||||||
@@ -393,7 +414,7 @@ function newPass(password, target) {
|
|||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body id="body">
|
||||||
<div id="content">
|
<div id="content">
|
||||||
<input type="password" placeholder="Password" class="password" onkeydown="pw_event(this)" id="password" onFocus="this.select()" autofocus/>
|
<input type="password" placeholder="Password" class="password" onkeydown="pw_event(this)" id="password" onFocus="this.select()" autofocus/>
|
||||||
<br><button id="button" type="button" onclick="pw(document.getElementById('password'));">Enter</button>
|
<br><button id="button" type="button" onclick="pw(document.getElementById('password'));">Enter</button>
|
||||||
@@ -415,6 +436,7 @@ def get_header(opts):
|
|||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
|
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1, height=device-height, viewport-fit=cover">
|
||||||
<meta name="generator" content="SimpleWebPage """
|
<meta name="generator" content="SimpleWebPage """
|
||||||
+ VERSION
|
+ VERSION
|
||||||
+ """" />
|
+ """" />
|
||||||
@@ -433,20 +455,22 @@ def get_header(opts):
|
|||||||
body {
|
body {
|
||||||
color: #222;
|
color: #222;
|
||||||
font: 14px monospace;
|
font: 14px monospace;
|
||||||
padding: 20px;
|
padding: 0;
|
||||||
background: #CCC;
|
background: #CCC;
|
||||||
}
|
}
|
||||||
h1 {
|
h1 {
|
||||||
text-align: center;
|
|
||||||
padding: 20px 0 12px 0;
|
padding: 20px 0 12px 0;
|
||||||
margin: 0;
|
margin: 0 0 0 70px;
|
||||||
font-family: sans-serif;
|
font-family: sans-serif;
|
||||||
}
|
}
|
||||||
.container {
|
.container {
|
||||||
|
margin: 20px;
|
||||||
box-shadow: 0 5px 10px -5px rgba(0,0,0,0.5);
|
box-shadow: 0 5px 10px -5px rgba(0,0,0,0.5);
|
||||||
position: relative;
|
position: relative;
|
||||||
background: #eee;
|
background: #eee;
|
||||||
border-top-left-radius: 6em;
|
border-top-left-radius: 70px;
|
||||||
|
display: inline-block;
|
||||||
|
min-width: calc(100% - 40px);
|
||||||
}
|
}
|
||||||
table {
|
table {
|
||||||
background-color: #F3F3F3;
|
background-color: #F3F3F3;
|
||||||
@@ -472,6 +496,9 @@ def get_header(opts):
|
|||||||
display: block;
|
display: block;
|
||||||
padding: 5px 10px;
|
padding: 5px 10px;
|
||||||
}
|
}
|
||||||
|
td a.link_dir {
|
||||||
|
font-weight: bold;
|
||||||
|
}
|
||||||
th a {
|
th a {
|
||||||
padding-left: 0
|
padding-left: 0
|
||||||
}
|
}
|
||||||
@@ -482,10 +509,13 @@ def get_header(opts):
|
|||||||
padding-left: 5px;
|
padding-left: 5px;
|
||||||
}
|
}
|
||||||
tr:nth-of-type(odd) {
|
tr:nth-of-type(odd) {
|
||||||
background-color: #DDD;
|
background-color: #e1e1e1;
|
||||||
}
|
}
|
||||||
tr:hover td {
|
tr.row_dir:hover td {
|
||||||
background-color:#BBB;
|
background-color: #fbe6b3;
|
||||||
|
}
|
||||||
|
tr.row_file:hover td {
|
||||||
|
background-color: #f9cba2;
|
||||||
}
|
}
|
||||||
tr:hover td a {
|
tr:hover td a {
|
||||||
color: #222;
|
color: #222;
|
||||||
|
|||||||
70
web/droopy
70
web/droopy
@@ -1,4 +1,4 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python3
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
# Droopy (http://stackp.online.fr/droopy)
|
# Droopy (http://stackp.online.fr/droopy)
|
||||||
@@ -52,8 +52,12 @@
|
|||||||
# * German translation by Michael.
|
# * German translation by Michael.
|
||||||
# 20080408 * First release.
|
# 20080408 * First release.
|
||||||
|
|
||||||
import BaseHTTPServer
|
from __future__ import print_function
|
||||||
import SocketServer
|
from future import standard_library
|
||||||
|
standard_library.install_aliases()
|
||||||
|
from builtins import str
|
||||||
|
import http.server
|
||||||
|
import socketserver
|
||||||
import cgi
|
import cgi
|
||||||
import os
|
import os
|
||||||
import posixpath
|
import posixpath
|
||||||
@@ -67,7 +71,7 @@ import shutil
|
|||||||
import tempfile
|
import tempfile
|
||||||
import socket
|
import socket
|
||||||
import locale
|
import locale
|
||||||
import urllib
|
import urllib.request, urllib.parse, urllib.error
|
||||||
|
|
||||||
LOGO = '''\
|
LOGO = '''\
|
||||||
_____
|
_____
|
||||||
@@ -611,7 +615,7 @@ class DroopyFieldStorage(cgi.FieldStorage):
|
|||||||
return self.tmpfile
|
return self.tmpfile
|
||||||
|
|
||||||
|
|
||||||
class HTTPUploadHandler(BaseHTTPServer.BaseHTTPRequestHandler):
|
class HTTPUploadHandler(http.server.BaseHTTPRequestHandler):
|
||||||
|
|
||||||
protocol_version = 'HTTP/1.0'
|
protocol_version = 'HTTP/1.0'
|
||||||
form_field = 'upfile'
|
form_field = 'upfile'
|
||||||
@@ -626,7 +630,7 @@ class HTTPUploadHandler(BaseHTTPServer.BaseHTTPRequestHandler):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
# -- Parse accept-language header
|
# -- Parse accept-language header
|
||||||
if not self.headers.has_key("accept-language"):
|
if "accept-language" not in self.headers:
|
||||||
a = []
|
a = []
|
||||||
else:
|
else:
|
||||||
a = self.headers["accept-language"]
|
a = self.headers["accept-language"]
|
||||||
@@ -642,7 +646,7 @@ class HTTPUploadHandler(BaseHTTPServer.BaseHTTPRequestHandler):
|
|||||||
# -- Choose the appropriate translation dictionary (default is english)
|
# -- Choose the appropriate translation dictionary (default is english)
|
||||||
lang = "en"
|
lang = "en"
|
||||||
for l in a:
|
for l in a:
|
||||||
if translations.has_key(l):
|
if l in translations:
|
||||||
lang = l
|
lang = l
|
||||||
break
|
break
|
||||||
dico = copy.copy(translations[lang])
|
dico = copy.copy(translations[lang])
|
||||||
@@ -665,7 +669,7 @@ class HTTPUploadHandler(BaseHTTPServer.BaseHTTPRequestHandler):
|
|||||||
if names:
|
if names:
|
||||||
for name in names:
|
for name in names:
|
||||||
links += '<a href="/%s">%s</a><br/>' % (
|
links += '<a href="/%s">%s</a><br/>' % (
|
||||||
urllib.quote(name.encode('utf-8')),
|
urllib.parse.quote(name.encode('utf-8')),
|
||||||
name)
|
name)
|
||||||
links = '<div id="files">' + links + '</div>'
|
links = '<div id="files">' + links + '</div>'
|
||||||
dico["files"] = links
|
dico["files"] = links
|
||||||
@@ -682,7 +686,7 @@ class HTTPUploadHandler(BaseHTTPServer.BaseHTTPRequestHandler):
|
|||||||
|
|
||||||
def do_GET(self):
|
def do_GET(self):
|
||||||
name = self.path.lstrip('/')
|
name = self.path.lstrip('/')
|
||||||
name = urllib.unquote(name)
|
name = urllib.parse.unquote(name)
|
||||||
name = name.decode('utf-8')
|
name = name.decode('utf-8')
|
||||||
|
|
||||||
if picture != None and self.path == '/__droopy/picture':
|
if picture != None and self.path == '/__droopy/picture':
|
||||||
@@ -714,7 +718,7 @@ class HTTPUploadHandler(BaseHTTPServer.BaseHTTPRequestHandler):
|
|||||||
form = DroopyFieldStorage(fp = self.rfile, environ = env);
|
form = DroopyFieldStorage(fp = self.rfile, environ = env);
|
||||||
fileitem = form[self.form_field]
|
fileitem = form[self.form_field]
|
||||||
realname=""
|
realname=""
|
||||||
if self.form_realname in form.keys():
|
if self.form_realname in list(form.keys()):
|
||||||
realname = form[self.form_realname].value.decode('utf-8')
|
realname = form[self.form_realname].value.decode('utf-8')
|
||||||
if realname=="":
|
if realname=="":
|
||||||
filename = self.basename(fileitem.filename).decode('utf-8')
|
filename = self.basename(fileitem.filename).decode('utf-8')
|
||||||
@@ -757,7 +761,7 @@ class HTTPUploadHandler(BaseHTTPServer.BaseHTTPRequestHandler):
|
|||||||
else:
|
else:
|
||||||
self.send_html(self.html("success"))
|
self.send_html(self.html("success"))
|
||||||
|
|
||||||
except Exception, e:
|
except Exception as e:
|
||||||
self.log_message(repr(e))
|
self.log_message(repr(e))
|
||||||
self.send_html(self.html("error"))
|
self.send_html(self.html("error"))
|
||||||
|
|
||||||
@@ -792,7 +796,7 @@ class HTTPUploadHandler(BaseHTTPServer.BaseHTTPRequestHandler):
|
|||||||
if publish_files:
|
if publish_files:
|
||||||
# os.listdir() returns a list of unicode strings when the
|
# os.listdir() returns a list of unicode strings when the
|
||||||
# directory is passed as an unicode string itself.
|
# directory is passed as an unicode string itself.
|
||||||
names = [name for name in os.listdir(unicode(directory))
|
names = [name for name in os.listdir(str(directory))
|
||||||
if os.path.isfile(os.path.join(directory, name))
|
if os.path.isfile(os.path.join(directory, name))
|
||||||
and not name.startswith(DroopyFieldStorage.TMPPREFIX)]
|
and not name.startswith(DroopyFieldStorage.TMPPREFIX)]
|
||||||
names.sort()
|
names.sort()
|
||||||
@@ -802,8 +806,8 @@ class HTTPUploadHandler(BaseHTTPServer.BaseHTTPRequestHandler):
|
|||||||
|
|
||||||
def handle(self):
|
def handle(self):
|
||||||
try:
|
try:
|
||||||
BaseHTTPServer.BaseHTTPRequestHandler.handle(self)
|
http.server.BaseHTTPRequestHandler.handle(self)
|
||||||
except socket.error, e:
|
except socket.error as e:
|
||||||
self.log_message(str(e))
|
self.log_message(str(e))
|
||||||
raise Abort()
|
raise Abort()
|
||||||
|
|
||||||
@@ -811,14 +815,14 @@ class HTTPUploadHandler(BaseHTTPServer.BaseHTTPRequestHandler):
|
|||||||
class Abort(Exception): pass
|
class Abort(Exception): pass
|
||||||
|
|
||||||
|
|
||||||
class ThreadedHTTPServer(SocketServer.ThreadingMixIn,
|
class ThreadedHTTPServer(socketserver.ThreadingMixIn,
|
||||||
BaseHTTPServer.HTTPServer):
|
http.server.HTTPServer):
|
||||||
|
|
||||||
def handle_error(self, request, client_address):
|
def handle_error(self, request, client_address):
|
||||||
# Override SocketServer.handle_error
|
# Override SocketServer.handle_error
|
||||||
exctype = sys.exc_info()[0]
|
exctype = sys.exc_info()[0]
|
||||||
if not exctype is Abort:
|
if not exctype is Abort:
|
||||||
BaseHTTPServer.HTTPServer.handle_error(self,request,client_address)
|
http.server.HTTPServer.handle_error(self,request,client_address)
|
||||||
|
|
||||||
|
|
||||||
# -- Options
|
# -- Options
|
||||||
@@ -867,7 +871,7 @@ def load_options():
|
|||||||
parse_args(cmd)
|
parse_args(cmd)
|
||||||
f.close()
|
f.close()
|
||||||
return True
|
return True
|
||||||
except IOError, e:
|
except IOError as e:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
@@ -891,8 +895,8 @@ def parse_args(cmd=None):
|
|||||||
"directory=", "help",
|
"directory=", "help",
|
||||||
"save-config","delete-config",
|
"save-config","delete-config",
|
||||||
"dl"])
|
"dl"])
|
||||||
except Exception, e:
|
except Exception as e:
|
||||||
print e
|
print(e)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
for o,a in opts:
|
for o,a in opts:
|
||||||
@@ -912,16 +916,16 @@ def parse_args(cmd=None):
|
|||||||
try:
|
try:
|
||||||
filename = configfile()
|
filename = configfile()
|
||||||
os.remove(filename)
|
os.remove(filename)
|
||||||
print 'Deleted ' + filename
|
print('Deleted ' + filename)
|
||||||
except Exception, e:
|
except Exception as e:
|
||||||
print e
|
print(e)
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|
||||||
elif o in ['--dl']:
|
elif o in ['--dl']:
|
||||||
publish_files = True
|
publish_files = True
|
||||||
|
|
||||||
elif o in ['-h', '--help']:
|
elif o in ['-h', '--help']:
|
||||||
print USAGE
|
print(USAGE)
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|
||||||
# port number
|
# port number
|
||||||
@@ -929,7 +933,7 @@ def parse_args(cmd=None):
|
|||||||
if args[0:]:
|
if args[0:]:
|
||||||
port = int(args[0])
|
port = int(args[0])
|
||||||
except ValueError:
|
except ValueError:
|
||||||
print args[0], "is not a valid port number"
|
print(args[0], "is not a valid port number")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
|
||||||
@@ -944,25 +948,25 @@ def run():
|
|||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
print LOGO
|
print(LOGO)
|
||||||
|
|
||||||
config_found = load_options()
|
config_found = load_options()
|
||||||
parse_args()
|
parse_args()
|
||||||
|
|
||||||
if config_found:
|
if config_found:
|
||||||
print 'Configuration found in %s' % configfile()
|
print('Configuration found in %s' % configfile())
|
||||||
else:
|
else:
|
||||||
print "No configuration file found."
|
print("No configuration file found.")
|
||||||
|
|
||||||
if must_save_options:
|
if must_save_options:
|
||||||
save_options()
|
save_options()
|
||||||
print "Options saved in %s" % configfile()
|
print("Options saved in %s" % configfile())
|
||||||
|
|
||||||
print "Files will be uploaded to %s" % directory
|
print("Files will be uploaded to %s" % directory)
|
||||||
try:
|
try:
|
||||||
print
|
print()
|
||||||
print "HTTP server running... Check it out at http://localhost:%d"%port
|
print("HTTP server running... Check it out at http://localhost:%d"%port)
|
||||||
run()
|
run()
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
print '^C received, shutting down server'
|
print('^C received, shutting down server')
|
||||||
# some threads may run until they terminate
|
# some threads may run until they terminate
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
python -c "import pyftpdlib" >/dev/null 2>&1 || {
|
python3 -c "import pyftpdlib" >/dev/null 2>&1 || {
|
||||||
echo "pyftpdlib is not installed:"
|
echo "pyftpdlib is not installed:"
|
||||||
echo " pip install --user pyftpdlib"
|
echo " pip3 install --user pyftpdlib"
|
||||||
exit
|
exit
|
||||||
}
|
}
|
||||||
python -m pyftpdlib "$@"
|
python3 -m pyftpdlib "$@"
|
||||||
|
|||||||
Reference in New Issue
Block a user