Skip to content

Commit 2d1622f

Browse files
author
Attila Szöllősi
committed
Add symlink support
1 parent 990820f commit 2d1622f

File tree

1 file changed

+50
-45
lines changed

1 file changed

+50
-45
lines changed

addon.py

Lines changed: 50 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ def add_labels(self):
4848
self.help_label = pyxbmct.Label("Help")
4949
self.placeControl(self.help_label, 2, 2, columnspan=2)
5050

51-
self.symlink_label = pyxbmct.Label("Symlink destination")
52-
self.placeControl(self.symlink_label, 7, 0, columnspan=2)
51+
self.destination_label = pyxbmct.Label("Destination:")
52+
self.placeControl(self.destination_label, 7, 0, columnspan=2)
5353

5454
def add_textboxes(self):
5555
self.help_textbox = pyxbmct.TextBox()
@@ -77,15 +77,18 @@ def add_edits(self):
7777
self.files_edit = pyxbmct.Edit("Files to select")
7878
self.placeControl(self.files_edit, 4, 0, columnspan=2)
7979

80-
self.symlink_edit = pyxbmct.Edit("Set symlink destination")
81-
self.placeControl(self.symlink_edit, 8, 0, columnspan=2)
80+
self.destination_edit = pyxbmct.Edit("Set destination")
81+
self.placeControl(self.destination_edit, 8, 0, columnspan=2)
8282

8383
def add_radiobuttons(self):
8484
self.files_radiobutton = pyxbmct.RadioButton("Select all files inside the directory")
8585
self.placeControl(self.files_radiobutton, 6, 0, columnspan=2)
8686

87+
self.working_dir_radiobutton = pyxbmct.RadioButton("Stay in working directory")
88+
self.placeControl(self.working_dir_radiobutton, 10, 0)
89+
8790
self.symlink_radiobutton = pyxbmct.RadioButton("Use symlinks")
88-
self.placeControl(self.symlink_radiobutton, 10, 0, columnspan=2)
91+
self.placeControl(self.symlink_radiobutton, 10, 1)
8992

9093
def add_buttons(self):
9194
self.source_browse_button = pyxbmct.Button("Browse")
@@ -100,11 +103,11 @@ def add_buttons(self):
100103
self.files_clear_button = pyxbmct.Button("Clear")
101104
self.placeControl(self.files_clear_button, 5, 1)
102105

103-
self.symlink_browse_button = pyxbmct.Button("Browse")
104-
self.placeControl(self.symlink_browse_button, 9, 0)
106+
self.destination_browse_button = pyxbmct.Button("Browse")
107+
self.placeControl(self.destination_browse_button, 9, 0)
105108

106-
self.symlink_clear_button = pyxbmct.Button("Clear")
107-
self.placeControl(self.symlink_clear_button, 9, 1)
109+
self.destination_clear_button = pyxbmct.Button("Clear")
110+
self.placeControl(self.destination_clear_button, 9, 1)
108111

109112
self.help_button = pyxbmct.Button("Help")
110113
self.placeControl(self.help_button, 9, 2)
@@ -124,10 +127,9 @@ def connect_controls(self):
124127
self.connect(self.files_browse_button, self.files_browse)
125128
self.connect(self.files_clear_button, self.files_clear)
126129
self.connect(self.files_radiobutton, self.files_all)
127-
self.connect(self.symlink_browse_button, self.symlink_browse)
128-
self.connect(self.symlink_clear_button, self.symlink_clear)
129-
self.connect(self.symlink_radiobutton, self.symlink_radiobutton_handler)
130-
self.symlink_radiobutton_handler()
130+
self.connect(self.destination_browse_button, self.destination_browse)
131+
self.connect(self.destination_clear_button, self.destination_clear)
132+
self.connect(self.working_dir_radiobutton, self.working_dir_radiobutton_handler)
131133
self.connect(self.settings_button, addon.openSettings)
132134
self.connect(self.close_button, self.close)
133135
self.connect(self.start_button, self.start)
@@ -167,29 +169,26 @@ def files_all(self):
167169
self.files_browse_button.setEnabled(True)
168170
self.files_clear_button.setEnabled(True)
169171

