Author Topic: Converting our in House Scripts to PerlGTK  (Read 12983 times)

Offline Neal ManBear

  • Administrator
  • Super Villain
  • *****
  • Posts: 15847
  • LXDE! Coffee, Bacon and Cheesecake!
Re: Converting our in House Scripts to PerlGTK
« Reply #45 on: August 11, 2010, 05:23:08 PM »
Thanks, Mark. I'll be testing this ASAP. Can't just now. Big storm coming up, so I need to shut down.

Offline Neal ManBear

  • Administrator
  • Super Villain
  • *****
  • Posts: 15847
  • LXDE! Coffee, Bacon and Cheesecake!
Re: Converting our in House Scripts to PerlGTK
« Reply #46 on: August 13, 2010, 01:30:49 PM »
I think that is a great idea. :D I can't think of how to accomplish it, though. :(

Offline Mark342

  • Sr. Member
  • ****
  • Posts: 334
Re: Converting our in House Scripts to PerlGTK
« Reply #47 on: August 13, 2010, 08:37:50 PM »
Couldn't we make an installer that uses 'patch' to modify the required files?

Here's how it plays out in my mind:

During Testing/Development:
To make a diff:
We keep a copy of an unmodified version of Control_Center.pm and drakconf.real somewhere.
When we need to modify either of the two files, we make another copy of the unmodified version.
Then we make our changes in one of the two identical files.
We then use 'diff' to generate a diff file that can be applied with patch.
For sanity's sake, It is important that each diff only provides changes for a specific app.

The installer:
The archive for the program would contain the one or two diff files that add the changes for that program.
The installer would then apply the diff files using 'patch' and do other necessary stuff.

Final Release (RPM):
All of the current patches are applied to the source code of the SRPMs containing drakconf.real and Control_Center.pm and the RPMs are rebuilt.
The actual perl scripts for the programs are packaged into their own RPMs.
Because if the perl script isn't installed, the PCC will ignore it and will not display an icon for it.
The PCC currently does this for some other non-existing apps.

Anyway, that's my idea. ;)
Tell me if there is anything wrong with it. (Note that the "make a diff" process should only have to be done once per app.)
« Last Edit: August 13, 2010, 09:06:01 PM by Mark342 »
Anything worth doing is worth overdoing.

Registered Linux user #493318
Register yourself here: Linux Counter

Offline Mark342

  • Sr. Member
  • ****
  • Posts: 334
Re: Converting our in House Scripts to PerlGTK
« Reply #48 on: August 13, 2010, 08:57:29 PM »
hello

Since we're writing a front end to switch-themes,  I made some modifications to switch-themes.sh so we can use it.  It now does the switch in about 15-25 seconds instead of  2 minutes.  All files containing references to theme get updated correctly.  It was also creating a broken link in /usr/share/gfxboot/themes.  There are no plymouth themes there, only bootsplash.
cheers

I assume you also modified the get_current_theme function?
Because switch-themes now modifies a different file so it needs to be changed.

Maybe this:
Code: [Select]
sysconfig=/etc/plymouth/plymouthd.conf
function get_current_theme () {
    $theme = `grep '^Theme=' $sysconfig | sed 's/Theme=//'`
    echo $theme
}

Or perhaps this:
(just the original code with THEME changed to Theme)
Code: [Select]
sysconfig=/etc/plymouth/plymouthd.conf
local opt= theme=
    while read opt ;do
