better log file

This commit is contained in:
brent s 2017-05-07 11:21:44 -04:00
parent ffedfaf684
commit c64b800618

View File

@ -16,6 +16,7 @@ try:
except ImportError: except ImportError:
import xml.etree.ElementTree as etree # https://docs.python.org/3/library/xml.etree.elementtree.html import xml.etree.ElementTree as etree # https://docs.python.org/3/library/xml.etree.elementtree.html
lxml_avail = False lxml_avail = False
import datetime
import shlex import shlex
import fileinput import fileinput
import os import os
@ -31,7 +32,7 @@ import urllib.response as urlresponse
from ftplib import FTP_TLS from ftplib import FTP_TLS
from io import StringIO from io import StringIO


logfile = '/root/log' logfile = '/root/aif.log.{0}'.format(int(datetime.datetime.utcnow().timestamp()))


class aif(object): class aif(object):
@ -881,6 +882,9 @@ class archInstall(object):
scripts = self.scripts scripts = self.scripts
if not pkgcmds: if not pkgcmds:
pkgcmds = self.packagecmds() pkgcmds = self.packagecmds()
# Switch in the log, and link.
os.rename(logfile, '{0}/{1}'.format(self.system['chrootpath'], logfile))
os.symlink('{0}/{1}'.format(self.system['chrootpath'], logfile), logfile)
self.pacmanSetup() # This needs to be done before the chroot self.pacmanSetup() # This needs to be done before the chroot
# We don't need this currently, but we might down the road. # We don't need this currently, but we might down the road.
#chrootscript = '#!/bin/bash\n# https://aif.square-r00t.net/\n\n' #chrootscript = '#!/bin/bash\n# https://aif.square-r00t.net/\n\n'
@ -922,6 +926,9 @@ class archInstall(object):
def unmount(self): def unmount(self):
with open(logfile, 'a') as log: with open(logfile, 'a') as log:
subprocess.call(['umount', '-lR', self.system['chrootpath']], stdout = log, stderr = subprocess.STDOUT) subprocess.call(['umount', '-lR', self.system['chrootpath']], stdout = log, stderr = subprocess.STDOUT)
# We should also remove the (now dead) log symlink.
#Note that this does NOT delete the logfile on the installed system.
os.remove(logfile)
return() return()
def runInstall(confdict): def runInstall(confdict):