forcing everything python3, might end up with bugs

This commit is contained in:
Ville Rantanen
2021-04-09 13:01:04 +03:00
parent 72310083f6
commit 525c93a106
23 changed files with 276 additions and 243 deletions

View File

@@ -1,5 +1,12 @@
#!/usr/bin/env python
#!/usr/bin/env python3
# -*- 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 os
import re
@@ -8,7 +15,8 @@ import subprocess
import hashlib
import magic
from argparse import ArgumentParser
import ConfigParser,StringIO,io
import configparser
import io
import datetime
SQLFILE='list_of_files.sqlite'
@@ -67,7 +75,7 @@ def setup_options():
BADDIRS.extend(options.exclude)
if options.duplicate:
options.add=not options.add
options.startpath=unicode(options.startpath, "UTF-8")
options.sqlpath=os.path.dirname(os.path.realpath(options.sqlfile))
return options
@@ -78,7 +86,7 @@ def add_recurse(options):
db=conn.cursor()
prev_path_len=0
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)
dirs=clean_dirs(dirs)
dirs.sort()
@@ -218,11 +226,11 @@ def createdb(options):
object TEXT)')
conn.commit()
config = ConfigParser.RawConfigParser()
config = configparser.RawConfigParser()
config.add_section("General")
config.set("General","Relative",str(options.relative))
config.set("General","FullFile",str(options.fullfile))
store=StringIO.StringIO()
store=io.StringIO()
config.write(store)
db.execute("INSERT INTO config (object) values (?)",(store.getvalue(),))
conn.commit()
@@ -337,7 +345,7 @@ def get_md5(filename,fullfile=False):
anim_i=0
anim_len=len(ANIM)
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()
with open(filename,'rb') as f:
for chunk in iter(lambda: f.read(block_size), b''):
@@ -425,7 +433,7 @@ def humanize_size(size,precision=1):
defPrecision=0
while size > 1024:
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
return "%.*f%s"%(defPrecision,size,suffixes[suffixIndex])
@@ -510,7 +518,7 @@ def stored_options(options):
store=""
for row in db:
store+=row[0]+'\n'
config = ConfigParser.RawConfigParser()
config = configparser.RawConfigParser()
config.readfp(io.BytesIO(store))
options.relative=config.getboolean("General","Relative")
options.fullfile=config.getboolean("General","FullFile")