• Welcome to Overclockers Forums! Join us to reply in threads, receive reduced ads, and to customize your site experience!

F@H stats in your sig: not just for Linux anymore!

Overclockers is supported by our readers. When you click a link to make a purchase, we may earn a commission. Learn More.
Why not just test whether the file exists. You can test other properties with other tests, some of which are here.

Code:
#!/usr/bin/perl -w
                                                                                                                                                
#user frankfurter doesn't exist, so "/home/frankfurter" doesn't exist either                                                                                                                                                
$file="/home/frankfurter/.mksig/mksig.conf";

if ( -f $file ) {
  print "found file\n";
} else {
  print "file doesn't seem to exist\n";
}

Alternately, you can do any number of things based on the return value of open():
Code:
#!/usr/bin/perl -w
                                                                                                                                                
$file="/home/frankfurter/.mksig/mksig.conf";
if ( open FILE, $file ) {
  print "found file\n";
  close FILE
} else {
  print "file couldn't be opened\n";
  print "the error was: $!\n";
}

The Camel book (aka "Programming Perl") only refers to try blocks once while mentioning that Java has them, so it's safe to say that they don't exist in Perl 5.
 
Last edited:
Thanks!. I was trying to find the try,catch,finally routine, and found a couple sites for it, but didn't know why it wasn't working. I thought it was me.
 
GUI v0.07
gui_v0.07.pl - Download
sig_gen.pl - Download

Internal changes, a new first start wizard, and a new validate button that checks if name and eocid combination exists at EOC.

At this stage of the game, I'm asking for anyone to help test and critique the GUI and sig_gen (beta testing). I won't post the code here because it's way too long, but if you want to take a look at the code, you're welcome to download it and check it out with notepad or perl compiler. There's a lot of crap that can be optimized, unfortunately I code in a manner that's more readable and basic, not necessarily faster ('Jer' eq 'non-programmer' :D).


gui_v0.07.gif



Decided to have this sig_gen.pl version come blank without any names, EOC ID or paths. If gui.pl finds this, then it allows for user input of their folding name and eoc id. User name is case sensitive, so if it doesn't match, it will ask the user again. It will allow 3 mistakes before saying "try again". This will be part of the GUI soon.

start_wizard.gif


New "validate" button near the Name and EOC ID# allows to check EOC database if that name and id# combination is valid. If combination is correct, then it pops up the window:

nameidvalidated.gif



Worklog, v0.07:

  • see above

To Do List

  • Link the color entry fields to its color button. If user types a color manually, and then clicks off somewhere else, hits tab, or return, then it'll check to see if color is valid and then change the button color... otherwise will pop up dialog saying invalid color.
  • Bug checking
  • Knick knacks like help elements
 
JerMe, I'd be glad to help you out with the code, but it's a pain to change all the hard-coded windows-style paths. I suggest you do something like what I did, using $^O to detect whether you're on windows or not, and changing the paths accordingly.
The idea is to have a single variable that contains most of the path, then detect whether you're under windows and fix it accordingly. Afterwards, append all the extra stuff and all the paths are both correct and easy to change.
Here's how I *should* do it in mksig.

Code:
#default to Linux
$dir = glob "~/.mksig/";
                                                                                                                                                
#if we're in windows, change base path
if ($^O =~ /win/i) {
  $dir = "C:\\mksig\\";
}

#now the following vars will be correct for either path style
$sig_gen  = $dir . "sig_gen";
$config   = $dir . "mksig.conf";
$sig_log  = $dir . "sig.log";
$sig_file = $dir . "sig";

edit: bug in my English
edit2: bug in my code too
edit3: I really should be doing other things, but the formatting was ugly and needed fixing.
 
Last edited:
Thanks Christoph :D I'll go through and make the changes. If I have it default to Windows, what would $^O match for Linux? I could use !~, but I'm curious :)

I went to the bookstore today...they didn't have a Perl/Tk book. I found a few pages describing Tk in the O'Reily advanced perl programming book, but only elements that are already included in the GUI. Bleh.

