Repository navigation
Expand file tree
/
Copy pathfix_paths.py
More file actions
62 lines (50 loc) · 1.92 KB
/
Copy pathfix_paths.py
File metadata and controls
62 lines (50 loc) · 1.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/usr/bin/env python3
# fix_paths.py - Arregla paths hardcoded de Termux
import os
import re
# Archivos a arreglar
files = [
'./blockchain/transaction.py',
'./blockchain/block.py',
'./blockchain/blockchain.py',
'./blockchain/block_explorer.py',
'./blockchain/difficulty.py',
'./blockchain/storage.py',
'./wallet/wallet.py',
'./wallet/transaction_history.py',
'./wallet/faucet.py',
'./network/node.py',
'./utils/statistics.py',
'./colcript.py',
'./api/server.py',
'./test_difficulty.py',
'./contracts/smart_contract.py',
'./mining/pool.py'
]
old_pattern = "project_root = '/data/data/com.termux/files/home/ColCript'"
new_code = """# Obtener ruta absoluta del proyecto de forma dinámica
project_root = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))"""
# Para archivos en la raíz (solo un nivel arriba)
root_files_pattern = ['./colcript.py', './test_difficulty.py']
print("🔧 Arreglando paths hardcoded...\n")
for filepath in files:
if not os.path.exists(filepath):
print(f"⚠️ Archivo no encontrado: {filepath}")
continue
with open(filepath, 'r') as f:
content = f.read()
if old_pattern in content:
# Archivos en raíz necesitan solo un dirname
if filepath in root_files_pattern:
replacement = "project_root = os.path.dirname(os.path.abspath(__file__))"
else:
replacement = "project_root = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))"
content = content.replace(old_pattern, replacement)
with open(filepath, 'w') as f:
f.write(content)
print(f"✅ {filepath}")
else:
print(f"⏭️ {filepath} (ya arreglado o sin path)")
print("\n✅ Todos los paths arreglados!\n")
print("🧪 Probando que funcione:")
print(" python -c 'from blockchain.blockchain import Blockchain; print(\"OK\")'")