[PATCH 1/4] Convert isys.isIsoImage to python code
David Shea
dshea at redhat.com
Mon Feb 24 14:27:02 UTC 2014
This removes the need for isys.h and brings the _isys module down to a
single C file.
---
pyanaconda/isys/Makefile.am | 10 +-------
pyanaconda/isys/__init__.py | 13 ++++++++++-
pyanaconda/isys/isofs.c | 57 ---------------------------------------------
pyanaconda/isys/isys.c | 17 --------------
pyanaconda/isys/isys.h | 31 ------------------------
5 files changed, 13 insertions(+), 115 deletions(-)
delete mode 100644 pyanaconda/isys/isofs.c
delete mode 100644 pyanaconda/isys/isys.h
diff --git a/pyanaconda/isys/Makefile.am b/pyanaconda/isys/Makefile.am
index 8a26aa7..0253491 100644
--- a/pyanaconda/isys/Makefile.am
+++ b/pyanaconda/isys/Makefile.am
@@ -19,8 +19,6 @@
pkgpyexecdir = $(pyexecdir)/py$(PACKAGE_NAME)
-ISYS_SRCS = isofs.c
-
dist_noinst_HEADERS = $(srcdir)/*.h
ISYS_CFLAGS = -DVERSION_RELEASE='"$(PACKAGE_VERSION)-$(PACKAGE_RELEASE)"' \
@@ -34,13 +32,7 @@ pkgpyexec_LTLIBRARIES = _isys.la
_isys_la_CFLAGS = $(PYTHON_CFLAGS) $(ISYS_CFLAGS)
_isys_la_LDFLAGS = -module -avoid-version
_isys_la_LIBADD = $(PYTHON_LIBS) $(ISYS_LIBS)
-_isys_la_SOURCES = isys.c $(ISYS_SRCS)
-
-noinst_LTLIBRARIES = libisys.la
-libisys_la_CFLAGS = $(ISYS_CFLAGS)
-libisys_la_LDFLAGS = -static
-libisys_la_LIBADD = $(ISYS_LIBS)
-libisys_la_SOURCES = $(ISYS_SRCS)
+_isys_la_SOURCES = isys.c
auditddir = $(libexecdir)/$(PACKAGE_NAME)
auditd_PROGRAMS = auditd
diff --git a/pyanaconda/isys/__init__.py b/pyanaconda/isys/__init__.py
index 5fb29f4..a1c7998 100644
--- a/pyanaconda/isys/__init__.py
+++ b/pyanaconda/isys/__init__.py
@@ -62,11 +62,22 @@ def isPseudoTTY (fd):
def sync ():
return _isys.sync ()
+ISO_BLOCK_SIZE = 2048
+
## 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.
def isIsoImage(path):
- return _isys.isisoimage(path)
+ try:
+ with open(path, "rb") as isoFile:
+ for blockNum in range(16, 100):
+ isoFile.seek(blockNum * ISO_BLOCK_SIZE + 1)
+ if isoFile.read(5) == "CD001":
+ return True
+ except IOError:
+ pass
+
+ return False
isPAE = None
def isPaeAvailable():
diff --git a/pyanaconda/isys/isofs.c b/pyanaconda/isys/isofs.c
deleted file mode 100644
index f144114..0000000
--- a/pyanaconda/isys/isofs.c
+++ /dev/null
@@ -1,57 +0,0 @@
-/*
- * isofs.c
- *
- * Copyright (C) 2007 Red Hat, Inc. 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/>.
- */
-
-#include "config.h"
-
-#include <fcntl.h>
-#include <string.h>
-#include <unistd.h>
-
-#define BLOCK_SIZE 2048
-
-/* returns 1 if file is an ISO, 0 otherwise */
-int fileIsIso(const char * file) {
- int blkNum;
- char magic[5];
- int fd;
-
- fd = open(file, O_RDONLY);
- if (fd < 0)
- return 0;
-
- for (blkNum = 16; blkNum < 100; blkNum++) {
- if (lseek(fd, blkNum * BLOCK_SIZE + 1, SEEK_SET) < 0) {
- close(fd);
- return 0;
- }
-
- if (read(fd, magic, sizeof(magic)) != sizeof(magic)) {
- close(fd);
- return 0;
- }
-
- if (!strncmp(magic, "CD001", 5)) {
- close(fd);
- return 1;
- }
- }
-
- close(fd);
- return 0;
-}
diff --git a/pyanaconda/isys/isys.c b/pyanaconda/isys/isys.c
index 103967b..2a00471 100644
--- a/pyanaconda/isys/isys.c
+++ b/pyanaconda/isys/isys.c
@@ -67,15 +67,12 @@
#include <sys/sysmacros.h>
#endif
-#include "isys.h"
-
#ifndef CDROMEJECT
#define CDROMEJECT 0x5309
#endif
static PyObject * doisPseudoTTY(PyObject * s, PyObject * args);
static PyObject * doSync(PyObject * s, PyObject * args);
-static PyObject * doisIsoImage(PyObject * s, PyObject * args);
static PyObject * doSegvHandler(PyObject *s, PyObject *args);
static PyObject * doGetAnacondaVersion(PyObject * s, PyObject * args);
static PyObject * doSetSystemTime(PyObject *s, PyObject *args);
@@ -83,7 +80,6 @@ static PyObject * doSetSystemTime(PyObject *s, PyObject *args);
static PyMethodDef isysModuleMethods[] = {
{ "isPseudoTTY", (PyCFunction) doisPseudoTTY, METH_VARARGS, NULL},
{ "sync", (PyCFunction) doSync, METH_VARARGS, NULL},
- { "isisoimage", (PyCFunction) doisIsoImage, METH_VARARGS, NULL},
{ "handleSegv", (PyCFunction) doSegvHandler, METH_VARARGS, NULL },
{ "getAnacondaVersion", (PyCFunction) doGetAnacondaVersion, METH_VARARGS, NULL },
{ "set_system_time", (PyCFunction) doSetSystemTime, METH_VARARGS, NULL},
@@ -119,19 +115,6 @@ static PyObject * doSync(PyObject * s, PyObject * args) {
return Py_None;
}
-int fileIsIso(const char * file);
-
-static PyObject * doisIsoImage(PyObject * s, PyObject * args) {
- char * fn;
- int rc;
-
- if (!PyArg_ParseTuple(args, "s", &fn)) return NULL;
-
- rc = fileIsIso(fn);
-
- return Py_BuildValue("i", rc);
-}
-
static PyObject * doSegvHandler(PyObject *s, PyObject *args) {
void *array[20];
size_t size;
diff --git a/pyanaconda/isys/isys.h b/pyanaconda/isys/isys.h
deleted file mode 100644
index ad31f7b..0000000
--- a/pyanaconda/isys/isys.h
+++ /dev/null
@@ -1,31 +0,0 @@
-/*
- * isys.h
- *
- * Copyright (C) 2007 Red Hat, Inc. 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/>.
- */
-
-#ifndef H_ISYS
-#define H_ISYS
-
-#define OUTPUT_TERMINAL "/dev/tty5"
-
-int insmod(char * modName, char * path, char ** args);
-int rmmod(char * modName);
-
-/* returns 0 for true, !0 for false */
-int fileIsIso(const char * file);
-
-#endif
--
1.9.0
More information about the anaconda-patches
mailing list