Skip to content

Commit

Permalink
refactor:resource_path
Browse files Browse the repository at this point in the history
  • Loading branch information
Guovin committed Nov 4, 2024
1 parent 6c02579 commit 3e72102
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 24 deletions.
2 changes: 1 addition & 1 deletion main.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import asyncio
from utils.config import resource_path
import utils.constants as constants
from utils.channel import (
get_channel_items,
Expand All @@ -20,6 +19,7 @@
process_nested_dict,
format_interval,
check_ipv6_support,
resource_path,
)
from updates.subscribe import get_channels_by_subscribe_urls
from updates.multicast import get_channels_by_multicast
Expand Down
2 changes: 1 addition & 1 deletion tkinter_ui/about.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import tkinter as tk
from PIL import Image, ImageTk
import webbrowser
from utils.config import resource_path
from utils.tools import resource_path


class AboutUI:
Expand Down
3 changes: 1 addition & 2 deletions updates/fofa/request.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from utils.config import resource_path
import utils.constants as constants
from tqdm.asyncio import tqdm_asyncio
from time import time
Expand All @@ -9,7 +8,7 @@
import re
from utils.retry import retry_func
from utils.channel import format_channel_name
from utils.tools import merge_objects, get_pbar_remaining, add_url_info
from utils.tools import merge_objects, get_pbar_remaining, add_url_info, resource_path
from updates.proxy import get_proxy, get_proxy_next
from requests_custom.utils import get_source_requests, close_session
from collections import defaultdict
Expand Down
3 changes: 1 addition & 2 deletions updates/multicast/update_tmp.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@

from updates.subscribe import get_channels_by_subscribe_urls
from driver.utils import get_soup_driver
from utils.config import resource_path
import utils.constants as constants
from utils.channel import format_channel_name, get_name_url
from utils.tools import get_pbar_remaining
from utils.tools import get_pbar_remaining, resource_path
import json

# import asyncio
Expand Down
18 changes: 1 addition & 17 deletions utils/config.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,7 @@
import os
import sys
import configparser
import shutil


def resource_path(relative_path, persistent=False):
"""
Get the resource path
"""
base_path = os.path.abspath(".")
total_path = os.path.join(base_path, relative_path)
if persistent or os.path.exists(total_path):
return total_path
else:
try:
base_path = sys._MEIPASS
return os.path.join(base_path, relative_path)
except Exception:
return total_path
from utils.tools import resource_path


def get_config():
Expand Down
18 changes: 17 additions & 1 deletion utils/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
import ipaddress
from urllib.parse import urlparse
import socket
from utils.config import resource_path
from utils.constants import get_resolution_value
import utils.constants as constants
import re
from bs4 import BeautifulSoup
from flask import render_template_string, send_file
import shutil
import requests
import sys


def format_interval(t):
Expand Down Expand Up @@ -458,3 +458,19 @@ def remove_cache_info(str):
Remove the cache info from the string
"""
return re.sub(r"cache:.*|\|cache:.*", "", str)


def resource_path(relative_path, persistent=False):
"""
Get the resource path
"""
base_path = os.path.abspath(".")
total_path = os.path.join(base_path, relative_path)
if persistent or os.path.exists(total_path):
return total_path
else:
try:
base_path = sys._MEIPASS
return os.path.join(base_path, relative_path)
except Exception:
return total_path

0 comments on commit 3e72102

Please sign in to comment.