Hi there,
So I have some code that I wrote to assist me in deploying headless pi's. I am a complete Python newb but I wrote this up and have some questions on what could have been done better.
1.) when I insert the sd card it normally mounts it to /media/daniel/ I need to change the directory where it copies the original vanilla interfaces file to the mounted files system. Something like /media/mount/rootfs/etc/interfaces.
Any how I would like someone to look over my code and if it could have been done better point me in the right direction.
Thanks,
So I have some code that I wrote to assist me in deploying headless pi's. I am a complete Python newb but I wrote this up and have some questions on what could have been done better.
import os import sys import fileinput import shutil os.chdir('/home/daniel/Documents/python_work/headlesspi/') shutil.copyfile('interfaces', 'mypi/interfaces') print("File Copy Done") textToSearch = "172.168.0.0" print ("Assign IP Address:") textToReplace = input( "> " ) os.chdir('/home/daniel/Documents/python_work/headlesspi/mypi/') fileToSearch = 'interfaces' tempFile = open( fileToSearch, 'r+' ) for line in fileinput.input( fileToSearch ): if textToSearch in line : print('Match Found') else: print('Match Not Found!!') tempFile.write( line.replace( textToSearch, textToReplace ) ) tempFile.close() input( '\n\n Press Enter to exit...' )The code works but I have a few adjustments I need to make.
1.) when I insert the sd card it normally mounts it to /media/daniel/ I need to change the directory where it copies the original vanilla interfaces file to the mounted files system. Something like /media/mount/rootfs/etc/interfaces.
Any how I would like someone to look over my code and if it could have been done better point me in the right direction.
Thanks,