I picked up the "Learning Perl" book, very nice. Now I can refer to a page rather than a huge list of bookmarked webpages. :p

Edit: match for Linux heh..
 
Under Linux, $^O is "linux" (it's "MSWin32" under windows, if you haven't tested it yet). I think it's better to use the *nix style as a default, though, since there's only 1 major OS that uses windows' path conventions, while any unix will use what Linux uses. It's a minor issue, but it will make life a little easier if someone wants to use this on OSX or Solaris or something else that won't match "linux".
 
I've always been a fan of readability, but that would work. ;) You might want to use the other slash in the windows paths, though.
 
"\" instead of "/"? It turns out that Windows doesn't mind C:/Program Files, If I type C:/ in Windows Explorer, it'll just change it back to C:\. Compatibility?

GUIv0.08

Included the Linux/Windows checking...
some other little validation buttons for error checking sig_gen and mksig. It runs sig_gen and mksig and looks for errors, then reports back. The dialog boxes were tracers, but get annoying after a while. I'll figure out what to do with them later.

Edit:
GUIv0.09
Hashed out the variable names. Now the drop down box to select variable is an actual name like "Points Per Day" rather than $ppd. Also, got rid of the "Validate Fields" button, but access to the function still lives in the File menubar.
 
Last edited:
Sorry for the long reply forgot i posed in here until just now. :eek:

I just tried the latest version of mksig.pl and... heres what happened:
http://kayak.gotdns.org/error3.gif
error3.gif


Additionally, the windows "firewall" is turned off, and i have no "anti-virus" programs running. I'm running Active Stat PERL v5.8, are there any non-standard/default packages i need to load?

Running Windows XP SP2, does the default mksig file need to be modified for windows?
 
K have you made any changes to the code? What's your BOINC ID#? Where are your SETI instances installed on your computer (i.e., what is the full directory path?) Do you use Windows or Linux?


If you haven't changed it already, you're going to have to open your sig_gen.pl with a text editor, and edit a few lines...

Code:
$boinc_id = [i]yourBoincID[/id];

your BOINC directory should be this next line, in "quotes"... it's probably not in C:\Program Files\Seti, I don't know because I don't crunch :) Just change it to whatever yours is. The one that Christoph posted is specific to his machine.

Code:
$seti_home = "C:/Program Files/Seti";

Just use "/", it works for my WinXP Pro. Alternatively, you can type "C:\\Progam Files\\Seti", using the double backslashes ("\\").

I'm not sure if you've already made changes to the code pertaining to ID and directories...
 
BOINC (berkelys program to run seti / einstein etc) is in C:/program files/BOINC
My BOINC ID is: 42a395244f41a6f58f73178825e0c2db
My SETI ID is: 7827933

Now, looking at the default sig_gen.pl file, isnt all its supposed to do is goto http://www.update.uu.se/user-cgi/bjorn/cookie.cgi?1+5 and download a random quote?
Code:
#!/usr/bin/perl

#This is the default sig_gen.
#Delete the line above if you don't want this file to be automatically
#updated.

use LWP::UserAgent;
#Get fortune from a website because windows isn't cool enough
#to have it installed natively.
$ua= LWP::UserAgent->new();
$newlines=100;
$max_newlines=5;
$fortune="";

