This commit is contained in:
Valentino Orlandi 2022-06-29 12:40:41 +02:00
parent 7a0484b0f0
commit 715b09859d
10 changed files with 83 additions and 70 deletions

View File

@ -371,7 +371,7 @@ def checkFile(
.format(**craptool.text_colors)\ .format(**craptool.text_colors)\
%( err_key, parent_path, entry_name )) %( err_key, parent_path, entry_name ))
if craptool.more_output is True: if craptool.more_output is True:
print("%s craptool doesn't have permissions to read from this file" %(spaces)) print("%s %s doesn't have permissions to read from this file" %(craptool.name,spaces))
print("%s please make the file readable and retry" %(spaces)) print("%s please make the file readable and retry" %(spaces))
print() print()
if w is True\ if w is True\
@ -381,7 +381,7 @@ def checkFile(
.format(**craptool.text_colors)\ .format(**craptool.text_colors)\
%( err_key, parent_path, entry_name )) %( err_key, parent_path, entry_name ))
if craptool.more_output is True: if craptool.more_output is True:
print("%s craptool doesn't have permissions to write in this file" %(spaces)) print("%s %s doesn't have permissions to write in this file" %(craptool.name,spaces))
print("%s please make the file writable and retry" %(spaces)) print("%s please make the file writable and retry" %(spaces))
print() print()
else: else:
@ -461,7 +461,7 @@ def checkFile(
pass pass
else: else:
# ..but should have existed # ..but should have existed
if craptool.name != "craptool": if craptool.name != "crapset":
# print an error message # print an error message
failed() failed()
print("\n{err}Error{white}[{grey}%s{white}]{red}>{default} the given path does not exist: %s\n"\ print("\n{err}Error{white}[{grey}%s{white}]{red}>{default} the given path does not exist: %s\n"\

View File

@ -31,6 +31,8 @@ class Craplog(object):
""" """
Craplog's initializer Craplog's initializer
""" """
# craptool name
self.name = "craplog"
# variables from args # variables from args
self.use_configs: bool self.use_configs: bool
self.use_arguments: bool self.use_arguments: bool

View File

@ -3,7 +3,7 @@ from sys import argv
from sys import path as libpath from sys import path as libpath
from time import sleep from time import sleep
from os.path import abspath from os.path import abspath, exists
crappath = abspath(__file__) crappath = abspath(__file__)
crappath = crappath[:crappath.rfind('/')] crappath = crappath[:crappath.rfind('/')]
@ -23,6 +23,8 @@ class Crapset():
""" """
def __init__(self, args:list ): def __init__(self, args:list ):
""" Initialize Crapset """ """ Initialize Crapset """
# craptool name
self.name = "crapset"
# get the path to the configuration files # get the path to the configuration files
crappath = abspath(__file__) crappath = abspath(__file__)
crappath = crappath[:crappath.rfind('/')] crappath = crappath[:crappath.rfind('/')]
@ -92,42 +94,42 @@ class Crapset():
""" """
Read the saved configuration Read the saved configuration
""" """
if os.path.exists( self.file_path ) is False: if exists( self.file_path ) is False:
# leave this normal yellow, it's secondary and doesn't need a real attention # leave this normal yellow, it's secondary and doesn't need a real attention
if self.less_output is False: if self.less_output is False:
print("\n{warn}Warning{white}[{grey}configs{white}]{warn}>{default} {yellow}configurations file not found\n"\ print("\n{warn}Warning{white}[{grey}configs{white}]{warn}>{default} {yellow}configurations file not found\n"\
.format(**self.text_colors)) .format(**self.text_colors))
sleep(1) sleep(1)
else: else:
with open(self.file_path,'r') as f: with open(self.file_path,'r') as f:
tmp = f.read().strip().split('\n') tmp = f.read().strip().split('\n')
configs = [] configs = []
for f in tmp: for f in tmp:
f = f.strip() f = f.strip()
if f == ""\ if f == ""\
or f[0] == "#": or f[0] == "#":
continue continue
configs.append(f) configs.append(f)
# check the length # check the length
if len(configs) != 5: if len(configs) != 5:
print("\n{err}Error{white}[{grey}crapset.crapconf{white}]{red}>{default} invalid number of lines: {rose}%s{default}"\ print("\n{err}Error{white}[{grey}crapset.crapconf{white}]{red}>{default} invalid number of lines: {rose}%s{default}"\
.format(**self.text_colors)\ .format(**self.text_colors)\
%( len(configs) )) %( len(configs) ))
if self.less_output is False: if self.less_output is False:
print(""" print("""
if you have manually edited the configurations file, please un-do the changes if you have manually edited the configurations file, please un-do the changes
else, please report this issue""") else, please report this issue""")
print("\n{err}CRAPSET ABORTED{default}\n"\ print("\n{err}CRAPSET ABORTED{default}\n"\
.format(**self.text_colors)) .format(**self.text_colors))
exit() exit()
# apply the configs # apply the configs
self.use_configs = bool(int(configs[0])) self.use_configs = bool(int(configs[0]))
if self.use_configs is True: if self.use_configs is True:
self.use_arguments: bool(int(configs[1])) self.use_arguments: bool(int(configs[1]))
self.less_output: bool(int(configs[2])) self.less_output: bool(int(configs[2]))
self.more_output: bool(int(configs[3])) self.more_output: bool(int(configs[3]))
self.use_colors: bool(int(configs[4])) self.use_colors: bool(int(configs[4]))
self.initMessages() self.initMessages()
@ -245,6 +247,8 @@ class Crapset():
""" """
Print the abortion message and exit Print the abortion message and exit
""" """
if self.less_output is False:
print()
print("\n{err}CRAPSET ABORTED{default}"\ print("\n{err}CRAPSET ABORTED{default}"\
.format(**self.text_colors)) .format(**self.text_colors))
if self.less_output is False: if self.less_output is False:

View File

@ -7,7 +7,7 @@ def versionCheck( crapup:object ):
Manages the request Manages the request
""" """
# version check url # version check url
url = "https://git.disroot.org/elB4RTO/craplog-CLI/blob/main/version_check" url = "https://github.com/elB4RTO/craplog-CLI/blob/main/version_check"
# additional headers # additional headers
headers = { 'Connection':'close' } headers = { 'Connection':'close' }
# timeout for the connection to be established (in seconds) # timeout for the connection to be established (in seconds)
@ -37,7 +37,7 @@ def versionCheck( crapup:object ):
try: try:
# get the new version string and convert it to number # get the new version string and convert it to number
new_version = html[ new_version = html[
(pos+len(version_mark)+1) (pos+len(version_mark))
: :
html.find(version_mark,(pos+len(version_mark)+1)) ] html.find(version_mark,(pos+len(version_mark)+1)) ]
new_version = float( new_version ) new_version = float( new_version )

View File

@ -223,7 +223,7 @@ def gitPull( crapup:object ):
if crapup.more_output is True: if crapup.more_output is True:
print("\n{rose}%s{default}"\ print("\n{rose}%s{default}"\
.format(**crapup.text_colors)\ .format(**crapup.text_colors)\
%( command.stderr.decode.strip('\n') )) %( command.stderr.decode().strip('\n') ))
print() print()
crapup.exitAborted() crapup.exitAborted()
# restore the personal gitignore file # restore the personal gitignore file

View File

@ -3,7 +3,7 @@ from sys import argv
from sys import path as libpath from sys import path as libpath
from time import sleep from time import sleep
from os.path import abspath from os.path import abspath, exists
crappath = abspath(__file__) crappath = abspath(__file__)
crappath = crappath[:crappath.rfind('/')] crappath = crappath[:crappath.rfind('/')]
@ -20,6 +20,8 @@ class Crapup():
Craplog's updater Craplog's updater
""" """
def __init__(self, args:list ): def __init__(self, args:list ):
# craptool name
self.name = "crapup"
# declare variables # declare variables
self.use_configs: bool self.use_configs: bool
self.use_arguments: bool self.use_arguments: bool
@ -125,7 +127,7 @@ class Crapup():
crappath = crappath[:crappath.rfind('/')] crappath = crappath[:crappath.rfind('/')]
self.crappath = crappath[:crappath.rfind('/')] self.crappath = crappath[:crappath.rfind('/')]
path = "%s/crapconfs/crapup.crapconf" %(self.crappath) path = "%s/crapconfs/crapup.crapconf" %(self.crappath)
if os.path.exists( path ) is False: if exists( path ) is False:
# leave this normal yellow, it's secondary and doesn't need a real attention # leave this normal yellow, it's secondary and doesn't need a real attention
if self.less_output is False: if self.less_output is False:
print("\n{warn}Warning{white}[{grey}configs{white}]{warn}>{default} {yellow}configurations file not found\n"\ print("\n{warn}Warning{white}[{grey}configs{white}]{warn}>{default} {yellow}configurations file not found\n"\
@ -271,6 +273,8 @@ class Crapup():
""" """
Print the abortion message and exit Print the abortion message and exit
""" """
if self.less_output is False:
print()
print("{err}CRAPUP ABORTED{default}"\ print("{err}CRAPUP ABORTED{default}"\
.format(**self.text_colors)) .format(**self.text_colors))
if self.less_output is False: if self.less_output is False:

View File

@ -107,6 +107,7 @@ class Tree( UIobj ):
trunk = "%s/crapstats" %( self.roots ) trunk = "%s/crapstats" %( self.roots )
trunk_len = len(trunk)+1 trunk_len = len(trunk)+1
for path,dirs,files in growing( trunk ): for path,dirs,files in growing( trunk ):
dirs2del = []
# step in the correct position # step in the correct position
branch = self.tree branch = self.tree
if len(path) > trunk_len: if len(path) > trunk_len:
@ -119,9 +120,11 @@ class Tree( UIobj ):
for dir_name in dirs: for dir_name in dirs:
if dir_name.startswith('.')\ if dir_name.startswith('.')\
or dir_name in ["CVS", "backups"]: or dir_name in ["CVS", "backups"]:
dirs.remove( dir_name ) dirs2del.append( dir_name )
continue continue
branch.update({ dir_name : {} }) branch.update({ dir_name : {} })
for dir_name in dirs2del:
dirs.remove( dir_name )
# append crapstat files as paths # append crapstat files as paths
for file_name in files: for file_name in files:
if not file_name.startswith('.')\ if not file_name.startswith('.')\

View File

@ -6,7 +6,7 @@ from time import sleep
from sys import argv from sys import argv
from sys import path as libpath from sys import path as libpath
from os.path import abspath from os.path import abspath, exists
crappath = abspath(__file__) crappath = abspath(__file__)
crappath = crappath[:crappath.rfind('/')] crappath = crappath[:crappath.rfind('/')]
@ -68,39 +68,39 @@ def initCrapview( args ) -> bool :
crappath = abspath(__file__) crappath = abspath(__file__)
crappath = crappath[:crappath.rfind('/')] crappath = crappath[:crappath.rfind('/')]
path = "%s/crapconfs/crapview.crapconf" %(crappath[:crappath.rfind('/')]) path = "%s/crapconfs/crapview.crapconf" %(crappath[:crappath.rfind('/')])
if os.path.exists( path ) is False: if exists( path ) is False:
# leave this normal yellow, it's secondary and doesn't need a real attention # leave this normal yellow, it's secondary and doesn't need a real attention
if self.less_output is False: if self.less_output is False:
print("\n{warn}Warning{white}[{grey}configs{white}]{warn}>{default} {yellow}configurations file not found\n"\ print("\n{warn}Warning{white}[{grey}configs{white}]{warn}>{default} {yellow}configurations file not found\n"\
.format(**self.text_colors)) .format(**self.text_colors))
sleep(2) sleep(2)
else: else:
with open(path,'r') as f: with open(path,'r') as f:
tmp = f.read().strip().split('\n') tmp = f.read().strip().split('\n')
configs = [] configs = []
for f in tmp: for f in tmp:
f = f.strip() f = f.strip()
if f == ""\ if f == ""\
or f[0] == "#": or f[0] == "#":
continue continue
configs.append(f) configs.append(f)
# check the length # check the length
if len(configs) != 3: if len(configs) != 3:
print("\n{err}Error{white}[{grey}configs{white}]{red}>{default} invalid number of lines: {rose}%s{default}"\ print("\n{err}Error{white}[{grey}configs{white}]{red}>{default} invalid number of lines: {rose}%s{default}"\
.format(**text_colors)\ .format(**text_colors)\
%( len(configs) )) %( len(configs) ))
print(""" print("""
if you have manually edited the configurations file, please un-do the changes if you have manually edited the configurations file, please un-do the changes
else, please report this issue""") else, please report this issue""")
print("\n{err}CRAPVIEW ABORTED{default}\n"\ print("\n{err}CRAPVIEW ABORTED{default}\n"\
.format(**text_colors)) .format(**text_colors))
exit() exit()
# apply the configs # apply the configs
use_configs = bool(int(configs[0])) use_configs = bool(int(configs[0]))
if use_configs is True: if use_configs is True:
use_arguments = bool(int(configs[1])) use_arguments = bool(int(configs[1]))
use_colors = bool(int(configs[2])) use_colors = bool(int(configs[2]))
initMessages() initMessages()
if use_arguments is True: if use_arguments is True:
# parse args # parse args

View File

@ -158,7 +158,7 @@ do
then then
dst="$(echo $dst | cut -d/ -f2)/" dst="$(echo $dst | cut -d/ -f2)/"
fi fi
mv "$crapdir/$src" "$inst_path/$dst" cp "$crapdir/$src" "$inst_path/$dst"
wait wait
done done

View File

@ -20,4 +20,4 @@
# USE COLORS TO PRINT THE OUTPUT MESSAGES # USE COLORS TO PRINT THE OUTPUT MESSAGES
1 1
0