rpms/olpc-utils/OLPC-2 failsafe.py, NONE, 1.1 olpc-utils.spec, 1.41, 1.42

Dennis Gilmore (ausil) fedora-extras-commits at redhat.com
Wed Jul 30 19:16:34 UTC 2008


Author: ausil

Update of /cvs/extras/rpms/olpc-utils/OLPC-2
In directory cvs-int.fedora.redhat.com:/tmp/cvs-serv11324

Modified Files:
	olpc-utils.spec 
Added Files:
	failsafe.py 
Log Message:
add script for http://dev.laptop.org/ticket/7591



--- NEW FILE failsafe.py ---
#!/usr/bin/env python
# -*- coding: latin-1 -*-
#
# failsafe.py: If the NAND doesn't have enough free space, delete datastore
#              objects until it does.  This doesn't modify the datastore's
#              index.
# Author:      Chris Ball <cjb at laptop.org>

import os, sys, statvfs, subprocess, shutil

THRESHOLD = 1024 * 20  # 20MB
DATASTORE_PATH = "/home/olpc/.sugar/default/datastore/store/*-*"
ACTIVITY_PATH  = "/home/olpc/Activities/*"

def main():
    # First, check to see whether we have enough free space.
    if find_freespace() < THRESHOLD:
        print "Not enough disk space."

        # Per Trac #5637, delete orphaned leaks in .sugar/default/data.
        # This is safe on any build.
        try:
            shutil.rmtree("/home/olpc/.sugar/default/data")
        except OSError:
            pass
        
        if find_freespace() >= THRESHOLD:
            # The above gained enough free space.
            return

        # Okay, we'll have to delete some real data.
        # Add datastore files to filelist string
        lines = os.popen("du -s %s" % DATASTORE_PATH).readlines()
        
        # Add activities to filelist
        lines += (os.popen("du -s %s" % ACTIVITY_PATH).readlines())
        
        filesizes = [line.split('\t') for line in lines]
        for file in filesizes:
           file[0] = int(file[0])     # size
           file[1] = file[1].rstrip() # path
        filesizes.sort()
        filelist = [file[1] for file in filesizes]
        
        # Unfreeze the DCON, print a message.
        unfreeze_dcon()

        # The below string is in latin-1, because Unicode isn't present
        # in the environment when this script runs.
        string = """
Your disk is nearly full.  The system cannot operate with a full disk.
To create free space, some of the entries in your Journal will now be
deleted.  If you wish to avoid having items deleted, power down your
XO and bring it to an expert for backup and recovery.

Error code:  DISKFULL

Press any key to delete some Journal entries.


Su disco está casi lleno.  El sistema no puede funcionar si el disco
está lleno.  Para liberar espacio, se deben borrar algunas entradas de
su Diario ahora.  Si prefiere no tener que borrar datos, apague su XO y
llévelo a un experto para que haga una copia de seguridad y
recuperación de datos.

Código del error:  DISKFULL

Pulse cualquier tecla para borrar algunas entradas del Diario.
"""

        key = raw_input(string)

        # Now, delete files/directories one at a time.
        while find_freespace() < THRESHOLD and len(filelist) > 0:
            delete_entry(filelist.pop())

def find_freespace():
    # Determine free space on /.
    stat = os.statvfs("/")
    freebytes  = stat[statvfs.F_BSIZE] * stat[statvfs.F_BAVAIL]
    freekbytes = freebytes / 1024
    return freekbytes

def delete_entry(entry):
    # Delete a single file from the datastore, or an activity directory
    print "Deleting " + entry
    try:
        if os.path.isdir(entry):
            shutil.rmtree(entry)
        else:
            os.remove(entry)                
    except OSError:
        print "Couldn't delete " + entry

def unfreeze_dcon():
    # Don't think there's anything useful I can do if this write fails.
    dcon = open('/sys/class/backlight/dcon-bl/device/freeze', 'w')
    dcon.write('0')
    dcon.close()

main()


Index: olpc-utils.spec
===================================================================
RCS file: /cvs/extras/rpms/olpc-utils/OLPC-2/olpc-utils.spec,v
retrieving revision 1.41
retrieving revision 1.42
diff -u -r1.41 -r1.42
--- olpc-utils.spec	27 May 2008 10:16:34 -0000	1.41
+++ olpc-utils.spec	30 Jul 2008 19:16:04 -0000	1.42
@@ -1,6 +1,6 @@
 Name:		olpc-utils
 Version:	0.74
-Release:	1%{?dist}
+Release:	2%{?dist}
 Summary:	OLPC utilities
 URL:		http://dev.laptop.org/git?p=projects/olpc-utils;a=summary
 Group:		System Environment/Base
@@ -13,6 +13,7 @@
 #  ./autoconf.sh
 #  make dist
 Source0:	olpc-utils-%{version}.tar.bz2
+Source1:        http://dev.laptop.org/~cjb/failsafe.py
 Source100:	dot-xsession-example
 BuildRoot:	%{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
 
@@ -53,6 +54,10 @@
 make install DESTDIR=%{buildroot}
 
 install -D -m 0644 %{SOURCE100} $RPM_BUILD_ROOT/etc/skel/.xsession-example
+mkdir -p $RPM_BUILD_ROOT%{_sysconfdir}/rc.d/rc3.d/
+install -D -m 0755 %{SOURCE1} $RPM_BUILD_ROOT%{_sysconfdir}/rc.d/rc3.d/S02diskspacecheck
+mkdir -p $RPM_BUILD_ROOT%{_sysconfdir}/rc.d/rc5.d/
+install -D -m 0755 %{SOURCE1} $RPM_BUILD_ROOT%{_sysconfdir}/rc.d/rc5.d/S02diskspacecheck
 
 
 %post
@@ -98,9 +103,14 @@
 %{_sysconfdir}/rc.d/init.d/olpc-configure
 %{_sysconfdir}/udev/rules.d
 %{_sysconfdir}/skel/.xsession-example
+%{_sysconfdir}/rc.d/rc3.d/S02diskspacecheck
+%{_sysconfdir}/rc.d/rc5.d/S02diskspacecheck
 
 
 %changelog
+* Wed Jul 30 2008 Dennis Gilmore <dennis at laptop.org> - 0.74-2
+- add clean up script for http://dev.laptop.org/ticket/7591
+
 * Tue May 27 2008 Sayamindu Dasgupta <sayamindu at gmail.com> -0.74-1
 - dl#6945: Added workaround for typo in mfg-data for Ethiopian machines.
 




More information about the fedora-extras-commits mailing list