until ($max_newlines > $newlines) {
  #print "getting page...";
  $res=$ua->get("http://www.update.uu.se/user-cgi/bjorn/cookie.cgi?1+5");
  #print "got page\n";
  die "Unable to download cookie page" unless $res->is_success;
  $f_state=0;
  $fortune="";
  $newlines=0;
  for $line (split /^/, $res->content) {
    if ($line =~ m#<HR># && $f_state == 0) {
      $f_state=1;
    } elsif ($f_state==1) {
      if ($line =~ m#</pre>#) {
        $f_state=0;
      } else {
        $line =~ s/<[^>]*>//g;
        $newlines++;
        $fortune .= $line;
      }
    }
  }
  #Hopefully my filtering out these words won't set off any filters.
  if ($fortune =~ /c[u]nt|fu[c]k/i) {
    #print "filter 1\n";
    $newlines = 100;
  } elsif ($fortune =~ /s[h]it|[s]ex/i) {
    #print "filter 2\n";
    $newlines = 100;
  } elsif ($fortune =~ /b[i]tch|[c]ock/i) {
    #print "filter 3\n";
    $newlines = 100;
  } elsif ($fortune =~ /di[c]k|lesb{o|ian}/i) {
    #print "filter 4\n";
    $newlines = 100;
  }
  #print "fortune: $fortune\n";
}
@time = localtime;
$time[5] += 1900;
$time[4]++;
$time_str = sprintf("%02d/%02d/%04d at %02d:%02d.",$time[4],$time[3],$time[5],$time[2],$time[1]);
print "Christoph's automatic sig generator v.8\n";
print "your fortune:[font=monospace][b]\n";
print "$fortune";
print "\n";
print "[/font][/b]This sig was generated on ";
print "$time_str";
 
I distrust MS too much to think that it's compatibility. It's probably so

It looks like Tk wasn't installed by default, but CPAN is happy to help me out. Among the other text it spit out while compiling was this gem:
All tests successful (3 subtests UNEXPECTEDLY SUCCEEDED), 1 test and 23 subtests skipped.
I wish my tests unexpectedly succeeded.

The gui works great and looks reasonably native under Linux. However, it seems to want ~/.mksig/varlist.txt. You might include that with the rest of the script when you get a chance.
Overall, I'm impressed. I love hacking around and don't think anything could rip me away from my trustry text editor, but this is a big step for people who're used to guis.

Once you feel like it's stable, pick a post and I'll add a link to it and some explanation to the first post.


zulfy: It looks like you haven't told your firewall to allow Perl.exe to connect to the outside world. I really need to add that to the first post.
edit: I just did. ;) Hopefully fewer people will run into this now.
edit2: I'm not entirely sure why you'd want another sig. That's one of the better ones I've seen. ;)
 
Last edited:
Hehe thanks chris, Main reason i'm pursuing this is because of interest. I love code, and i like mucking around in it messing with stuff and seeing what happens.
 
Major Update - GUI Done, Installer Created

Major Update

The GUI is completed at v0.10. Any updates will be bugfixes and minor updates. Any of the features I mentioned in the previous worklogs are going to be left out.

Windows Installer
I've made a Windows installer that puts all the necessary files in c:\mksig. That installer is here:

www.geocities.com/backwardsmiley/SigGenerator-0.1.0.zip

It installs everything you need, and creates desktop shortcuts if you'd like. Once you're done, run gui.pl and follow the onscreen instructions.

I've started another thread just as an FAQ so it wouldn't blow up this sticky. That's just meant for my personal use because it's easier to maintain than one HUGE post. Plus broken links suck.


Worklog, v0.10:

  • Upon first run, gui.pl will ask for Folding Name and EOCID, then if correct (it checks EOC if the combination exists), will look for mksig's mksig.conf file. If it doesn't find it, it'll run mksig (allow the user to add their OC Forums information and mksig preferences).
  • Made windows installer that places mksig, sig_gen, gui, and varlist.txt into c:\mksig. Zipped up file and included TEAM32.nfo in zip file :p

To Do List

  • Return the "Learning Perl" book and borrow "Programming Perl" from the library :)

I wanna thank Christoph again for all his work and help. Without the mksig and sig_gen, I wouldn't have been inspired to code. Thanks man, I think I just might continue on with this coding stuff. ;) I'll have to find some uses at work though, because it's mainly Windows machines there. I'll try to pick up VB(A|script) or .Net so that I start manipulating everything there.