170-
def symlink_browse(self):
171-
self.symlink_edit.setText(self.dialog.choose_directory("Select symlink target directory"))
172-
173-
def symlink_clear(self):
174-
self.symlink_edit.setText("")
172+
def destination_browse(self):
173+
self.destination_edit.setText(self.dialog.choose_directory("Select target directory"))
175174

176-
def symlink_radiobutton_handler(self):
177-
use_symlinks = self.symlink_radiobutton.isSelected()
175+
def destination_clear(self):
176+
self.destination_edit.setText("")
178177

179-
if use_symlinks:
180-
# Not yet implemented
181-
self.dialog.ok("Alert", "This feature is not yet implemented.")
182-
self.symlink_radiobutton.setSelected(False)
183-
self.symlink_radiobutton_handler()
184-
# self.symlink_label.setEnabled(True)
185-
# self.symlink_edit.setEnabled(True)
186-
# self.symlink_browse_button.setEnabled(True)
187-
# self.symlink_clear_button.setEnabled(True)
178+
def working_dir_radiobutton_handler(self):
179+
use_working_dir = self.working_dir_radiobutton.isSelected()
180+
if use_working_dir:
181+
self.destination_label.setEnabled(False)
182+
self.destination_edit.setEnabled(False)
183+
self.destination_browse_button.setEnabled(False)
184+
self.destination_clear_button.setEnabled(False)
185+
self.symlink_radiobutton.setEnabled(False)
188186
else:
189-
self.symlink_label.setEnabled(False)
190-
self.symlink_edit.setEnabled(False)
191-
self.symlink_browse_button.setEnabled(False)
192-
self.symlink_clear_button.setEnabled(False)
187+
self.destination_label.setEnabled(True)
188+
self.destination_edit.setEnabled(True)
189+
self.destination_browse_button.setEnabled(True)
190+
self.destination_clear_button.setEnabled(True)
191+
self.symlink_radiobutton.setEnabled(True)
193192

194193
def start(self):
195194
# get settings
@@ -198,7 +197,7 @@ def start(self):
198197
# parse data from Edits
199198
source_path = self.source_edit.getText()
200199

201-
if self.check_if_empty(source_path):
200+
if not source_path:
202201
self.dialog.alert("You must specify the source directory.")
203202
return
204203

@@ -209,18 +208,30 @@ def start(self):
209208
else:
210209
filenames = self.files_edit.getText()
211210

212-
if self.check_if_empty(filenames):
213-
self.dialog.alert("You should specify, what files to select.")
211+
if not filenames:
212+
self.dialog.alert("You must specify, what files to select.")
214213
return
215214

216215
filenames = filenames.split('; ')
217216
paths = [os.path.join(source_path, filename)
218217
for filename in filenames]
219218
paths = tuple(paths)
220219

220+
stay_in_working_dir = self.working_dir_radiobutton.isSelected()
221+
if stay_in_working_dir:
222+
destination = None
223+
use_symlink = False
224+
else:
225+
destination = self.destination_edit.getText()
226+
if not destination:
227+
self.dialog.alert("You must specify a destination path.")
228+
return
229+
use_symlink = self.symlink_radiobutton.isSelected()
230+
231+
221232
regex = self.regex_edit.getText()
222233

223-
if self.check_if_empty(regex):
234+
if not regex:
224235
self.dialog.alert("You must specify a regular expression.")
225236
return
226237

@@ -233,9 +244,9 @@ def start(self):
233244
episode=None, ignore_filelist=(), log_file=None,
234245
log_level=None, name=None, no_cache=False,
235246
output_format=None, organise=True, partial=False,
236-
quiet=False, recursive=False, rename_dir=None,
247+
quiet=False, recursive=False, rename_dir=destination,
237248
regex=regex, season=None, show=None,
238-
show_override=None, specials=None, symlink=False,
249+
show_override=None, specials=None, symlink=use_symlink,
239250
the=False, paths=paths)
240251

241252
from tvrenamr.logs import log_buffer
@@ -245,12 +256,6 @@ def start(self):
245256
self.dialog.textviewer("Log", log_buffer.getvalue())
246257
log_buffer.truncate(0)
247258

248-
def check_if_empty(self, string):
249-
if string == "":
250-
return True
251-
else:
252-
return False
253-
254259
window = RenamerDialog("TV Show renamer")
255260
window.doModal()
256261
del window

0 commit comments

Comments
 (0)