mirror of
https://github.com/clinton-hall/nzbToMedia.git
synced 2025-08-19 21:03:14 -07:00
Refactor path functions from utils to utils.paths
This commit is contained in:
parent
2d6e8034e2
commit
a50a5edbf7
2 changed files with 45 additions and 37 deletions
|
@ -3,7 +3,6 @@
|
||||||
from __future__ import print_function, unicode_literals
|
from __future__ import print_function, unicode_literals
|
||||||
|
|
||||||
import datetime
|
import datetime
|
||||||
from functools import partial
|
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
import shutil
|
import shutil
|
||||||
|
@ -26,6 +25,7 @@ from core.utils.parsers import (
|
||||||
parse_args, parse_deluge, parse_other, parse_qbittorrent, parse_rtorrent, parse_transmission,
|
parse_args, parse_deluge, parse_other, parse_qbittorrent, parse_rtorrent, parse_transmission,
|
||||||
parse_utorrent, parse_vuze,
|
parse_utorrent, parse_vuze,
|
||||||
)
|
)
|
||||||
|
from core.utils.paths import get_dir_size, make_dir, remote_dir
|
||||||
from core.utils.processes import RunningProcess
|
from core.utils.processes import RunningProcess
|
||||||
from core.utils.torrents import create_torrent_class, pause_torrent, remove_torrent, resume_torrent
|
from core.utils.torrents import create_torrent_class, pause_torrent, remove_torrent, resume_torrent
|
||||||
|
|
||||||
|
@ -74,33 +74,6 @@ def sanitize_name(name):
|
||||||
return name
|
return name
|
||||||
|
|
||||||
|
|
||||||
def make_dir(path):
|
|
||||||
if not os.path.isdir(path):
|
|
||||||
try:
|
|
||||||
os.makedirs(path)
|
|
||||||
except Exception:
|
|
||||||
return False
|
|
||||||
return True
|
|
||||||
|
|
||||||
|
|
||||||
def remote_dir(path):
|
|
||||||
if not core.REMOTEPATHS:
|
|
||||||
return path
|
|
||||||
for local, remote in core.REMOTEPATHS:
|
|
||||||
if local in path:
|
|
||||||
base_dirs = path.replace(local, '').split(os.sep)
|
|
||||||
if '/' in remote:
|
|
||||||
remote_sep = '/'
|
|
||||||
else:
|
|
||||||
remote_sep = '\\'
|
|
||||||
new_path = remote_sep.join([remote] + base_dirs)
|
|
||||||
new_path = re.sub(r'(\S)(\\+)', r'\1\\', new_path)
|
|
||||||
new_path = re.sub(r'(/+)', r'/', new_path)
|
|
||||||
new_path = re.sub(r'([/\\])$', r'', new_path)
|
|
||||||
return new_path
|
|
||||||
return path
|
|
||||||
|
|
||||||
|
|
||||||
def category_search(input_directory, input_name, input_category, root, categories):
|
def category_search(input_directory, input_name, input_category, root, categories):
|
||||||
tordir = False
|
tordir = False
|
||||||
|
|
||||||
|
@ -195,14 +168,6 @@ def category_search(input_directory, input_name, input_category, root, categorie
|
||||||
return input_directory, input_name, input_category, root
|
return input_directory, input_name, input_category, root
|
||||||
|
|
||||||
|
|
||||||
def get_dir_size(input_path):
|
|
||||||
prepend = partial(os.path.join, input_path)
|
|
||||||
return sum([
|
|
||||||
(os.path.getsize(f) if os.path.isfile(f) else get_dir_size(f))
|
|
||||||
for f in map(prepend, os.listdir(text_type(input_path)))
|
|
||||||
])
|
|
||||||
|
|
||||||
|
|
||||||
def is_min_size(input_name, min_size):
|
def is_min_size(input_name, min_size):
|
||||||
file_name, file_ext = os.path.splitext(os.path.basename(input_name))
|
file_name, file_ext = os.path.splitext(os.path.basename(input_name))
|
||||||
|
|
||||||
|
|
43
core/utils/paths.py
Normal file
43
core/utils/paths.py
Normal file
|
@ -0,0 +1,43 @@
|
||||||
|
|
||||||
|
from functools import partial
|
||||||
|
import os
|
||||||
|
import re
|
||||||
|
|
||||||
|
from six import text_type
|
||||||
|
|
||||||
|
import core
|
||||||
|
|
||||||
|
|
||||||
|
def make_dir(path):
|
||||||
|
if not os.path.isdir(path):
|
||||||
|
try:
|
||||||
|
os.makedirs(path)
|
||||||
|
except Exception:
|
||||||
|
return False
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
def remote_dir(path):
|
||||||
|
if not core.REMOTEPATHS:
|
||||||
|
return path
|
||||||
|
for local, remote in core.REMOTEPATHS:
|
||||||
|
if local in path:
|
||||||
|
base_dirs = path.replace(local, '').split(os.sep)
|
||||||
|
if '/' in remote:
|
||||||
|
remote_sep = '/'
|
||||||
|
else:
|
||||||
|
remote_sep = '\\'
|
||||||
|
new_path = remote_sep.join([remote] + base_dirs)
|
||||||
|
new_path = re.sub(r'(\S)(\\+)', r'\1\\', new_path)
|
||||||
|
new_path = re.sub(r'(/+)', r'/', new_path)
|
||||||
|
new_path = re.sub(r'([/\\])$', r'', new_path)
|
||||||
|
return new_path
|
||||||
|
return path
|
||||||
|
|
||||||
|
|
||||||
|
def get_dir_size(input_path):
|
||||||
|
prepend = partial(os.path.join, input_path)
|
||||||
|
return sum([
|
||||||
|
(os.path.getsize(f) if os.path.isfile(f) else get_dir_size(f))
|
||||||
|
for f in map(prepend, os.listdir(text_type(input_path)))
|
||||||
|
])
|
Loading…
Add table
Add a link
Reference in a new issue