Search Members Help

» Welcome Guest
[ Log In :: Register ]

Mini-ITX Boards Sale, Fanless BareBones Mini-ITX, Bootable 1G DSL USBs, 533MHz Fanless PC <-- SALE $200 each!
Get The Official Damn Small Linux Book. DSL Market , Great VPS hosting provided by Tektonic
Pages: (4) </ 1 2 3 [4] >/

[ Track this topic :: Email this topic :: Print this topic ]

reply to topic new topic new poll
Topic: murgaLua tests, scriptlets< Next Oldest | Next Newest >
mikshaw Offline





Group: Members
Posts: 4856
Joined: July 2004
Posted: Feb. 08 2007,19:12 QUOTE

xdesktopwaves frontend updated Feb 7. That will probably be the last bit of development on that particular project for a while.

I'm going back to the ucitool script soon, but I may need to rethink its behavior...maybe wrap it in a bash script with whiptail so it can be used in textmode if necessary...or just use a plain text list of files in Lua. Still also debating whether the "build package" feature is indeed useful.

In the meantime, there is much more that murgaLua can do on the Lua side of the coin, besides just providing a clickable interface. Robert has demonstrated this several times in his scripts written for DSL.  As far as I have been able to tell, the murgaLua program is a complete Lua 5.1 interpreter, which might be useable for Lua scripts that were not written specifically for murgaLua.  I haven't tested much so far, but there's another thing to look into.


--------------
http://www.tldp.org/LDP/intro-linux/html/index.html
Back to top
Profile PM WEB 
mikshaw Offline





Group: Members
Posts: 4856
Joined: July 2004
Posted: May 16 2007,07:03 QUOTE

With the recent addition of popen support in murgaLua, it was necessary to dive into that a little.  Here are a few simple examples of using shell command output within a gui.

Code Sample

ww=300
wh=180
cmd="ls"

w = fltk:Fl_Window(ww,wh,"Hello")

-- DISPLAY SINGLE-LINE COMMAND OUTPUT
butt=fltk:Fl_Button(10,10,100,20,"display output")
outpoot=fltk:Fl_Browser(10,30,ww-20,wh-40)
butt:callback(
function(butt)
local c=io.popen("date")
local o=c:read("*a")
c:close()
outpoot:add(o)
end
)

-- DISPLAY MULTILINE COMMAND OUTPUT (no file close)
butt=fltk:Fl_Button(10,10,100,20,"display output");
outpoot=fltk:Fl_Browser(10,30,ww-20,wh-40);
butt:callback(
function(butt)
for line in io.popen(cmd):lines() do
outpoot:add(line)
end
end
)

-- DISPLAY MULTILINE COMMAND OUTPUT
butt=fltk:Fl_Button(10,10,100,20,"display output")
outpoot=fltk:Fl_Browser(10,30,ww-20,wh-40)
butt:callback(
function(butt)
outpoot:clear()
local c=io.popen(cmd)
for line in c:lines() do outpoot:add(line) end
c:close()
end
)

w:show()
Fl:run()


Note the three variants are redundant and overlapping. They aren't all meant to be used in the same script.
I'm also not sure if the middle one is any better or worse than the last.


--------------
http://www.tldp.org/LDP/intro-linux/html/index.html
Back to top
Profile PM WEB 
MakodFilu Offline





Group: Members
Posts: 65
Joined: Jan. 2006
Posted: May 16 2007,20:24 QUOTE

Mmmmm, I didn't even know I would need that for substituting gtkfind :D

Thx, mikshaw

...if only I could dedicate less time to my Nokia and more time to DSL :D
Back to top
Profile PM WEB 
mikshaw Offline





Group: Members
Posts: 4856
Joined: July 2004
Posted: May 18 2007,19:13 QUOTE

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
Back to top
Profile PM WEB 
18 replies since Aug. 21 2006,05:55 < Next Oldest | Next Newest >

[ Track this topic :: Email this topic :: Print this topic ]

Pages: (4) </ 1 2 3 [4] >/
reply to topic new topic new poll
Quick Reply: murgaLua tests

Do you wish to enable your signature for this post?
Do you wish to enable emoticons for this post?
Track this topic
View All Emoticons
View iB Code