2011-01-18 09:24:57 +00:00
|
|
|
#
|
|
|
|
# isys.py - installer utility functions and glue for C module
|
|
|
|
#
|
2014-04-07 12:38:09 +00:00
|
|
|
# Copyright (C) 2001-2013 Red Hat, Inc.
|
2011-01-18 09:24:57 +00:00
|
|
|
# All rights reserved.
|
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation; either version 2 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
#
|
|
|
|
|
2013-01-23 17:28:19 +00:00
|
|
|
try:
|
|
|
|
from pyanaconda import _isys
|
|
|
|
except ImportError:
|
|
|
|
# We're running in some sort of testing mode, in which case we can fix
|
|
|
|
# up PYTHONPATH and just do this basic import.
|
|
|
|
import _isys
|
|
|
|
|
2014-04-07 12:38:09 +00:00
|
|
|
import blivet.arch
|
|
|
|
import time
|
|
|
|
import datetime
|
2015-05-30 11:20:59 +00:00
|
|
|
import pytz
|
2011-01-18 09:24:57 +00:00
|
|
|
|
|
|
|
import logging
|
|
|
|
log = logging.getLogger("anaconda")
|
|
|
|
|
2017-01-09 02:09:07 +00:00
|
|
|
if blivet.arch.get_arch() in ["ppc64", "ppc64le"]:
|
2015-03-23 11:36:12 +00:00
|
|
|
MIN_RAM = 768
|
|
|
|
GUI_INSTALL_EXTRA_RAM = 512
|
2014-04-07 12:38:09 +00:00
|
|
|
else:
|
2015-03-23 11:36:12 +00:00
|
|
|
MIN_RAM = 320
|
|
|
|
GUI_INSTALL_EXTRA_RAM = 90
|
2011-01-18 09:24:57 +00:00
|
|
|
|
2014-04-07 12:38:09 +00:00
|
|
|
MIN_GUI_RAM = MIN_RAM + GUI_INSTALL_EXTRA_RAM
|
2015-03-23 11:36:12 +00:00
|
|
|
SQUASHFS_EXTRA_RAM = 750
|
|
|
|
NO_SWAP_EXTRA_RAM = 200
|
2011-01-18 09:24:57 +00:00
|
|
|
|
2015-03-23 11:36:12 +00:00
|
|
|
ISO_BLOCK_SIZE = 2048
|
|
|
|
|
2011-01-18 09:24:57 +00:00
|
|
|
## Determine if a file is an ISO image or not.
|
|
|
|
# @param file The full path to a file to check.
|
|
|
|
# @return True if ISO image, False otherwise.
|
2014-04-07 12:38:09 +00:00
|
|
|
def isIsoImage(path):
|
2015-03-23 11:36:12 +00:00
|
|
|
try:
|
|
|
|
with open(path, "rb") as isoFile:
|
|
|
|
for blockNum in range(16, 100):
|
|
|
|
isoFile.seek(blockNum * ISO_BLOCK_SIZE + 1)
|
2016-04-10 04:00:00 +00:00
|
|
|
if isoFile.read(5) == b"CD001":
|
2015-03-23 11:36:12 +00:00
|
|
|
return True
|
|
|
|
except IOError:
|
|
|
|
pass
|
|
|
|
|
|
|
|
return False
|
2011-01-18 09:24:57 +00:00
|
|
|
|
|
|
|
isPAE = None
|
|
|
|
def isPaeAvailable():
|
|
|
|
global isPAE
|
|
|
|
if isPAE is not None:
|
|
|
|
return isPAE
|
|
|
|
|
|
|
|
isPAE = False
|
2017-01-09 02:09:07 +00:00
|
|
|
if not blivet.arch.is_x86():
|
2011-01-18 09:24:57 +00:00
|
|
|
return isPAE
|
|
|
|
|
|
|
|
f = open("/proc/cpuinfo", "r")
|
|
|
|
lines = f.readlines()
|
|
|
|
f.close()
|
|
|
|
|
|
|
|
for line in lines:
|
|
|
|
if line.startswith("flags") and line.find("pae") != -1:
|
|
|
|
isPAE = True
|
|
|
|
break
|
|
|
|
|
|
|
|
return isPAE
|
|
|
|
|
2014-04-07 12:38:09 +00:00
|
|
|
def isLpaeAvailable():
|
|
|
|
with open("/proc/cpuinfo", "r") as fobj:
|
|
|
|
for line in fobj:
|
|
|
|
if line.startswith("Features") and "lpae" in line.split():
|
|
|
|
return True
|
|
|
|
|
|
|
|
return False
|
2011-01-18 09:24:57 +00:00
|
|
|
|
2014-04-07 12:38:09 +00:00
|
|
|
def set_system_time(secs):
|
|
|
|
"""
|
|
|
|
Set system time to time given as a number of seconds since the Epoch.
|
|
|
|
|
|
|
|
:param secs: a number of seconds since the Epoch to set system time to
|
|
|
|
:type secs: int
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
2017-01-09 02:09:07 +00:00
|
|
|
# pylint: disable=no-member
|
2014-04-07 12:38:09 +00:00
|
|
|
_isys.set_system_time(secs)
|
2015-05-30 11:20:59 +00:00
|
|
|
log.info("System time set to %s UTC", time.asctime(time.gmtime(secs)))
|
2014-04-07 12:38:09 +00:00
|
|
|
|
|
|
|
def set_system_date_time(year=None, month=None, day=None, hour=None, minute=None,
|
2015-05-30 11:20:59 +00:00
|
|
|
second=None, tz=None):
|
2014-04-07 12:38:09 +00:00
|
|
|
"""
|
|
|
|
Set system date and time given by the parameters as numbers. If some
|
|
|
|
parameter is missing or None, the current system date/time field is used
|
|
|
|
instead (i.e. the value is not changed by this function).
|
|
|
|
|
|
|
|
:type year, month, ..., second: int
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
2015-05-30 11:20:59 +00:00
|
|
|
# If no timezone is set, use UTC
|
|
|
|
if not tz:
|
|
|
|
tz = pytz.UTC
|
|
|
|
|
2014-04-07 12:38:09 +00:00
|
|
|
# get the right values
|
2015-05-30 11:20:59 +00:00
|
|
|
now = datetime.datetime.now(tz)
|
|
|
|
year = year if year is not None else now.year
|
|
|
|
month = month if month is not None else now.month
|
|
|
|
day = day if day is not None else now.day
|
|
|
|
hour = hour if hour is not None else now.hour
|
|
|
|
minute = minute if minute is not None else now.minute
|
|
|
|
second = second if second is not None else now.second
|
|
|
|
|
2017-01-09 02:09:07 +00:00
|
|
|
set_date = tz.localize(datetime.datetime(year, month, day, hour, minute, second))
|
2015-05-30 11:20:59 +00:00
|
|
|
|
|
|
|
# Calculate the number of seconds between this time and timestamp 0
|
2017-01-09 02:09:07 +00:00
|
|
|
epoch = tz.localize(datetime.datetime.fromtimestamp(0))
|
2015-05-30 11:20:59 +00:00
|
|
|
timestamp = (set_date - epoch).total_seconds()
|
|
|
|
|
2016-04-10 04:00:00 +00:00
|
|
|
set_system_time(int(timestamp))
|
2014-04-07 12:38:09 +00:00
|
|
|
|
2015-03-23 11:36:12 +00:00
|
|
|
def total_memory():
|
|
|
|
"""Returns total system memory in kB (given to us by /proc/meminfo)"""
|
2011-01-18 09:24:57 +00:00
|
|
|
|
2015-03-23 11:36:12 +00:00
|
|
|
with open("/proc/meminfo", "r") as fobj:
|
|
|
|
for line in fobj:
|
|
|
|
if not line.startswith("MemTotal"):
|
|
|
|
# we are only interested in the MemTotal: line
|
|
|
|
continue
|
|
|
|
|
|
|
|
fields = line.split()
|
|
|
|
if len(fields) != 3:
|
|
|
|
log.error("unknown format for MemTotal line in /proc/meminfo: %s", line.rstrip())
|
|
|
|
raise RuntimeError("unknown format for MemTotal line in /proc/meminfo: %s" % line.rstrip())
|
|
|
|
|
|
|
|
try:
|
|
|
|
memsize = int(fields[1])
|
|
|
|
except ValueError:
|
|
|
|
log.error("ivalid value of MemTotal /proc/meminfo: %s", fields[1])
|
|
|
|
raise RuntimeError("ivalid value of MemTotal /proc/meminfo: %s" % fields[1])
|
|
|
|
|
|
|
|
# Because /proc/meminfo only gives us the MemTotal (total physical
|
|
|
|
# RAM minus the kernel binary code), we need to round this
|
|
|
|
# up. Assuming every machine has the total RAM MB number divisible
|
|
|
|
# by 128.
|
|
|
|
memsize /= 1024
|
|
|
|
memsize = (memsize / 128 + 1) * 128
|
|
|
|
memsize *= 1024
|
|
|
|
|
|
|
|
log.info("%d kB (%d MB) are available", memsize, memsize / 1024)
|
|
|
|
return memsize
|
|
|
|
|
|
|
|
log.error("MemTotal: line not found in /proc/meminfo")
|
|
|
|
raise RuntimeError("MemTotal: line not found in /proc/meminfo")
|
2011-01-18 09:24:57 +00:00
|
|
|
|
2017-01-09 02:09:07 +00:00
|
|
|
# pylint: disable=no-member
|
2015-05-30 11:20:59 +00:00
|
|
|
installSyncSignalHandlers = _isys.installSyncSignalHandlers
|