wget gui


Forum: Programming and Scripting
Topic: wget gui
started by: jaapz

Posted by jaapz on Mar. 31 2008,15:53
I was planning to make a wget gui some time ago, and now as mikshaw mentioned it, i started one. For now its only a simple base, it can only download to the dir the lua script is in, but i will add some more features later, cos wget has a LOT of features.
Feel free to edit the code, but please post it here again when u r done :).

EDIT: updated script

Code Sample

#!/bin/lua
-- Written by Jaap Broekhuizen aka Jaapz
-- This script is released under the terms of the GPL2 License

-- aswg.lua
--- A Simple Wget Gui written in murgaLua

prefix = os.getenv("HOME").."/"

--Main
w = fltk:Fl_Window(300,110,"ASWG for DSL")
w:callback(
function(w)
 os.exit(0)
end)

text = fltk:Fl_Box(135,5,30,30,"Fill in the URL of the file you want to download.")

urlInput = fltk:Fl_Input(5,35,290,30)
urlInput:value("http://")

okBtn = fltk:Fl_Return_Button(5,75,50,25,"Ok")
okBtn:callback(
function(okBtn)
 url = urlInput:value()
 os.execute("aterm +tr -geometry 80x4 -e wget --directory-prefix=" ..prefix.. " " ..url)
end)

closeBtn = fltk:Fl_Button(60,75,50,25,"Close")
closeBtn:callback(
function(closeBtn)
 os.exit(0)
end)

optionsBtn = fltk:Fl_Button(115,75,60,25,"Options")
optionsBtn:callback(
function(optionsBtn)
 optionsw = fltk:Fl_Window(300,110,"Options")

 preftext = fltk:Fl_Box(135,5,30,30,"Target Directory:")
 prefixval = fltk:Fl_Input(5,35,290,30)
 prefixval:value(prefix)

 applyBtn = fltk:Fl_Button(100,75,100,25,"Apply")
 applyBtn:callback(
 function(applyBtn)
   prefix = prefixval:value()
   optionsw:hide()
 end)

 optionsw:show()
end)

helpBtn = fltk:Fl_Button(245,75,50,25,"Help")
helpBtn:callback(
function(helpBtn)
 fltk:fl_message([[A Simple Wget GUI, written in murgaLua.

The files will be automatically downloaded to your home directory,
unless otherwise specified.
Click on the "Options" button to edit the options.]])
end)

w:show()
Fl:run()

Posted by lucky13 on Mar. 31 2008,17:27
Quote
Feel free to edit the code

I did by stripping out over a quarter of the lines (11?) that tell me about you and your copyright instead of actually doing something with wget.:)

I'll see if I can find my tcl/tk scripts for wget. My last version allowed recursion of N levels, select file extension, etc. And mine's not even copyrighted because I figured it's just a front end to someone else's program...

Posted by roberts on Mar. 31 2008,18:09
Code Sample
 os.execute("aterm +tr -geometry 80x4 -e wget " ..url)