"All tests successful (3 subtests UNEXPECTEDLY SUCCEEDED), 1 test and 23 subtests skipped." lol you got me on that one boss. As for Tk, it came with ActivePerl, so I used it. I thought it came with your distro, since the sources I read suggested that Tk has been around for a while.

I'll send you a little explanation of the GUI for your first post, thanks again! :p
 
Last edited:
can't run this OR the installer... all because my windows install defaulted my harddrive to F: instead of C:..... CRAP. i'm NOT going and re-install for hours just to fix the drive letter....
 
JerMe: I was thinking that you could just stick everything you wanted to say into a post of your own, and I'd summarize it and link to it from the first post. I don't have a problem sticking more stuff in the first post, but it'll be much easier for you (and me) to maintain your part if you can edit it directly instead of having to go through me.
Either way will work, though.

As for the strange message about unexpected success, I just thought it might be entertaining. It compiled without a hitch and I haven't run into any problems with it. (BTW, I run Gentoo, so almost everything is compiled, although the compilation process is highly automated. CPAN also compiles stuff, and it's also all automated.)
 
Good deal, can you link to this thread? If I posted all the FAQ posts here, it would have made a huge mess, and possibly drowned out some legitimate questions from others. =T

Regarding TollhouseFrank's question, is there an easy, silent way to detect for perl the Windows root drive? As of now, anyone not using C:\ would have to edit the mksig and gui scripts.

Edit: I think Win32::GetFolderPath() can be used for the above, and just substring the first three chars, then have the scripts use that as $dir...

Code:
#!perl
use Win32;

$root = substr(Win32::GetFolderPath(CSIDL_WINDOWS), 0,2);
$dir = $root."/mksig";

I'm still looking around to see if there's something better... what do you think?
 
Last edited:
I'm scratching $dir = $root."mksig" in favor of relative path references to the directory where all the scripts live. That way, if someone decides to dump the scripts into a different folder or drive, the scripts would still continue to function as long as they were installed into the same directory.

In order to make it all work, mksig would have to be updated as well... is this a better way to go, rather than hard-coding to "c:\mksig"? I'm testing it by hacking the Windows paths in mksig:

Code:
#Linux default file paths
$dir      = glob "~/.mksig";
$sig_gen  = "$dir/sig_gen";
$config   = "$dir/mksig.conf";
$sig_log  = "$dir/sig.log";
$sig_file = "$dir/sig";

#Windows default file paths
if ($^O =~ /win/i) {
  $sig_gen = "sig_gen.pl";
  $config  = "mksig.conf";
  $sig_log = "sig.log";
  $sig_file= "sig";
} else {
  $dir = glob $dir; #?
}

What do you think?


Add: Your autoupdate script is looking mighty yummy right now... can I mooch? It'd be cool to see how it'd work with Tk. :D
 
Last edited:
In mksig, I tried to make sure that I only referred to "C:\\mksig\\" once so that it'd be as easy as possible to change it if the need arose. For now, anyone who wants mksig to live somewhere other than C:\mksig\ can manually change the line $dir = "C:/mksig"; (line 26 in v.67).
It would be possible to get and look for the value in the registry using Win32::TieRegistry, but I couldn't actually debug something like that, not having access to a window box. If one of you don't mind writing a snippet of code that looks through the registry for a key (pick a name), using it if it's found and asking the user for it otherwise, I'd appreciate it. It'd also be useful to use in JerMe's gui code.
Once I've got some code that's known to work, I'll add it and release it as v.68. I'll probably add a little code that automatically makes the registry key if c:\\mksig\\ exists, just so people who are running it as a service won't need to input anything.


Jerme, knock yourself out as far as automatically updating your gui. I recommend making it configurable, though, since it could be quite obnoxious for a 56k user to have to wait 15-20 extra seconds for each update.
If it's not obvious how it works, just ask and I'll explain it.
The only problem I see is that it's not as simple to reload the gui as it is to fork an instance of the updated mksig script. Tk's man pages are here if you haven't found them already. ;) Hopefully there's something in there that will help you.
 
Last edited:
Back