-
Notifications
You must be signed in to change notification settings - Fork 0
/
imageorganizer.py
173 lines (133 loc) · 3.47 KB
/
imageorganizer.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
import configparser
import os
from os.path import join as join
# =========================
# globals
# =========================
env_config = None
loc_config = None
#log_file = None
working_pictures = None
curr_index = None
# =========================
# useful get list or strings
# =========================
def get_files(dir):
for root, dirs, files in os.walk(os.getcwd()):
files.sort()
return files
def get_pictures(dir):
files = get_files(dir)
filetypes = env_config['settings']['filetypes'].split(',')
files = [f for f in files if os.path.splitext(f)[1] in filetypes]
return files
def get_current():
global working_pictures, curr_index
working_pictures = get_pictures(loc_config['paths']['working'])
curr_index = working_pictures.indexOf(env_config['environment']['current'])
#if (curr):
# if not(curr in files):
# if len(files) > 0:
# env_config['environment']['current'] = files[0]
# else:
# env_config['environment']['current'] = '.'
# return env_config['environment']['current']
def get_prev():
None
def get_next():
None
def get_undo():
None
# =========================
# make/load files
# =========================
def mk_env_default():
mk_env('.', ','.join(['.jpg', '.jpeg', '.png', '.bmp', '.gif']))
def mk_loc_default():
testbed = join(os.getcwd(), 'testbed')
mk_loc(
join(testbed, 'organize'),
join(testbed, 'working'),
join(testbed, 'overflow'),
join(testbed, 'transfer'),
[])
def mk_log_default():
# global log_file
log_file = open('log.dat', 'w')
# flush and close
def mk_env(current, filetypes):
global env_config
env_config = configparser.ConfigParser()
env_config['environment'] = {}
env_config['environment']['current'] = current
env_config['settings'] = {}
env_config['settings']['filetypes'] = filetypes
with open('environment.ini', 'w') as configfile:
env_config.write(configfile)
def ld_env():
None
def mk_loc(organize, working, overflow, transfer, macro_lst):
global loc_config
loc_config = configparser.ConfigParser()
loc_config['paths'] = {}
loc_config['paths']['organize'] = organize
loc_config['paths']['working'] = working
loc_config['paths']['overflow'] = overflow
loc_config['paths']['transfer'] = transfer
loc_config['macros'] = {}
for i in range(len(macro_lst)):
macro_id = 'macro' + str(i)
loc_config['macros'][macro_id] = macro_lst[i]
with open('locations.ini', 'w') as configfile:
env_config.write(configfile)
def ld_loc():
None
def ap_log(entry):
None
def rm_log():
None
# =========================
# info commands
# =========================
def do_current():
None
def do_count():
return len(get_pictures(loc_config['paths']['working']))
# =========================
# action commands
# =========================
def do_show():
None
def do_move(dest):
None
def do_next():
None
def do_prev():
None
def do_undo():
None
# =========================
# main
# =========================
def main():
print("===ImageOrganizer===")
mk_env_default()
#mk
#mk_config_default()
print(get_files(os.getcwd()))
print(get_pictures(os.getcwd()))
# for root, dirs, files in os.walk(os.getcwd()):
# files.sort()
# print(files)
# break
# for root, dirs, files in os.walk("."):
# for name in files:
# print(os.path.join(root, name))
# for name in dirs:
# print(os.path.join(root, name))
# config = configparser.ConfigParser()
# config['DEFAULT'] = {'STUFF': 1, 'THING': 2, 'BLEH': 3}
# with open('init.ini', 'w') as configfile:
# config.write(configfile)
if __name__ == "__main__":
main()