[[ $opt != Theme=* ]] && continue
theme=${opt##*=}
    done < $sysconfig
    echo $theme

Take your pick.  :D :D
Anything worth doing is worth overdoing.

Registered Linux user #493318
Register yourself here: Linux Counter

Offline Neal ManBear

  • Administrator
  • Super Villain
  • *****
  • Posts: 15847
  • LXDE! Coffee, Bacon and Cheesecake!
Re: Converting our in House Scripts to PerlGTK
« Reply #49 on: August 15, 2010, 04:09:36 AM »
Quote
## Then replace switch-themes $SELECTED_THEME
## with  plymouth-set-default-theme -R $SELECTED_THEME
## in this line
117.
#!/bin/bash
(echo && switch-themes $SELECTED_THEME) | $DIALOG --progress --pulsate --auto-close

This is on line 119.

I made the changes and will test.

Offline Neal ManBear

  • Administrator
  • Super Villain
  • *****
  • Posts: 15847
  • LXDE! Coffee, Bacon and Cheesecake!
Re: Converting our in House Scripts to PerlGTK
« Reply #50 on: August 15, 2010, 04:14:39 AM »
Those changes disable theme switching. The "Plymouth theme unchanged." message pops up.


Offline Neal ManBear

  • Administrator
  • Super Villain
  • *****
  • Posts: 15847
  • LXDE! Coffee, Bacon and Cheesecake!
Re: Converting our in House Scripts to PerlGTK
« Reply #51 on: August 15, 2010, 12:50:47 PM »
Lines 118 and 119:
Quote
#!/bin/bash
(echo && /usr/sbin/plymouth-set-default-theme -R) | $DIALOG --progress --pulsate --auto-close --width=300 --title "$TITLE" --text=$"Updating plymouth theme, please wait.. \n(This may take a while)" --window-icon=$ICON

Still the same result. Theme unchanged and no terminal output.


Offline Neal ManBear

  • Administrator
  • Super Villain
  • *****
  • Posts: 15847
  • LXDE! Coffee, Bacon and Cheesecake!
Re: Converting our in House Scripts to PerlGTK
« Reply #52 on: August 15, 2010, 05:10:47 PM »
 ::) I hadn't seen that. ::)
On to the next prob -- the OK button is greyed out. The switching themes pane hangs on for about 20 or so seconds and closes. Then the theme unchanged pane appears.

Offline Neal ManBear

  • Administrator
  • Super Villain
  • *****
  • Posts: 15847
  • LXDE! Coffee, Bacon and Cheesecake!
Re: Converting our in House Scripts to PerlGTK
« Reply #53 on: August 15, 2010, 05:12:50 PM »
Here is ezswitch, from line 25 as I have it now:
Code: [Select]
# verbose output for debugging
#set -xv;

# define some variables
#=================================================
TITLE="EZSwitch 0.1.1"
TMP_DIR=$HOME/tmp/ezswitch_gui
#MSG1=$"Updating plymouth theme, please wait.. \n(This may take a while)"
#MSG2=$"Themes were updated successfully."
#MSG3=$"Plymouth theme unchanged."

# test for temp folder
#=================================================
if [ ! -d $TMP_DIR ]; then mkdir -p $TMP_DIR; fi


# Check if kdialog exists, if not, use gdialog.
#=================================================
if [ -f /usr/bin/kdialog ]; then
    DIALOG=kdialog
else
    DIALOG=gdialog
fi


# test for zenity
#=================================================
if which zenity >/dev/null; then
  DIALOG=`which zenity`
else
  $DIALOG --yesno $"Zenity is required to run this script.\n\nWould you like to install it now?"
  if [ "$?" == "0" ]; then
    synaptic &
    exit 1
  elif [ "$?" == "1" ]; then
    $DIALOG --sorry $"Exiting now"
    exit 1
  fi
fi


# Check if gksu exists, if not, use kdesu.
#=================================================
GUI_SU=`which gksu 2>/dev/null` || GUI_SU=`which kdesu 2>/dev/null`

# i18n - Internationalization - Internationalisierung
#=================================================
export TEXTDOMAIN=ezswitch
export TEXTDOMAINDIR="/usr/share/locale"

# icon
#=================================================
ICON="/usr/share/icons/ezswitch.png"


