forked from specify/web-asset-server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
specify7_ipup.py
65 lines (51 loc) · 1.72 KB
/
specify7_ipup.py
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
63
64
"""this document is for seeking out files containing absolute ip address in the specify7 files, and
replace them with the current absolute ip address"""
# importing packages
import socket
import os
import re
def ip_getter():
"""ip_getter:
gets a copy of the host machine's absolute ip address
returns:
ip_ad: a copy of the host machine's absolute ip address"""
hostname = socket.gethostname()
ip_ad = socket.gethostbyname(hostname)
print(ip_ad)
return ip_ad
def set_direct():
"""get_direct: changes directory to
current file location directory
returns:
none
"""
# get current directory
# current_directory = os.getcwd()
# this is absolute path for running chron from bin
current_directory = os.path.dirname(os.path.abspath(__file__))
# set current directory
os.chdir(current_directory)
def ip_replace(filename: str):
"""ip_replace: opens a target file path, and replaces,
all references to ip addresses
to the current ip address
"""
with open(filename, 'r') as file:
# Read the contents of the file
content = file.read()
ip_ad = ip_getter()
# Replace the string
new_content = re.sub(r'\b10.1.12.\w*\b', ip_ad, content)
# Open the file in write mode
with open(filename, 'w') as file:
# Write the modified content back to the file
file.write(new_content)
def master_run():
"""runs all functions in this file sequentially"""
set_direct()
ip_replace('../specify7/docker-compose.yml')
ip_replace('settings.py')
ip_replace('docker-compose.yml')
# running master function
master_run()
print(socket.gethostname())