| mikshaw  
 
  
 
 
 Group: Members
 Posts: 4856
 Joined: July 2004
 | 
|  | Posted: May 18 2007,19:13 |  |  Update to ucitool.lua.
 It now uses io.popen to avoid the need for a temp file. This means murgaLua 0.4.1 is required, which is not yet available in DSL.
 http://www.murga-projects.com/murgaLua/index.html
 
 I'm still not completely happy with the way packages are built (seems a bit messy), and I have to find a more dependable way to compare files in /ramdisk with those in /home/dsl, /opt, and others.
 I also have done very little streamlining. I'm sure there are things that could improve its performance.
 
 
 | Code Sample |  | #!/home/dsl/bin/murgaLua -- mounts, umounts and builds .uci extensions
 -- (c) 2005,2006 mikshaw
 --
 -- Changelog (yyyy/mm/dd)
 --    2007/05/18: Removed the need for a temp file
 --                  (requires murgaLua 0.4.1 or newer)
 --                Cut "/ramdisk" from mtab names to prevent duplicate listings
 --                  (must watch for possible bugs from this)
 --    2006/11/12: Fixed md5sum not finding uci file
 --                Removed unnecessary "about" tab
 --    2006/10/23: Fixed multiple trailing slashes on dir name
 --                Sort the list of available packges
 --                Consolidated mount and umount functions
 --    2006/10/21: Added basic feature to build UCI packages
 --                UCI directory can be specified via UCITOOL_DIR
 --    2006/09/05: Port to MurgaLua
 --                Added tabs and ability to mount packages
 --                Output of mydsl-load is displayed in the gui
 --    2005/12/30: Changed UI to match DSL tools
 --                Added hotkey support
 --                Auto-selects first line for better keyboard support
 --    2005/12/09: Displays total number of mounted UCIs
 --    2005/12/08: First release
 --
 -- TODO: Make it fully keyboard controllable (is that possible with fltk?)
 -----------------------------------------------------------------------------
 
 ww=420; wh=240;      -- window size
 tx=2; ty=27;         -- tab position
 tw=ww-4; th=wh-2; -- tab size
 bw=120; bh=30;       -- button size
 pwd=os.getenv("PWD")
 --ucidir="/cdrom/mydsl/optional" -- default uci directory
 ucidir="/home/dsl/mydsl/optional" -- default uci directory
 
 -- check for UCITOOL_DIR environment variable
 ucivar=os.getenv("UCITOOL_DIR")
 if murgaLua.isDirectory(ucivar) then ucidir=ucivar end
 
 
 -- done at startup, add/remove a uci, and when "refresh" is pressed
 function build_uci_lists()
 -- add mounted files from mtab to ufiles window
 local cmd=io.popen("grep \"^.*.uci \" /etc/mtab | awk '{print $1}' | sed 's/ramdisk\\/home/home/' | sort") --
 ufiles:clear()
 --for line in io.lines(tempfile) do ufiles:add(line) end
 for line in cmd:lines() do ufiles:add(line) end --
 mounted=cmd:read("*a") --
 cmd:close() --
 ufiles:redraw()
 -- compare mtab UCI files (tempfile) with files in ucidir
 if murgaLua.isDirectory(ucidir) then
 allfiles=murgaLua.readDirectory(ucidir)
 table.sort(allfiles)
 -- list only *.uci files that are not in mtab
 mfiles:clear()
 for i=0,table.getn(allfiles) do
 if string.find(allfiles[i],".uci",-4,plain) then
 if not string.find(mounted,allfiles[i].."\n") then mfiles:add(ucidir.."/"..allfiles[i]) end
 end
 end
 mfiles:redraw()
 end
 end
 
 -- choose a different uci directory
 function browse_cb()
 new_ucidir=fltk.fl_dir_chooser("choose a uci directory",ucidir,"*",0)
 if murgaLua.isDirectory(new_ucidir) then
 -- remove trailing slash if found
 ucidir=string.gsub(new_ucidir,"%/*$","")
 build_uci_lists() end
 end
 
 -- run mydsl-load on selected files
 function mount_cb(self)
 tab3:show()
 tab1:hide()
 tab2:hide()
 -- mount or umount? Uses the button label
 if self:label() == "mount" then lst=mfiles else lst=ufiles end
 for i = 1,lst:nitems() do
 if lst:checked(i)==1 then
 local cmd=io.popen("mydsl-load "..lst:text(i))
 -- print mydsl-load output to browser
 for line in cmd:lines() do outpoot:add(line) end
 outpoot:bottomline(outpoot:size())
 cmd:close()
 end
 end
 build_uci_lists()
 end
 
 -- BEGIN interface
 w=fltk:Fl_Double_Window(ww,wh,"UCI Tool");
 
 tabs=fltk:Fl_Tabs(tx,2,tw,th);
 tabs:selection_color(7);
 tabs:color(1);
 
 tab1 = fltk:Fl_Group(tx,ty,tw,th,"available UCIs");
 -- checklist of unmounted ucis
 mfiles=fltk:Fl_Check_Browser(tx+2,ty+2,tw-4,th-bh*2); mfiles:box(fltk.FL_THIN_DOWN_BOX);
 -- this label MUST be "mount"
 mount=fltk:Fl_Button(tx,th-bh,bw,bh,"mount"); mount:box(fltk.FL_THIN_UP_BOX);
 mount:callback(mount_cb);
 browse=fltk:Fl_Button(ww-bw-2,th-bh,bw,bh,"change directory"); browse:box(fltk.FL_THIN_UP_BOX);
 browse:callback(browse_cb);
 fltk:Fl_End();
 
 tab2 = fltk:Fl_Group(tx,ty,tw,th,"mounted UCIs");
 -- checklist of mounted ucis
 ufiles=fltk:Fl_Check_Browser(tx+2,ty+2,tw-4,th-bh*2); ufiles:box(fltk.FL_THIN_DOWN_BOX);
 umount=fltk:Fl_Button(tx,th-bh,bw,bh,"umount"); umount:box(fltk.FL_THIN_UP_BOX);
 umount:callback(mount_cb);
 refresh=fltk:Fl_Button(ww-bw-2,th-bh,bw,bh,"refresh list"); refresh:box(fltk.FL_THIN_UP_BOX);
 refresh:callback(build_uci_lists);
 fltk:Fl_End();
 
 tab3 = fltk:Fl_Group(tx,ty,tw,th-bh,"output")
 -- output display
 outpoot=fltk:Fl_Browser(tx+2,ty+2,tw-4,th-bh*2); outpoot:box(fltk.FL_THIN_DOWN_BOX)
 outpoot:format_char(0);
 clearout=fltk:Fl_Button(ww-bw-2,th-bh,bw,bh,"clear"); clearout:box(fltk.FL_THIN_UP_BOX);
 clearout:callback(function(clearout) outpoot:clear() end)
 fltk:Fl_End();
 
 tab4 = fltk:Fl_Group(tx,ty,tw,th-bh,"build your own");
 frame=fltk:Fl_Box(tx+2,ty+2,tw-4,th-bh); frame:box(fltk.FL_THIN_DOWN_BOX);
 createinfo=fltk:Fl_Box(tx+12,ty,tw-24,th-bh*3,"The \"MAKE PACKAGE\" button will build a UCI extension using the directory entered in the box below.\n\
 Created files will include "..pwd.."/name.uci and "..pwd.."/name.uci.md5.txt, where \"name\" is the basename of the source directory.")
 createinfo:align(fltk.FL_ALIGN_WRAP)
 createdir=fltk:Fl_Input(tx+12,th-bh*2-4,tw-bh-24,bh); createdir:box(fltk.FL_THIN_DOWN_BOX)
 createdir:label("source directory:"); createdir:align(fltk.FL_ALIGN_LEFT_TOP)
 createbut=fltk:Fl_Button(tx+12,th-bh-4,tw-24,bh,"MAKE PACKAGE")
 createbut:box(fltk.FL_THIN_UP_BOX); createbut:labelfont(fltk.FL_HELVETICA_BOLD)
 cdbut=fltk:Fl_Button(tw-40,th-bh*2-4,bh,bh,"...")
 cdbut:box(fltk.FL_THIN_UP_BOX)
 cdbut:callback (
 function(cd_cb)
 ucisource=fltk.fl_dir_chooser("choose a source directory",pwd,"*",0)
 if murgaLua.isDirectory(ucisource) then createdir:value(ucisource) end
 end
 )
 createbut:callback (
 function(make_package)
 if murgaLua.isDirectory(createdir:value()) then
 -- trim trailing slash(es), if needed
 trim=string.gsub(createdir:value(),"%/*$","")
 -- get basename
 newuciname=string.gsub(trim,".*/","")
 -- build uci
 -- TODO: should the block size be user-configurable?
 os.execute("cd `dirname "..createdir:value().."` && aterm -e sudo su -c \"mkisofs -R -hide-rr-moved -cache-inodes -pad "..newuciname.."/ | create_compressed_fs - 65536 > "..pwd.."/"..newuciname..".uci\" && cd "..pwd.." && md5sum "..newuciname..".uci > "..newuciname..".uci.md5.txt")
 end
 end
 )
 fltk:Fl_End();
 
 build_uci_lists();
 
 w:show();
 Fl:run();
 
 | 
 
 --------------
 http://www.tldp.org/LDP/intro-linux/html/index.html
 |