# welcome screen
#=================================================
echo -e "\nPrevious theme - `grep -i "^Theme=" /etc/plymouth/plymouthd.conf | cut -d= -f2`"
MSG=$"This program will change your plymouth bootsplash theme to the theme of your choice\!\n\nDo you wish to continue with the theme switch\?"
$DIALOG --question --width 400 --title="$TITLE" --text="$MSG" --window-icon=$ICON

if [ $? = 1 ];
then exit 1
fi

# create plymouth-theme list for zenity dialog
#=================================================
#ZEN_LIST=`ls /usr/share/plymouth/themes/ | cut -d"/" -f1 | awk '{print "FALSE " $1}'`
#SELECTED_THEME=$( $DIALOG --title $"Select a Plymouth Theme" --text $"Please select a plymouth theme or press Cancel to quit.\nNOTE: you must reboot to apply the new plymouth theme\!" --list --height 300 --radiolist --column $"Select" --column $"Plymouth Theme" $ZEN_LIST )

for plym_theme in `ls /usr/share/plymouth/themes/ | cut -d"/" -f1 | awk '{print $1}'`; do
  theme_description=`grep -i "^description=" /usr/share/plymouth/themes/$plym_theme/*.plymouth |cut -d= -f2`
  ZEN_LIST+="FALSE \n$plym_theme \n$theme_description \n"
done

#echo -e $ZEN_LIST
SELECTED_THEME=$( echo -e $ZEN_LIST | $DIALOG --title $"Select a Plymouth Theme" --text $"Please select a plymouth theme or press Cancel to quit.\nNOTE: you must reboot to apply the new plymouth theme\!" --list --height 300 --width 600 --radiolist --column $"Select" --column $"Plymouth Theme" --column $"Theme Description" --window-icon=$ICON )

# check if a new theme was selected and if so, apply it
#=================================================
if [ "$?" != "0" ]; then  # just quit
  $DIALOG --title "$TITLE" --info --text=$"Plymouth theme unchanged." --window-icon=$ICON
  exit 0
fi

echo -e "Selected theme - $SELECTED_THEME \n\n"

if [ $SELECTED_THEME == `grep -i "^Theme=" /etc/plymouth/plymouthd.conf | cut -d= -f2` ]; then  # check if already set as theme
  $DIALOG --title "$TITLE" --info --text=$"Plymouth theme unchanged." --window-icon=$ICON
  exit 0
else  # apply the new plymouth theme

cat > $TMP_DIR/gui-theme-switcher <<__EOF__
#!/bin/bash
(echo && /usr/sbin/plymouth-set-default-theme -R $SELECTED_THEME) | $DIALOG --progress --pulsate --auto-close --width=300 --title "$TITLE" --text=$"Updating plymouth theme, please wait.. \n(This may take a while)" --window-icon=$ICON

# check if sucessfully set as theme
#=================================================
if [ $SELECTED_THEME == `grep -i "^THEME=" /etc/sysconfig/bootsplash | cut -d= -f2` ]; then 
  $DIALOG --info --width=300 --title "$TITLE" --text=$"Themes were updated successfully." --window-icon=$ICON
else
  $DIALOG --info --width=300 --title "$TITLE" --text=$"Plymouth theme unchanged." --window-icon=$ICON
fi

__EOF__

 chmod u+x $TMP_DIR/gui-theme-switcher
 cd $TMP_DIR
 $GUI_SU ./gui-theme-switcher > /dev/null 2>&1

fi


rm -fR $TMP_DIR

exit 0

Offline Mark342

  • Sr. Member
  • ****
  • Posts: 334
Re: Converting our in House Scripts to PerlGTK
« Reply #54 on: August 15, 2010, 11:08:48 PM »
Neal, your problem is with this line:
if [ $SELECTED_THEME == `grep -i "^THEME=" /etc/sysconfig/bootsplash | cut -d= -f2` ]; then 

