Skip to content

Interactive

interactive #

Module contains the procedures used for Interactive Mode.

This module has been deprecated.#

InteractiveCreator() #

Class namespace for interactive program options.

@Deprecated

Initialize interactive meta file creator dialog.

@Deprecated

Source code in torrentfile\interactive.py
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
def __init__(self):
    """
    Initialize interactive meta file creator dialog.

    @Deprecated
    """
    self.kwargs = {
        "announce": None,
        "url_list": None,
        "private": None,
        "source": None,
        "comment": None,
        "piece_length": None,
        "outfile": None,
        "path": None,
        "httpseeds": None,
    }
    self.outfile, self.meta = self.get_props()

get_props() #

Gather details for torrentfile from user.

@Deprecated

Source code in torrentfile\interactive.py
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
def get_props(self):
    """
    Gather details for torrentfile from user.

    @Deprecated
    """
    piece_length = get_input("Piece Length (empty=auto): ",
                             lambda x: x.isdigit())

    self.kwargs["piece_length"] = piece_length
    announce = get_input("Tracker list (empty): ",
                         lambda x: isinstance(x, str))

    if announce:
        self.kwargs["announce"] = announce.split()

    url_list = get_input("Web Seed {GetRight} list (empty): ",
                         lambda x: isinstance(x, str))

    httpseeds = get_input("Web Seed {Hoffman} list (empty): ",
                          lambda x: isinstance(x, str))

    if url_list:
        self.kwargs["url_list"] = url_list.split()
    if httpseeds:
        self.kwargs["httpseeds"] = httpseeds.split()
    comment = get_input("Comment (empty): ", None)

    if comment:
        self.kwargs["comment"] = comment
    source = get_input("Source (empty): ", None)

    if source:
        self.kwargs["source"] = source

    private = get_input("Private Torrent? {Y/N}: (N)",
                        lambda x: x in "yYnN")

    if private and private.lower() == "y":
        self.kwargs["private"] = 1

    contents = get_input("Content Path: ", os.path.exists)
    self.kwargs["path"] = contents

    outfile = get_input(
        f"Output Path ({contents}.torrent): ",
        lambda x: os.path.exists(os.path.dirname(x)),
    )

    if outfile:
        self.kwargs["outfile"] = outfile

    meta_version = get_input("Meta Version {1,2,3}: (1)",
                             lambda x: x in "123")

    showcenter(f"creating {outfile}")

    if meta_version == "3":
        torrent = TorrentFileHybrid(**self.kwargs)
    elif meta_version == "2":
        torrent = TorrentFileV2(**self.kwargs)
    else:
        torrent = TorrentFile(**self.kwargs)
    return torrent.write()

InteractiveEditor(metafile: str) #

Interactive dialog class for torrent editing.

@Deprecated

Initialize the Interactive torrent editor guide.

@Deprecated

PARAMETER DESCRIPTION
metafile

user input string identifying the path to a torrent meta file.

TYPE: str

Source code in torrentfile\interactive.py
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
def __init__(self, metafile: str):
    """
    Initialize the Interactive torrent editor guide.

    @Deprecated

    Parameters
    ----------
    metafile : str
        user input string identifying the path to a torrent meta file.
    """
    self.metafile = metafile
    self.meta = pyben.load(metafile)
    self.info = self.meta["info"]

    self.args = {
        "url-list": self.meta.get("url-list", None),
        "httpseeds": self.meta.get("httpseeds", None),
        "announce": self.meta.get("announce-list", None),
        "source": self.info.get("source", None),
        "private": self.info.get("private", None),
        "comment": self.info.get("comment", None),
    }

edit_props() #

Loop continuosly for edits until user signals DONE.

@Deprecated

Source code in torrentfile\interactive.py
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
def edit_props(self):
    """
    Loop continuosly for edits until user signals DONE.

    @Deprecated
    """
    while True:
        showcenter("Choose the number for a propert the needs editing."
                   "Enter DONE when all editing has been completed.")

        props = {
            1: "comment",
            2: "source",
            3: "private",
            4: "tracker",
            5: "web-seed",
            6: "httpseeds",
        }

        args = {
            1: "comment",
            2: "source",
            3: "private",
            4: "announce",
            5: "url-list",
            6: "httpseeds",
        }

        txt = ", ".join((str(k) + ": " + v) for k, v in props.items())
        prop = get_input(txt)
        if prop.lower() == "done":
            break

        if prop.isdigit() and 0 < int(prop) < 6:
            key = props[int(prop)]
            key2 = args[int(prop)]
            val = self.args.get(key2)
            showtext(
                "Enter new property value or leave empty for no value.")
            response = get_input(f"{key.title()} ({val}): ")
            self.sanatize_response(key2, response)

        else:
            showtext("Invalid input: Try again.")
    edit_torrent(self.metafile, self.args)

sanatize_response(key, response) #

Convert the input data into a form recognizable by the program.

@ Deprecated

PARAMETER DESCRIPTION
key

name of the property and attribute being eddited.

TYPE: str

response

User input value the property is being edited to.

TYPE: str

Source code in torrentfile\interactive.py
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
def sanatize_response(self, key, response):
    """
    Convert the input data into a form recognizable by the program.

    @ Deprecated

    Parameters
    ----------
    key : str
        name of the property and attribute being eddited.
    response : str
        User input value the property is being edited to.
    """
    if key in ["announce", "url-list", "httpseeds"]:
        val = response.split()
    else:
        val = response
    self.args[key] = val

show_current() #

Display the current met file information to screen.

@Deprecated

Source code in torrentfile\interactive.py
240
241
242
243
244
245
246
247
248
249
250
251
def show_current(self):
    """
    Display the current met file information to screen.

    @Deprecated
    """
    out = "Current properties and values:\n"
    longest = max(len(label) for label in self.args) + 3
    for key, val in self.args.items():
        txt = (key.title() + ":").ljust(longest) + str(val)
        out += f"\t{txt}\n"
    showtext(out)

create_torrent() #

Create new torrent file interactively.

@Deprecated

Source code in torrentfile\interactive.py
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
def create_torrent():
    """
    Create new torrent file interactively.

    @Deprecated
    """
    showcenter("Create Torrent")
    showtext(
        "\nEnter values for each of the options for the torrent creator, "
        "or leave blank for program defaults.\nSpaces are considered item "
        "seperators for options that accept a list of values.\nValues "
        "enclosed in () indicate the default value, while {} holds all "
        "valid choices available for the option.\n\n")
    creator = InteractiveCreator()
    return creator

edit_action() #

Edit the editable values of the torrent meta file.

@Deprecated

Source code in torrentfile\interactive.py
196
197
198
199
200
201
202
203
204
205
206
def edit_action():
    """
    Edit the editable values of the torrent meta file.

    @Deprecated
    """
    showcenter("Edit Torrent")
    metafile = get_input("Metafile(.torrent): ", os.path.exists)
    dialog = InteractiveEditor(metafile)
    dialog.show_current()
    dialog.edit_props()

get_input(*args: tuple) #

Determine appropriate input function to call.

@Deprecated

PARAMETER DESCRIPTION
*args

Arbitrary number of args to pass to next function

TYPE: tuple DEFAULT: ()

RETURNS DESCRIPTION
str

The results of the function call.

Source code in torrentfile\interactive.py
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
def get_input(*args: tuple):  # pragma: no cover
    """
    Determine appropriate input function to call.

    @Deprecated

    Parameters
    ----------
    *args : tuple
        Arbitrary number of args to pass to next function

    Returns
    -------
    str
        The results of the function call.
    """
    if len(args) == 2:
        return _get_input_loop(*args)
    return _get_input(*args)

recheck_torrent() #

Check torrent download completed percentage.

@Deprecated

Source code in torrentfile\interactive.py
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
def recheck_torrent():
    """
    Check torrent download completed percentage.

    @Deprecated
    """
    showcenter("Check Torrent")
    msg = "Enter path to torrent contents, and corresponding torrent metafile."
    showtext(msg)
    metafile = get_input("Conent Path (downloads/complete/torrentname):",
                         os.path.exists)
    contents = get_input("Metafile (*.torrent): ", os.path.exists)
    checker = Checker(metafile, contents)
    results = checker.results()
    showtext(f"Completion for {metafile} is {results}%")
    return results

select_action() #

Operate TorrentFile program interactively through terminal.

DEPRECATION WARNING: The interactive CLI feature will be deprecated in the future.

Source code in torrentfile\interactive.py
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
def select_action():
    """
    Operate TorrentFile program interactively through terminal.

    DEPRECATION WARNING: The interactive CLI feature will be deprecated
    in the future.
    """
    showcenter("TorrentFile: Starting Interactive Mode")
    showcenter("DEPRECATION WARNING: The interactive feature will be"
               "deprecated in the near future.")
    action = get_input("Enter the action you wish to perform.\n"
                       "Action ( Create (c) | Edit (e) | Recheck (r) ): ")
    action = action.lower()

    if "create" in action or action == "c":
        return create_torrent()

    if "check" in action or action == "r":
        return recheck_torrent()

    if "edit" in action or action == "e":
        return edit_action()
    print("Unable to recognize input.  Please try again.")  # pragma: nocover
    return select_action()  # pragma: nocover

showcenter(txt: str) #

Print text to screen in the center position of the terminal.

@Deprecated

PARAMETER DESCRIPTION
txt

the preformated message to send to stdout.

TYPE: str

Source code in torrentfile\interactive.py
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
def showcenter(txt: str):
    """
    Print text to screen in the center position of the terminal.

    @Deprecated

    Parameters
    ----------
    txt : str
        the preformated message to send to stdout.
    """
    termlen = shutil.get_terminal_size().columns
    padding = " " * int(((termlen - len(txt)) / 2))
    string = "".join(["\n", padding, txt, "\n"])
    showtext(string)

showtext(txt) #

Print contents of txt to screen.

@Deprecated

PARAMETER DESCRIPTION
txt

text to print to terminal.

TYPE: str

Source code in torrentfile\interactive.py
104
105
106
107
108
109
110
111
112
113
114
115
def showtext(txt):
    """
    Print contents of txt to screen.

    @Deprecated

    Parameters
    ----------
    txt : str
        text to print to terminal.
    """
    sys.stdout.write(txt)