From: <ale...@us...> - 2008-03-14 13:45:21
|
Revision: 2618 http://morphix.svn.sourceforge.net/morphix/?rev=2618&view=rev Author: alextreme Date: 2008-03-14 06:45:18 -0700 (Fri, 14 Mar 2008) Log Message: ----------- * adding make-mini-home Modified Paths: -------------- trunk/morph-scripts/Makefile trunk/morph-scripts/debian/changelog trunk/morph-scripts/debian/control trunk/morph-scripts/debian/rules Added Paths: ----------- trunk/morph-scripts/make-mini-home/ trunk/morph-scripts/make-mini-home/linux_devices.py trunk/morph-scripts/make-mini-home/make-mini-home.py trunk/morph-scripts/make-mini-home/zenity_wrapper.py Modified: trunk/morph-scripts/Makefile =================================================================== --- trunk/morph-scripts/Makefile 2008-02-26 19:59:44 UTC (rev 2617) +++ trunk/morph-scripts/Makefile 2008-03-14 13:45:18 UTC (rev 2618) @@ -98,6 +98,13 @@ cp ./morphmini/morphmini $(DESTDIR)/usr/sbin/morphmini chmod a+x $(DESTDIR)/usr/sbin/morphmini +morphix-make-mini-home: + mkdir -p $(DESTDIR)/usr/sbin + mkdir -p $(DESTDIR)/usr/lib/morphix-make-mini-home + cp ./make-mini-home/*.py $(DESTDIR)/usr/lib/morphix-make-mini-home/ + ln -s ../lib/morphix-make-mini-home/make-mini-home.py $(DESTDIR)/usr/sbin/make-mini-home + chmod a+x $(DESTDIR)/usr/sbin/make-mini-home + remove: rm $(DESTDIR)/usr/sbin/install2mainmod rm $(DESTDIR)/usr/sbin/isomorph.pl @@ -115,3 +122,5 @@ rm $(DESTDIR)/usr/sbin/morphix-rebrand rm $(DESTDIR)/usr/sbin/morphix-chroot rm $(DESTDIR)/usr/share/morphix-rebrand/morphix-iso-grubtheme_0.1-4.tar.gz + rm $(DESTDIR)/usr/sbin/make-mini-home + rm -r $(DESTDIR)/usr/lib/morphix-make-mini-home Modified: trunk/morph-scripts/debian/changelog =================================================================== --- trunk/morph-scripts/debian/changelog 2008-02-26 19:59:44 UTC (rev 2617) +++ trunk/morph-scripts/debian/changelog 2008-03-14 13:45:18 UTC (rev 2618) @@ -1,3 +1,9 @@ +morph-scripts (0.2-36) unstable; urgency=low + + * Adding morphix-make-mini-home (a GUI-tool for creating a homedir minimod and storing it on a USB storage device) + + -- Alex de Landgraaf <al...@de...> Fri, 14 Mar 2008 14:34:16 +0100 + morph-scripts (0.2-35) unstable; urgency=low * Workround for transparent poxy servers that cache stale/old files. Modified: trunk/morph-scripts/debian/control =================================================================== --- trunk/morph-scripts/debian/control 2008-02-26 19:59:44 UTC (rev 2617) +++ trunk/morph-scripts/debian/control 2008-03-14 13:45:18 UTC (rev 2618) @@ -8,7 +8,7 @@ Package: morphing-tools Provides: morphix-tools, morph-scripts Architecture: any -Depends: morphix-moduleloader, morphix-isomorph, morphix-install2mainmod, morphix-changekernel, morphix-make-iso, morphix-modulebuilder, morphix-moduleextractor, morphix-minimodgen, morphix-deb-get, morphix-addtoiso, morphix-converttobootimg, morphix-buildminimod, morphix-mmaker, morphix-morphmini, morphix-rebrand, morphix-chroot +Depends: morphix-moduleloader, morphix-isomorph, morphix-install2mainmod, morphix-changekernel, morphix-make-iso, morphix-modulebuilder, morphix-moduleextractor, morphix-minimodgen, morphix-deb-get, morphix-addtoiso, morphix-converttobootimg, morphix-buildminimod, morphix-mmaker, morphix-morphmini, morphix-rebrand, morphix-chroot, morphix-make-mini-home Description: Metapackage for all Morphix commandline tools Metapackage for all Morphix commandline tools that handle modules. See separate packages for descriptions @@ -121,3 +121,14 @@ Architecture: any Depends: coreutils, morphix-modulebuilder, morphix-moduleextractor Description: chroot into a Morphix MainModule. + +Package: morphix-make-mini-home +Architecture: any +Depends: morphix-mmaker, morphix-modulebuilder, zenity, python +Description: Stores the current home-directory on to a USB storage device. + This interactive zenity-based script gives the user a few questions, + after which a Morphix minimodule is stored upon a selected USB storage device. + . + The point of this tool is to allow a user to save his current home directory + without having to touch the command-line. Also an excuse to play around + with zenity. Modified: trunk/morph-scripts/debian/rules =================================================================== --- trunk/morph-scripts/debian/rules 2008-02-26 19:59:44 UTC (rev 2617) +++ trunk/morph-scripts/debian/rules 2008-03-14 13:45:18 UTC (rev 2618) @@ -67,6 +67,7 @@ $(MAKE) morphmini DESTDIR=$(CURDIR)/debian/morphix-morphmini $(MAKE) morphix-rebrand DESTDIR=$(CURDIR)/debian/morphix-rebrand $(MAKE) morphix-chroot DESTDIR=$(CURDIR)/debian/morphix-chroot + $(MAKE) morphix-make-mini-home DESTDIR=$(CURDIR)/debian/morphix-make-mini-home dh_install -s # Must not depend on anything. This is to be called by Added: trunk/morph-scripts/make-mini-home/linux_devices.py =================================================================== --- trunk/morph-scripts/make-mini-home/linux_devices.py (rev 0) +++ trunk/morph-scripts/make-mini-home/linux_devices.py 2008-03-14 13:45:18 UTC (rev 2618) @@ -0,0 +1,42 @@ +import os + +def get_usb_devices(): + """ + Assume: udev is enabled + """ + + udev_usb = "/dev/disk/by-id" + files = os.listdir(udev_usb) + usb_devices = [] + for file in files: + if not file.startswith("usb-") or file.find("-part") == -1: + continue + + file_str = file[4:] + parts = file_str.split("_") + if len(parts) < 2: + continue + dest = os.readlink(udev_usb + "/" + file) + dest_dev = dest[-4:] + if len(dest_dev) != 4: + continue + + usb_devices += [[file, parts[0] + " " + parts[1] + " " + parts[2], dest_dev]] + + return usb_devices + +def get_partition_size(partition): + proc_partitions = "/proc/partitions" + + fd = open(proc_partitions, "r") + data = fd.read() + fd.close() + + data = data.split("\n") + for line in data[2:]: + line_data = line.split() + if len(line_data) != 4: + continue + if line_data[3] == partition: + return line_data[2] + return -1 Added: trunk/morph-scripts/make-mini-home/make-mini-home.py =================================================================== --- trunk/morph-scripts/make-mini-home/make-mini-home.py (rev 0) +++ trunk/morph-scripts/make-mini-home/make-mini-home.py 2008-03-14 13:45:18 UTC (rev 2618) @@ -0,0 +1,79 @@ +#!/usr/bin/python + +import sys, os, time, zenity_wrapper + +import linux_devices + +mount_directory = "/tmp/morphix-make-mini-home" +minimod_directory = mount_directory + "/minimod" +minimod_name = "MorphixHomedirMini.mod" + +if os.getuid() != 0: + zenity_wrapper.zenity_info("Unable to continue", "'USB home-dir' requires you to be root in order to proceed. Please start this tool as root or via sudo and try again") + sys.exit(1) + +ret = zenity_wrapper.zenity_question("Save changes", "'USB home-dir' will let you save any changes you made within your home directory to any USB storage device with enough free space. If you have this device inserted before you boot this Live CD/DVD all changes will be restored.\n\nPlease connect your USB storage device before continuing.") + +if ret != 0: + sys.exit(1) + +time.sleep(2) + +# find devices: ls -l /dev/disk/by-id/usb-* +# or /proc/partitions + +usb_devices = linux_devices.get_usb_devices() +print usb_devices +storage_list = [] +for device in usb_devices: + size = linux_devices.get_partition_size(device[2]) + storage_list += [[ device[1] + ", " + str(int(size) / 1024) + "MB (" + device[2] + ")", usb_devices]] + +selected = zenity_wrapper.zenity_list("Select USB storage device", "Select the inserted device", "Devices found", storage_list) + +selected_device = [] +for item in storage_list: + if selected.strip() == item[0].strip(): + selected_device = item[1][0] + +if selected_device == []: + zenity_wrapper.zenity_info("No device selected, aborting", "No USB device was selected upon which to store the files from the current home directory, unable to continue") + sys.exit(1) + +### We have a USB device upon which to store our mini-module ### + + + +# Just to be sure... +os.system("umount " + mount_directory) +try: + os.mkdir(mount_directory) +except: # Ignore if already exists + pass +print selected_device +os.system("mount /dev/" + selected_device[2] + " " + mount_directory) + +# FIXME: We'll just assume that mounting worked, for now... + +try: + os.mkdir(minimod_directory) +except: # Again, ignore if exists + pass + +if os.access(minimod_directory + "/" + minimod_name, os.F_OK): + ret = zenity_wrapper.zenity_question("Replace exisiting home directory files?", "An existing home directory file has been found on the selected USB storage device. Do you want to replace it?") + if ret != 0: + zenity_wrapper.zenity_info("Unable to continue", "As you have selected not to replace the current home directory file 'USB home-dir' will now exit. Please select a different USB storage device, or make sure the existing home directory file can be replaced.") + sys.exit(1) + +cmd = "make-mini --homedir-all " + minimod_directory + "/" + minimod_name +print cmd +os.system(cmd) + +# Flush filesystem buffers and umount +os.system('sync') +time.sleep(2) +os.system("umount " + mount_directory) + +zenity_wrapper.zenity_info("Completed", "All files in your home directory have been stored to the USB storage device (" + selected_device[1] + ", in the file /minimod/" + minimod_name + "). \n\nUpon reboot all stored files will be available in your home directory") + Added: trunk/morph-scripts/make-mini-home/zenity_wrapper.py =================================================================== --- trunk/morph-scripts/make-mini-home/zenity_wrapper.py (rev 0) +++ trunk/morph-scripts/make-mini-home/zenity_wrapper.py 2008-03-14 13:45:18 UTC (rev 2618) @@ -0,0 +1,28 @@ +import os, subprocess + +def zenity_info(title, text): + """ + Assume: title and text are strings + """ + + return os.system('zenity --title="' + title + '" --info --text="' + text + '"') + +def zenity_question(title, text): + """ + Assume: title and text are strings + """ + + return os.system('zenity --title="' + title + '" --question --text="' + text + '"') + +def zenity_list(title, text, header, choices): + """ + Assume: title, text, header are strings + """ + + choices_str = "" + for choice in choices: + choices_str += choice[0] + " " + + p = subprocess.Popen(['zenity', '--title="' + title + '"', '--list', '--text="' + text + '"', '--column="' + header + '"', choices_str], stdout = subprocess.PIPE) + return p.communicate()[0] + This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |