Skip to content

Commit

Permalink
Addressing Codacy feedback
Browse files Browse the repository at this point in the history
And reworking the mv command in response to feedback it was too complicated. Let's see if this improves. A few other methods also flagged as too complicated by Codacy.
  • Loading branch information
bernd-wechner committed Mar 4, 2021
1 parent cf8ac62 commit 040d78f
Show file tree
Hide file tree
Showing 5 changed files with 324 additions and 219 deletions.
9 changes: 4 additions & 5 deletions build.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,22 @@
import stat

source = "commands.py"
commands = ["cd", "get", "ll", "login", "ls", "mkdir", "path", "props", "put", "pwd", "rm", "tree", "user", "test",
"mv"]
commands = ["cd", "get", "ll", "login", "ls", "mkdir", "path", "props", "put", "pwd", "rm", "mv", "tree", "user", "test"]

# Make sure the os. functions have the script dir as their working directory
cwd = os.path.dirname(os.path.abspath(__file__))
os.chdir(cwd)

if os.getcwd() == cwd:
Commands = [degoo.command_prefix + c for c in commands]

for c in Commands:
try:
os.link(source, c)
os.chmod(c, stat.S_IRWXU | stat.S_IRGRP | stat.S_IXGRP | stat.S_IROTH | stat.S_IXOTH);
os.chmod(c, stat.S_IRWXU | stat.S_IRGRP | stat.S_IXGRP | stat.S_IROTH | stat.S_IXOTH);
except FileExistsError:
pass

# TODO: Copy default_properties to config dir.
# TODO: Create test_data folder if it doesn't exist
else:
Expand Down
45 changes: 36 additions & 9 deletions commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,16 @@
import os
import sys
import textwrap
import traceback

from argparse import ArgumentParser, HelpFormatter

__all__ = []
__version__ = 0.1
__date__ = '2020-06-03'
__updated__ = '2020-06-03'

DEBUG = 0
DEBUG = 1
TESTRUN = 0
PROFILE = 0

Expand All @@ -41,7 +43,7 @@ class CLIError(Exception):

def __init__(self, msg):
super().__init__(type(self))
self.msg = f"Eror: {msg}"
self.msg = f"Error: {msg}"

def __str__(self):
return self.msg
Expand All @@ -66,6 +68,10 @@ def main(argv=None): # IGNORE:C0111

command = os.path.basename(sys.argv[0])

if not command.startswith(P):
command = sys.argv[0] = P + sys.argv[1]
sys.argv.pop(1)

program_version = f"v{__version__}"
program_build_date = str(__updated__)
program_version_message = '%%(prog)s %s (%s)' % (program_version, program_build_date)
Expand Down Expand Up @@ -156,7 +162,8 @@ def main(argv=None): # IGNORE:C0111
parser.add_argument('folder', help='The folder/path to list')
args = parser.parse_args()

path = degoo.mkpath(args.folder)
ID = degoo.mkpath(args.folder)
path = degoo.get_item(ID)["FilePath"]
print(f"Created folder {path}")

elif command == P + "rm":
Expand All @@ -167,14 +174,21 @@ def main(argv=None): # IGNORE:C0111
print(f"Deleted {path}")

elif command == P + "mv":
parser.add_argument('file', help='The path of file/folder to be moved')
parser.add_argument('destination_path', help='Path where the file or directory will be moved')
parser.add_argument('source', help='The path of file/folder to be moved')
parser.add_argument('target', help='Path where the file or directory will be moved')

args = parser.parse_args()

result = degoo.mv(args.file, args.destination_path)
message = 'success' if result else 'failed'
print(f"Move { message }")
abs_from = degoo.util.path_str(args.source)

try:
ID = degoo.mv(args.source, args.target)

if ID:
abs_to = degoo.util.path_str(ID)
print(f"Moved {abs_from} to {abs_to}")
except Exception as e:
print(e)

elif command == P + "get":
parser.add_argument('-d', '--dryrun', action='store_true', help="Show what would be uploaded but don't upload it.")
Expand Down Expand Up @@ -232,7 +246,20 @@ def main(argv=None): # IGNORE:C0111
return 0
except Exception as e:
if DEBUG or TESTRUN:
raise(e)

def format_exception(e):
exception_list = traceback.format_stack()
exception_list = exception_list[:-2]
exception_list.extend(traceback.format_tb(sys.exc_info()[2]))
exception_list.extend(traceback.format_exception_only(sys.exc_info()[0], sys.exc_info()[1]))

exception_str = "Traceback (most recent call last):\n"
exception_str += "".join(exception_list)

return exception_str

sys.stderr.write(format_exception(e))

indent = len(command) * " "
sys.stderr.write(command + ": " + str(e) + "\n")
sys.stderr.write(indent + " for help use --help\n")
Expand Down
Loading

0 comments on commit 040d78f

Please sign in to comment.