This is what I have used many times. Do a grep 80x4 /usr/bin/*.lua

We didn't have popen until much later when murgaLua added it.

A better goal would be not to do another os.execute of a wget hosted by aterm, but instead without the os.execute and without the hosting aterm.

Possibly io.popen - see examples of netcardconf.lua and printing.lua
then add a murgaLua progess meter.



Posted by mikshaw on Mar. 31 2008,18:15
in my opinion, a person that puts in the work required to make something useful or creative deserves to put his name on it.  I don't see a frontend as being part of the backend, but a compliment to it, so I think a copyright notice or a simple "written by so-and-so" is perfectly acceptable.

What I dislike is dishonesty and selfishness. A person deliberately writing code that no one but himself can understand, or  adding a license prohibiting users from modifying/improving the code, even for personal use.

Posted by mikshaw on Mar. 31 2008,18:18
Quote
Possibly io.popen - see examples of netcardconf.lua and printing.lua
then add a murgaLua progess meter.
This is exactly what kept me from starting this project. I don't know how to keep checking on the progress...guessing it requires coroutine, which I've never learned.

Posted by lucky13 on Mar. 31 2008,19:53
Quote
a person that puts in the work required to make something useful or creative deserves to put his name on it.

There's a difference between adding one's name and even copyright notice and doing it in both comments and with an "about" button that uses as many lines of code as the functional part of the front end. That's my only complaint.

Edit: Well, one of my only complaints. The other is declaring a copyright on something (especially like this) and then inviting others' input. Will the copyright then be expanded to accommodate everyone who contributes, and if so will it be collectively or proportionately and who's the judge for it? That's why I don't give a rat's ___ about licenses or whether people want to make them restrictive or not. I've never shied away from helping others, but I back off when I see people start slapping copyright notices on everything. Yeah, it's their right to do it. It's also mine to not appreciate it.

Posted by jaapz on Mar. 31 2008,21:09
lucky13: this app will get way bigger, as i said, this is  just the base! soon the copyright will just be veeeery small part of the script...

ill try to find some stuff about the io.popen and the progressbar, but as even mikshaw doesnt know how it works... xD

EDIT
oh, and lucky, check out some of the lua scripts in DSL, all with copyrights fro robertS

Posted by lucky13 on Mar. 31 2008,22:44
I know Robert has copyrights in many of the scripts. The difference is he did a lot of those on his own and he gives credit to those who helped. I don't recall him adding "about"/ego buttons to any of his GUIs.
Posted by joer on April 01 2008,02:43
Where's the beef? Putting out a template with mostly your copyright and asking for the community to contribute to code is very odd.

To compare your actions of copyright to roberts is even more odd. Robert brought Lua/Fltk scripting to DSL. Way before there was murgaLua. I don't how he did what he did. But many of us, including me, have the luxury to read and learn from his scripts. His style of writing them is easy to read and easy to learn.

Just try the murgaLua fluid examples and see that they look nothing like the style of Lua/Fltk that is Robert's style. Look at DSL-N all those Lua Fltk scripts that robert wrote was before murgaLua. If I recall he started with Lua 4.1 and Fltk way back around v0.7 something.

Dude, you need a dose of humility.

Posted by jaapz on April 01 2008,13:42
@lucky: who says im not going to give credit to the people who help me??

Well, if everybody thinks its not the right place, ill cut the copyrights out of it...
About button will be replaced by a help button...

Oh, and thx for all those reactions, it really's a good way to scare people away from helping the project by doing this...  (this is not about you mikshaw and roberts!)

Lets all now go back to the thing this topic was originally created for, the SCRIPT...

Posted by lucky13 on April 01 2008,16:26
Quote
Oh, and thx for all those reactions, it really's a good way to scare people away from helping the project by doing this.

How do you figure that? That others are vainglory and seek out legacies through minimally functional front ends with their names and copyrights -- repeatedly invoking your legal claims to something -- taking up a sizable part of the code? Or that they see someone with dual copyright sections in a simple front end with invitations for others to do all the work while someone else's name is all over it? Yeah, shame on me for wondering what's up with that.

Your initial egotism with more lines of code dedicated to putting your name (possibly) in others' computers than actual function of the script and your response defending it is why *I*'m not posting my tcl/tk scripts here, parts of which would be very helpful to what it sounds like you want to do. I've posted a few scripts here, in other forums and USENET, and on my blog for others who've wanted them (the DSL ones were mostly flua/lua 4). At most I added one line with "-- lucky13" or "# lucky13" so they know whom to blame. Maybe throw in that it's public domain, BSD license, "copy and use freely," but no copyright. That's it -- at most a couple lines regardless of how much time I spend on it or however many lines. Shell wrappers, little front ends, stuff that's a little more complex, whatever. None of which is really deserving of legal protections afforded by claiming copyrights. Besides, I have a hunch most wrappers and front ends would be thrown out of court if anyone ever tried to claim copyright infringement of one. So why bother making any legal claims like that?

I appreciate your desire to do stuff like this. But, as you can tell, I think it's ridiculous to post a script that only opens a terminal executing one small wget command to get one item at a time and then have it include all kinds of legalities (copyright) and ego-stroking with it. If your script were nearly as polished or complex as others' efforts -- Robert's many scripts, Zucca's scripts that he copyrights and posts here, mikshaw's excellent contributions, etc. -- I could accept that and even appreciate it. But like joer wrote, there's really *no* comparison.

Posted by jaapz on April 01 2008,21:07
... i dont like discussions like these, in the end everybody is angry at eachother. lets restart this topic ...

Ok, i've written a base for a wget gui, it's "released" under the gpl2 license. Please be so kind to help to make this app better.

For now, this is the code:
Code Sample

#!/bin/lua
-- Written by Jaap Broekhuizen aka Jaapz
-- This script is released under the terms of the GPL2 License

-- aswg.lua
--- A Simple Wget Gui written in murgaLua

prefix = os.getenv("HOME").."/"

--Main
w = fltk:Fl_Window(300,110,"ASWG for DSL")
w:callback(
function(w)
 os.exit(0)
end)

text = fltk:Fl_Box(135,5,30,30,"Fill in the URL of the file you want to download.")

urlInput = fltk:Fl_Input(5,35,290,30)
urlInput:value("http://")

okBtn = fltk:Fl_Return_Button(5,75,50,25,"Ok")
okBtn:callback(
function(okBtn)
 url = urlInput:value()
 os.execute("aterm +tr -geometry 80x4 -e wget --directory-prefix=" ..prefix.. " " ..url)
end)

closeBtn = fltk:Fl_Button(60,75,50,25,"Close")
closeBtn:callback(
function(closeBtn)
 os.exit(0)
end)

optionsBtn = fltk:Fl_Button(115,75,60,25,"Options")
optionsBtn:callback(
function(optionsBtn)
 optionsw = fltk:Fl_Window(300,110,"Options")

 preftext = fltk:Fl_Box(135,5,30,30,"Target Directory:")
 prefixval = fltk:Fl_Input(5,35,290,30)
 prefixval:value(prefix)

 applyBtn = fltk:Fl_Button(100,75,100,25,"Apply")
 applyBtn:callback(
 function(applyBtn)
   prefix = prefixval:value()
   optionsw:hide()
 end)

 optionsw:show()
end)

helpBtn = fltk:Fl_Button(245,75,50,25,"Help")
helpBtn:callback(
function(helpBtn)
 fltk:fl_message([[A Simple Wget GUI, written in murgaLua.

The files will be automatically downloaded to your home directory,
unless otherwise specified.
Click on the "Options" button to edit the options.]])
end)

w:show()
Fl:run()

Posted by u2musicmike on April 03 2008,02:13
jaapz,

Don't feel bad about copyright stuff unless you are a lawyer and want to sue someone.  :)   Really copyrights are okey one of the best scripts that I use alot has this banner:

#!/bin/sh
##################################################################
# $Id: ff, v-0.1 : GPL-v2 : 2002/11/24 17:25:45 bish Exp $
# © 2002 USM Bish <bish@nde.vsnl.net.in>
# Released under GNU GPL v2 - < http://www.gnu.org/copyleft/gpl.html >
##################################################################

I don't think I am violating a copyright by posting this because it is GPL.  There is a big difference between copyrights and patents.  The great man Arthur C. Clark said he didn't patent his ideals because of lawyers.

Posted by ^thehatsrule^ on April 03 2008,16:36
Note on your script: busybox has a minimalistic set of options, so yours should error out (untested)

I've taken a shot a this a while back when I decided a simple downloader was going to be my first (murga)lua script built from scratch, mainly because I didn't really like the xterm invocations used in the current mydsl utilities, and the blocking effects of it.

The gui elements and the simplicity of working in this was really nice to use... I was surprised how fast it was to develop.
And then I ran into the problems of os.execute and io.popen (that was hinted at earlier in this thread).

os.execute blocks the calling lua script, then returns control to it only after the child process is terminated.
io.popen doesn't block and allows you to read stdout from the spawned process, but you have no control over it.

Obviously execute is out of the question, but popen has the 'flaw' of still having the spawned process running even when the lua script terminates.
I ended up hacking up a dirty workaround that stored the pid in a temp file and killing it when a "stop download" command was issued or when the lua script exited.  And then there was the problem of handling signals... (I'm guessing a wrapper script would be needed to handle those)

I searched for better methods online, but it seems that only extra/external modules could possibly contain functions to remedy this.  And I'm assuming I'd have to see if murgaLua adopts something that would help before trying to do something with it in DSL - unless adding binary module blobs would be okay to do.

I've just stopped short of ideas for this now.  I'm comtemplating throwing the above code away.  From my 'research,' seems that using lua sockets could be a much better idea (and are included in murgaLua).  Has anyone used them?

Posted by roberts on April 03 2008,17:16
Quote
From my 'research,' seems that using lua sockets could be a much better idea (and are included in murgaLua).  Has anyone used them?


To see an example of sockets see my gettime.lua script.

/usr/local/bin/gettime.lua

Posted by jaapz on April 04 2008,07:27
What can u excaclty do with those sockets?
Posted by roberts on April 04 2008,16:08
You can go low level and implement an RFC as the example that I posted.

Or you can use higher level known protocols like FTP

Here is a trivial example: (Warning this script will try to download the mydsl extension Xeyes into the current directory)

Code Sample

#!/bin/murgaLua
local ftp = require("socket.ftp")
file,error = ftp.get("ftp://ibiblio.org/pub/Linux/distributions/damnsmall/mydsl/apps/xeyes.info")
if error == nil then io.output("xeyes.info"); io.write(file); end
file,error = ftp.get("ftp://ibiblio.org/pub/Linux/distributions/damnsmall/mydsl/apps/xeyes.tar.gz.md5.txt")
if error == nil then io.output("xeyes.tar.gz.md5.txt"); io.write(file); end
file,error = ftp.get("ftp://ibiblio.org/pub/Linux/distributions/damnsmall/mydsl/apps/xeyes.tar.gz;type=i")
if error == nil then io.output("xeyes.tar.gz"); io.write(file); end

Posted by jaapz on April 04 2008,20:44
is it possible to use those sockets and get a progress bar in the gui?
anyways, it looks cool, certainly gonna look at that some more

Posted by roberts on April 04 2008,20:59
It would seem to me that in order to have a progress bar would be to fetch the file in chunks then it would be easy to write a co-routine and having such would not be difficult to display a progress bar.

Using the standard protocol ftp does not allow chunks. So, I would think the more difficult part would be to use the lower level socket interface and use the RFC specs for FTP. Much more work but doable. ATM I am very busy with working on new DSL tiny core or I would attempt it. Maybe later if still not done.

Posted by jaapz on April 04 2008,21:59
Ok, but when using sockets, are we still using wget? Cos this app is actually a wget GUI xD.
Posted by MaxiJavi on April 13 2008,18:21
In 3rd-party/luasocket/etc on the murgaLua dist there seems to be a wget clone already written in Lua ...
Posted by mikshaw on April 13 2008,19:00
That looks like a useful piece of reference material. Unfortunately it's far from a wget clone.
Particularly, for anything larger than a few MB, wget's continue option is a necessity for me.

Powered by Ikonboard 3.1.2a
Ikonboard © 2001 Jarvis Entertainment Group, Inc.