plymouth-set-default-theme doesn't change this file.
Instead it changes this file: /etc/plymouth/plymouthd.conf
Here is the same line, but modified for plymouth-set-default-theme:
if [ $SELECTED_THEME == `grep -i "^Theme=" /etc/plymouth/plymouthd.conf | cut -d= -f2` ]; then

=================================================================

In other news:
I figured out how to make our perl scripts translatable.
Here is the relevant code snippet:

Code: [Select]
use Locale::gettext;
use POSIX;     # Needed for setlocale()
setlocale(LC_MESSAGES,"");
my $d = Locale::gettext->domain("gezSwitch4");

#just add $d->get() to string to be translated
my $title = $d->get('Plymouth Theme Switcher');
« Last Edit: August 15, 2010, 11:20:42 PM by Mark342 »
Anything worth doing is worth overdoing.

Registered Linux user #493318
Register yourself here: Linux Counter

Offline Neal ManBear

  • Administrator
  • Super Villain
  • *****
  • Posts: 15847
  • LXDE! Coffee, Bacon and Cheesecake!
Re: Converting our in House Scripts to PerlGTK
« Reply #55 on: August 16, 2010, 05:01:04 AM »
Same results after making that change --
Quote
the OK button is greyed out. The switching themes pane hangs on for about 20 or so seconds and closes. Then the theme unchanged pane appears.

Questions: Why /etc/sysconfig/bootsplash or /etc/plymouth/plymouthd.conf? Why not /etc/sysconfig/bootsplash and /etc/plymouth/plymouthd.conf?

Offline Neal ManBear

  • Administrator
  • Super Villain
  • *****
  • Posts: 15847
  • LXDE! Coffee, Bacon and Cheesecake!
Re: Converting our in House Scripts to PerlGTK
« Reply #56 on: August 16, 2010, 05:41:20 AM »
My questions were about changes in the ezswitch script, not about old-bootsplash v plymouth. The "Plymouth theme unchanged" dialog should not be popping up at the end of a switch. It should only appear if the switch was aborted. I was asking if by combining the 2 the error would be gone. Sorry I wasn't clear and hope I'm clear now. :)

Offline Neal ManBear

  • Administrator
  • Super Villain
  • *****
  • Posts: 15847
  • LXDE! Coffee, Bacon and Cheesecake!
Re: Converting our in House Scripts to PerlGTK
« Reply #57 on: August 16, 2010, 06:04:44 AM »
With your script, the OK button is greyed out (not a real problem) and the successful change message is displayed. Hmm...... I could see no differences in the 2 files. I suppose I should look them over and compare them again; I missed something.

Offline Neal ManBear

  • Administrator
  • Super Villain
  • *****
  • Posts: 15847
  • LXDE! Coffee, Bacon and Cheesecake!
Re: Converting our in House Scripts to PerlGTK
« Reply #58 on: August 16, 2010, 08:09:10 AM »
The greyed out OK button is not a big problem. The Cancel button is the important part of that dialog. :)

Code: [Select]
plymouth-set-default-theme -lworks fine for me. But then I reinstalled plymouth back in early July.

Offline Neal ManBear

  • Administrator
  • Super Villain
  • *****
  • Posts: 15847
  • LXDE! Coffee, Bacon and Cheesecake!
Re: Converting our in House Scripts to PerlGTK
« Reply #59 on: August 17, 2010, 07:41:44 AM »
When I remove plymouth themes with synaptic it removes the contents of theme folders but leaves the empty folders.  So the list of themes is bogus after that.

When you add a new theme from synaptic it automatically switches and becomes the current theme.

Perhaps we could come up with a way to test the folders to see if they have content or are empty?

Suppose you add a new theme. You like it and use it for a few days or a week. But then you want to change to your previous theme, but you do not want remove the new theme. So, you switch to the old theme for a while and then back to the new theme.
I have quite a few themes. Some are my own creation. Some are available in the repos and some not as I'm not satisfied that they are ready. As I'm sure I'm not unique, the thought is that there are others with a number of themes to switch between. Hence, this project.