Files
hostpanel/ssh_manager/cross_platform_utils.py
ilkeral f4ee7a2d0b yeni
2025-08-08 07:24:25 +03:00

78 lines
2.0 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"""
Platform bağımsız yedekleme işlemleri için yardımcı fonksiyonlar
Windows ve Linux sistemlerinde tutarlı davranış sağlamak için kullanılır
"""
import os
import sys
import tempfile
import platform
def get_temp_directory():
"""
Platform bağımsız şekilde geçici dizin yolunu döndürür
"""
# Python'un tempfile modülü ile platform bağımsız geçici dizini al
temp_dir = tempfile.gettempdir()
# Dizinin var olduğunu ve yazılabilir olduğunu kontrol et
if not os.path.exists(temp_dir):
try:
os.makedirs(temp_dir)
except:
# Oluşturamazsa alternatif bir dizin kullan
if sys.platform.startswith('win'):
temp_dir = 'C:\\temp'
if not os.path.exists(temp_dir):
os.makedirs(temp_dir)
else:
temp_dir = '/var/tmp'
return temp_dir
def normalize_path(path):
"""
Platform bağımsız şekilde dosya yolunu normalleştirir
"""
# Yol ayırıcıları normalize et
path = os.path.normpath(path)
# Windows'ta UNC yolları için ek kontrol
if sys.platform.startswith('win') and path.startswith('\\\\'):
# Windows UNC yolu düzeltmesi
pass
return path
def path_join(*args):
"""
Platform bağımsız şekilde yolları birleştirir
"""
return os.path.join(*args)
def is_windows():
"""
Sistemin Windows olup olmadığını kontrol eder
"""
return sys.platform.startswith('win')
def is_linux():
"""
Sistemin Linux olup olmadığını kontrol eder
"""
return sys.platform.startswith('linux')
def get_platform_info():
"""
Platform hakkında detaylı bilgi döndürür
"""
return {
'system': platform.system(),
'release': platform.release(),
'version': platform.version(),
'python_version': platform.python_version(),
'is_windows': is_windows(),
'is_linux': is_linux(),
'temp_dir': get_temp_directory(),
}