ChangeSet 1.1392, 2005/04/28 14:54:01+01:00, mjw@xxxxxxxxxxxxxxxxxxx
Apply Nguyen's patch:
- extend filesystem abstraction by adding file_exist() method. this
method is used to check for existent of a file given its name. now
ext2fs implements this method.
- pygrub opens and parses /boot/grub/menu.lst or /boot/grub/grub.conf,
in that order.
- add /usr/lib/python to system path (see pygrub). without this
change, pygrub cannot find grub python package.
- remove few blank lines
Signed-off-by: Nguyen Anh Quynh <aquynh@xxxxxxxxx>
Signed-off-by: Mike Wray <mike.wray@xxxxxx>
fsys/__init__.py | 5 +++-
fsys/ext2/ext2module.c | 51 ++++++++++++++++++++++++++++++++++++++++---------
pygrub | 12 +++++++++--
3 files changed, 56 insertions(+), 12 deletions(-)
diff -Nru a/tools/pygrub/src/fsys/__init__.py
b/tools/pygrub/src/fsys/__init__.py
--- a/tools/pygrub/src/fsys/__init__.py 2005-05-13 16:05:36 -04:00
+++ b/tools/pygrub/src/fsys/__init__.py 2005-05-13 16:05:36 -04:00
@@ -49,7 +49,10 @@
should look similar to a native file object."""
raise RuntimeError, "open_file not implemented"
-
+ def file_exist(self, file):
+ """Check to see if the give file is existed.
+ Return true if file existed, return false otherwise."""
+ raise RuntimeError, "file_exist not implemented"
mydir = sys.modules['grub.fsys'].__path__[0]
for f in os.listdir(mydir):
diff -Nru a/tools/pygrub/src/fsys/ext2/ext2module.c
b/tools/pygrub/src/fsys/ext2/ext2module.c
--- a/tools/pygrub/src/fsys/ext2/ext2module.c 2005-05-13 16:05:36 -04:00
+++ b/tools/pygrub/src/fsys/ext2/ext2module.c 2005-05-13 16:05:36 -04:00
@@ -174,6 +174,25 @@
return (PyObject *) file;
}
+static PyObject *
+ext2_file_exist (Ext2Fs *fs, char * name)
+{
+ int err;
+ ext2_ino_t ino;
+ Ext2File * file;
+
+ file = (Ext2File *) PyObject_NEW(Ext2File, &Ext2FileType);
+ file->file = NULL;
+
+ err = ext2fs_namei_follow(fs->fs, EXT2_ROOT_INO, EXT2_ROOT_INO, name,
&ino);
+ if (err) {
+ Py_INCREF(Py_False);
+ return Py_False;
+ }
+ Py_INCREF(Py_True);
+ return Py_True;
+}
+
/* ext2fs object */
static PyObject *
@@ -231,6 +250,18 @@
return ext2_file_open(fs, name, flags);
}
+static PyObject *
+ext2_fs_file_exist (Ext2Fs *fs, PyObject *args, PyObject *kwargs)
+{
+ static char *kwlist[] = { "name", NULL };
+ char * name;
+
+ if (!PyArg_ParseTupleAndKeywords(args, kwargs, "s", kwlist, &name))
+ return NULL;
+
+ return ext2_file_exist(fs, name);
+}
+
static void
ext2_fs_dealloc (Ext2Fs * fs)
{
@@ -249,6 +280,9 @@
{ "open_file",
(PyCFunction) ext2_fs_open_file,
METH_VARARGS|METH_KEYWORDS, NULL },
+ { "file_exist",
+ (PyCFunction) ext2_fs_file_exist,
+ METH_VARARGS|METH_KEYWORDS, NULL },
{ NULL, NULL, 0, NULL }
};
@@ -312,21 +346,20 @@
return (PyObject *)pfs;
}
-
static struct PyMethodDef Ext2ModuleMethods[] = {
{ "Ext2Fs", (PyCFunction) ext2_fs_new, METH_VARARGS|METH_KEYWORDS, NULL },
{ NULL, NULL, 0, NULL }
};
-
void init_pyext2(void) {
- PyObject *m, *d;
+ PyObject *m;
m = Py_InitModule("_pyext2", Ext2ModuleMethods);
- d = PyModule_GetDict(m);
-
- /* o = PyObject_NEW(PyObject, yExt2FsConstructorType);
- PyDict_SetItemString(d, "PyExt2Fs", o);
- Py_DECREF(o);*/
-
+ /*
+ * PyObject *d;
+ * d = PyModule_GetDict(m);
+ * o = PyObject_NEW(PyObject, yExt2FsConstructorType);
+ * PyDict_SetItemString(d, "PyExt2Fs", o);
+ * Py_DECREF(o);
+ */
}
diff -Nru a/tools/pygrub/src/pygrub b/tools/pygrub/src/pygrub
--- a/tools/pygrub/src/pygrub 2005-05-13 16:05:36 -04:00
+++ b/tools/pygrub/src/pygrub 2005-05-13 16:05:36 -04:00
@@ -19,6 +19,8 @@
import curses, _curses, curses.wrapper
import getopt
+sys.path = [ '/usr/lib/python' ] + sys.path
+
import grub.GrubConf
import grub.fsys
@@ -78,7 +80,6 @@
if len(buf) >= 512 and struct.unpack("H", buf[0x1fe: 0x200]) == (0xaaff):
return True
return False
-
def get_config(fn):
if not os.access(fn, os.R_OK):
@@ -97,7 +98,14 @@
break
if fs is not None:
- f = fs.open_file("/boot/grub/grub.conf")
+ if fs.file_exist("/boot/grub/menu.lst"):
+ grubfile = "/boot/grub/menu.lst"
+ elif fs.file_exist("/boot/grub/grub.conf"):
+ grubfile = "/boot/grub/grub.conf"
+ else:
+ raise RuntimeError, "we couldn't find
/boot/grub{menu.lst,grub.conf} " + \
+ "in the image provided. halt!"
+ f = fs.open_file(grubfile)
buf = f.read()
f.close()
fs.close()
_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog
|