yeni
This commit is contained in:
77
ssh_manager/cross_platform_utils.py
Normal file
77
ssh_manager/cross_platform_utils.py
Normal file
@ -0,0 +1,77 @@
|
||||
"""
|
||||
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(),
|
||||
}
|
||||
Reference in New Issue
Block a user