-
Notifications
You must be signed in to change notification settings - Fork 0
/
teddy.py
79 lines (63 loc) · 1.9 KB
/
teddy.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/usr/bin/env python3
import click
import os
import sys
from shutil import copyfile
@click.command()
@click.argument('filename', type=click.Path(exists=True))
def handler(filename):
# click.echo(click.format_filename(filename))
os_slash = "/"
if os.name == 'nt':
os_slash = "\\"
path = os.getcwd() + os_slash
path += click.format_filename(filename)
sorted_path = path + " Sorted"
if os.path.exists(sorted_path):
click.echo(click.style("Error", fg="red") + ": Already sorted")
sys.exit(0)
os.mkdir(sorted_path)
sorted_path += os_slash
path += os_slash
print(path)
list_dir = os.listdir(path)
sort = bubbleSort(list_dir)
counter = 0
for org in sort:
for filename in os.listdir(path):
if org == filename:
dst = str(counter + 1) + "--)" + filename
src = path + filename
dst = sorted_path + dst
copyfile(src, dst)
counter += 1
break
click.echo(click.style("Info", fg="green") + ": Sorted Successfully")
def bubbleSort(arr):
array = list(arr)
for i in range(0, len(arr)):
arr[i] = arr[i][-12:-4]
# for i in array :
# print(i)
n = len(arr)
# Traverse through all array elements
for i in range(n):
# Last i elements are already in place
for j in range(0, n - i - 1):
# traverse the array from 0 to n-i-1
# Swap if the element found is greater
# than the next element
if arr[j] > arr[j + 1]:
array[j], array[j + 1] = array[j + 1], array[j]
arr[j], arr[j + 1] = arr[j + 1], arr[j]
return array
# for arg in sys.argv:
# print(arg)
# print(os.name)
# print(os.getcwd())
# directory = os.getcwd()
# directory += "/HW"
# directory += arg[0]
# print(directory)
if __name__ == '__main__':
handler()