ia64/xen-unstable

changeset 4682:397aeb925c68

bitkeeper revision 1.1392 (4270eaf9Zx1D03KOAVKHY8tW-aANmg)

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@gmail.com>
Signed-off-by: Mike Wray <mike.wray@hp.com>
author mjw@wray-m-3.hpl.hp.com
date Thu Apr 28 13:54:01 2005 +0000 (2005-04-28)
parents f85eb51dc313
children 65b28c74cec2
files tools/pygrub/src/fsys/__init__.py tools/pygrub/src/fsys/ext2/ext2module.c tools/pygrub/src/pygrub
line diff
     1.1 --- a/tools/pygrub/src/fsys/__init__.py	Thu Apr 28 13:33:33 2005 +0000
     1.2 +++ b/tools/pygrub/src/fsys/__init__.py	Thu Apr 28 13:54:01 2005 +0000
     1.3 @@ -49,7 +49,10 @@ class FileSystem(object):
     1.4          should look similar to a native file object."""
     1.5          raise RuntimeError, "open_file not implemented"
     1.6      
     1.7 -
     1.8 +    def file_exist(self, file):
     1.9 +        """Check to see if the give file is existed.
    1.10 +        Return true if file existed, return false otherwise."""
    1.11 +        raise RuntimeError, "file_exist not implemented"
    1.12  
    1.13  mydir = sys.modules['grub.fsys'].__path__[0]
    1.14  for f in os.listdir(mydir):
     2.1 --- a/tools/pygrub/src/fsys/ext2/ext2module.c	Thu Apr 28 13:33:33 2005 +0000
     2.2 +++ b/tools/pygrub/src/fsys/ext2/ext2module.c	Thu Apr 28 13:54:01 2005 +0000
     2.3 @@ -174,6 +174,25 @@ ext2_file_open (Ext2Fs *fs, char * name,
     2.4      return (PyObject *) file;
     2.5  }
     2.6  
     2.7 +static PyObject *
     2.8 +ext2_file_exist (Ext2Fs *fs, char * name)
     2.9 +{
    2.10 +    int err;
    2.11 +    ext2_ino_t ino;
    2.12 +    Ext2File * file;
    2.13 +
    2.14 +    file = (Ext2File *) PyObject_NEW(Ext2File, &Ext2FileType);
    2.15 +    file->file = NULL;
    2.16 +
    2.17 +    err = ext2fs_namei_follow(fs->fs, EXT2_ROOT_INO, EXT2_ROOT_INO, name, &ino);
    2.18 +    if (err) {
    2.19 +        Py_INCREF(Py_False);
    2.20 +        return Py_False;
    2.21 +    }
    2.22 +    Py_INCREF(Py_True);
    2.23 +    return Py_True;
    2.24 +}
    2.25 +
    2.26  /* ext2fs object */
    2.27  
    2.28  static PyObject *
    2.29 @@ -231,6 +250,18 @@ ext2_fs_open_file (Ext2Fs *fs, PyObject 
    2.30      return ext2_file_open(fs, name, flags);
    2.31  }
    2.32  
    2.33 +static PyObject *
    2.34 +ext2_fs_file_exist (Ext2Fs *fs, PyObject *args, PyObject *kwargs)
    2.35 +{
    2.36 +    static char *kwlist[] = { "name", NULL };
    2.37 +    char * name;
    2.38 +
    2.39 +    if (!PyArg_ParseTupleAndKeywords(args, kwargs, "s", kwlist, &name))
    2.40 +                                     return NULL;
    2.41 +
    2.42 +    return ext2_file_exist(fs, name);
    2.43 +}
    2.44 +
    2.45  static void
    2.46  ext2_fs_dealloc (Ext2Fs * fs)
    2.47  {
    2.48 @@ -249,6 +280,9 @@ static struct PyMethodDef Ext2FsMethods[
    2.49          { "open_file",
    2.50            (PyCFunction) ext2_fs_open_file,
    2.51            METH_VARARGS|METH_KEYWORDS, NULL },
    2.52 +        { "file_exist",
    2.53 +          (PyCFunction) ext2_fs_file_exist,
    2.54 +          METH_VARARGS|METH_KEYWORDS, NULL },
    2.55  	{ NULL, NULL, 0, NULL }	
    2.56  };
    2.57  
    2.58 @@ -312,21 +346,20 @@ ext2_fs_new(PyObject *o, PyObject *args,
    2.59      return (PyObject *)pfs;
    2.60  }
    2.61  
    2.62 -
    2.63  static struct PyMethodDef Ext2ModuleMethods[] = {
    2.64      { "Ext2Fs", (PyCFunction) ext2_fs_new, METH_VARARGS|METH_KEYWORDS, NULL },
    2.65      { NULL, NULL, 0, NULL }
    2.66  };
    2.67  
    2.68 -
    2.69  void init_pyext2(void) {
    2.70 -    PyObject *m, *d;
    2.71 +    PyObject *m;
    2.72  
    2.73      m = Py_InitModule("_pyext2", Ext2ModuleMethods);
    2.74 -    d = PyModule_GetDict(m);
    2.75 -
    2.76 -    /*    o = PyObject_NEW(PyObject, yExt2FsConstructorType);
    2.77 -    PyDict_SetItemString(d, "PyExt2Fs", o);
    2.78 -    Py_DECREF(o);*/
    2.79 -                      
    2.80 +    /*
    2.81 +     * PyObject *d;
    2.82 +     * d = PyModule_GetDict(m);
    2.83 +     * o = PyObject_NEW(PyObject, yExt2FsConstructorType);
    2.84 +     * PyDict_SetItemString(d, "PyExt2Fs", o);
    2.85 +     * Py_DECREF(o);
    2.86 +     */
    2.87  }
     3.1 --- a/tools/pygrub/src/pygrub	Thu Apr 28 13:33:33 2005 +0000
     3.2 +++ b/tools/pygrub/src/pygrub	Thu Apr 28 13:54:01 2005 +0000
     3.3 @@ -19,6 +19,8 @@ import logging
     3.4  import curses, _curses, curses.wrapper
     3.5  import getopt
     3.6  
     3.7 +sys.path = [ '/usr/lib/python' ] + sys.path
     3.8 +
     3.9  import grub.GrubConf
    3.10  import grub.fsys
    3.11  
    3.12 @@ -78,7 +80,6 @@ def is_disk_image(file):
    3.13      if len(buf) >= 512 and struct.unpack("H", buf[0x1fe: 0x200]) == (0xaaff):
    3.14          return True
    3.15      return False
    3.16 -    
    3.17  
    3.18  def get_config(fn):
    3.19      if not os.access(fn, os.R_OK):
    3.20 @@ -97,7 +98,14 @@ def get_config(fn):
    3.21              break
    3.22  
    3.23      if fs is not None:
    3.24 -        f = fs.open_file("/boot/grub/grub.conf")
    3.25 +        if fs.file_exist("/boot/grub/menu.lst"):
    3.26 +            grubfile = "/boot/grub/menu.lst"
    3.27 +        elif fs.file_exist("/boot/grub/grub.conf"):
    3.28 +            grubfile = "/boot/grub/grub.conf"
    3.29 +        else:
    3.30 +            raise RuntimeError, "we couldn't find /boot/grub{menu.lst,grub.conf} " + \
    3.31 +                                "in the image provided. halt!"
    3.32 +        f = fs.open_file(grubfile)
    3.33          buf = f.read()
    3.34          f.close()
    3.35          fs.close()