From: genone Date: Sun, 17 Oct 2004 17:50:47 +0000 (-0000) Subject: replace perl euse with bash euse X-Git-Tag: gentoolkit-0.2.4.3~346 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=97b39c1fc1dda6082199dbcc2e77dfd90c7d61a7;p=gentoolkit.git replace perl euse with bash euse svn path=/; revision=156 --- diff --git a/trunk/ChangeLog b/trunk/ChangeLog index 08a574e..29a65ff 100644 --- a/trunk/ChangeLog +++ b/trunk/ChangeLog @@ -5,6 +5,7 @@ * equery: changed defaults for `equery depends` as making a depgraph for the full portage tree isn't a good idea and find_all_packages() uses way to much memory currently + * euse: replaced the old perl version with a newly written bash version. 2004-10-12 Marius Mauch * equery: fix for bug #67210 diff --git a/trunk/src/euse/AUTHORS b/trunk/src/euse/AUTHORS index 8e777bc..12e6db7 100644 --- a/trunk/src/euse/AUTHORS +++ b/trunk/src/euse/AUTHORS @@ -1 +1,2 @@ -* Arun Bhanu +* original perl version: Arun Bhanu +* new bash version: Marius Mauch diff --git a/trunk/src/euse/README b/trunk/src/euse/README deleted file mode 100644 index 9d9e3de..0000000 --- a/trunk/src/euse/README +++ /dev/null @@ -1,116 +0,0 @@ -Euse is a command line USE flag editor for Gentoo Linux. - -What does it do? -================ -USE flags are central to Gentoo Linux. When you want to compile (in Gentoo -terminology emerge) a new package you can set a few USE flags to customize the -behavior of the build. At present you do this by editing the /etc/make.conf and -change the USE variable there. - -With euse you don't have to open the file to edit anymore. You can directly -add/delete/view USE flags from make.conf. When you want to enable a particular -USE flag you might want to find out what this flag does. At present, you can -grep on use.desc and use.local.desc to find the details of an USE flag. With -euse -i flag you can directly find out the details about an USE flag without -grepping many files. Read ahead to view the usage. - -Usage -===== -# euse -c -d -e -Prints out the current setting of USE variable in make.conf, make.defaults, -environment variable USE respectively. You can use them individually. E.g. -# euse -c - -# euse -i -Prints all the use flags with descriptions and their current status. -1st Column - Use flag -2nd Column - Shows if the USE flag is enabled or disabled. -3rd Column - If USE flag is enabled this columns show where it has been - enabled. C means make.conf, D means make.defaults, E means - enviroment variable USE. -4th Column - Shows if the use flag is a global or local use flags. - For local use flags the desc field(next column) begins with - showing which package it belongs to in square brackets. -5th Column - Use flag description. -Use Flag | Enabled/Disabled | Conf/Env/Defaults | Global/Local | Desc -alpha [-] [ ] [G] indicates that architecture is 64-bit Alpha -alsa [+] [C] [G] Adds support for media-libs/alsa-lib (Advanced - Linux Sound Architecture) -moznocompose [+] [C] [L] [net-www/mozilla] : If you do NOT want the web page - composer built with mozilla - -# euse -i mozilla -Prints details of just mozilla. -mozilla [-] [ ] [G] Adds mozilla support - -# euse -E mozilla alsa -Enables mozilla alsa in make.conf. Accepts one or more arguments to enable. - -Case 1: -If before executing this command the USE in make.conf looks like this: -USE="tiff doc" -After executing it becomes: -USE="tiff doc mozilla alsa" - -Case 2: -If before executing this command the USE in make.conf looks like this: -USE="tiff doc -mozilla -alsa" -After executing it becomes: -USE="tiff doc mozilla alsa" - -There are lot of other cases, but you get the idea. - -# euse -D mozilla alsa -Disables mozilla alsa in make.conf. Accepts one or more arguments to enable. - -Case 1: -If before executing this command the USE in make.conf looks like this: -USE="tiff doc" -After executing it becomes: -USE="tiff doc -mozilla -alsa" - -Case 2: -If before executing this command the USE in make.conf looks like this: -USE="tiff mozilla doc alsa" -After executing it becomes: -USE="tiff -mozilla doc -alsa" - -There are lot of other cases, but you get the idea. - -Special Case: -all is special flag. It is equivalent to * in USE setting. You can use "*" -instead. But is NOT recommended. There are high chances you'll just type * -instead of "*" and Euse will spit out some warnings. Note that * has be quoted -to prevent bash expanding the wildchar. You can use all with -E and -D. With -E -it will remove the last occurrence of -* from the make.conf. With -D it will -will include -* to the end of the USE setting in make.conf if a -* is already -present. If not it'll put a -* at the beginning of USE. If it is confusing, try -it to find out. -So this is how you use it: -# euse -E mozilla alsa all -Case 1: -If before executing this command the USE in make.conf looks like this: -USE="-* tiff -mozilla doc -alsa" -After executing it becomes: -USE="tiff mozilla doc alsa" - -# euse -D mozilla alsa all -If before executing this command the USE in make.conf looks like this: -USE="tiff mozilla doc alsa" -After executing it becomes: -USE="-* tiff -mozilla doc -alsa" - -Note: -1. -E and -D flags can be used together like: -# euse -D mozilla -E alsa -To enable alsa and disable mozilla in the same command. - - -Author's Note -============= -If you have any comments(both good and bad) about the code or any features in -this program feel free to mail me codebear@gentoo.org. - - -Enjoy!! - --Arun diff --git a/trunk/src/euse/TODO b/trunk/src/euse/TODO deleted file mode 100644 index e69de29..0000000 diff --git a/trunk/src/euse/euse b/trunk/src/euse/euse index c604605..f2972ad 100755 --- a/trunk/src/euse/euse +++ b/trunk/src/euse/euse @@ -1,1043 +1,389 @@ -#!/usr/bin/perl -# Name : euse -# Purpose : Command line USE flag editor -# Author : Arun Bhanu -# Version : 0.1.0 -# Copyright : GNU GPL v2 - -use warnings; -use strict; - -use Getopt::Long; -use File::Copy; -use Env qw(USE); - -# Define constants -use constant FLAG_TYPE=>['G', 'L']; -use constant FLAG_MASK=>['+', '-', 'M']; -use constant FLAG_SITE=>['E', 'C', 'A', 'D', ' ']; -use constant SITE_DESC=>['environment', 'make.conf', 'auto', 'make.defaults']; - -# parse_wo_args & parse_with_args populate command line arguments into -# these. The argument and variable names has to match because we make use -# of symbolic references. Yeah, I know these are not good names. -our $h = 0; # -h|help, boolean -our $v = 0; # -v|version, boolean -our $c = 0; # -c|conf, boolean -our $d = 0; # -d|defaults, boolean -our $e = 0; # -e|env, boolean -our @i = (); # -i|info, info accepts many optional values. -our @p = (); # -p|package argument, package accepts many values. -our @E = (); # -E|enable, enable use flags in make.conf -our @D = (); # -D|disable, disable use flags in make.conf. Not a physical - # delete, but just minus sign in front of the given use flag. - -# arguments that does not take values. -our $Args_Wo_Param = "hvcde"; -our $Non_Arg = " "; -our $Curr_Arg; # Argument being parsed. -our %Unknown_Args; # All unknown arguments are populate here. - -our %Uf_warnings; - -our $Version = "0.1.0"; - -# Paths to all the reqd files -our $FMake_conf = "/etc/make.conf"; -our $FMake_defaults = "/etc/make.profile/make.defaults"; -our $FUse_desc = "/etc/make.profile/../use.desc"; -our $FUse_local = "/etc/make.profile/../use.local.desc"; -our $FUse_mask = "/etc/make.profile/use.mask"; - -# For my local testing -#our $FMake_conf = "make.conf"; #/etc/make.conf -#our $FMake_defaults = "make.defaults"; #/etc/make.profile/make.defaults -#our $FUse_desc = "use.desc"; #$PORTDIR/profiles/use.desc -#our $FUse_local = "use.local.desc";#$PORTDIR/profiles/use.local.desc -#our $FUse_mask = "use.mask";#/etc/make.profile/use.mask - -if (-f "/etc/make.profile/parent") { - print "euse doesn't support cascading profiles yet\n"; - exit(0); -} - -#BEGIN Main -MAIN: { - Getopt::Long::Configure("no_ignore_case"); - # help, version does not accept arguments - # info accepts optional agruments. - # package requires arguments. - GetOptions( - "h|help" => \&parse_wo_args, # Show usage info. - - "v|version" => \&parse_wo_args, # Show version info. - - "i|info:s" => \&parse_with_args, # Show use flags info. - # Show all use flags if none - # specified. (Optional values) - - #"p|package:s" => \&parse_with_args, # Show use flag info for all - # given packages (Mandatory values) - - "E|enable:s" => \&parse_with_args, # enable use flag from make.conf - # e.g. mozilla - - "D|disable:s" => \&parse_with_args, # disable use flag from make.conf - # e.g. -mozilla. - - "c|conf" => \&parse_wo_args, # print the contents of make.conf - # use flag setting - - "d|defaults" => \&parse_wo_args, # print the contents of - # make.defaults use flag setting - - "e|env" => \&parse_wo_args, # print the contents of - # environment use flag setting - - "<>" => \&handle_unknown # all unknown arguments. - ) or usage(); - - - # If no options are entered show usage. - if ((my $opts = $h + - $v + - ($c or $d or $e) + - defined(@i) + - defined(@p) + - (defined(@E) or defined(@D))) < 1) { - usage(); - } - - # If any arguments are provided for options which are boolean show usage. - if (%Unknown_Args) { - print ("Unknown arguments: \n"); - foreach (sort keys %Unknown_Args) { - print "\t$_ => " . join (" ", @{$Unknown_Args{$_}}) . "\n"; - } - usage(); - } - - # Only one of -h, -v, -i, -p, -c/-d/-e or -E/-D allowed - if ((my $opts = $h + - $v + - ($c or $d or $e) + - defined(@i) + - defined(@p) + - (defined(@E) or defined(@D))) > 1) { - usage("Only one of -h, -v, -i, -p or -E/-D allowed"); - } - - # Mandatory argument field check if arguments have been entered - my @reqd_args = (); - if (defined(@E)) { - if ($E[0] eq '') { - push @reqd_args, "-E"; - } - } - if (defined(@D)) { - if ($D[0] eq '') { - push @reqd_args, "-D"; - } - } - if ($#reqd_args >= 0) { - print join(", ", @reqd_args), " require argument(s). \n"; - usage(); - } - - # If -h,--help is entered show usage. - if ($h) { - #check_permissions("rw"); #just for testing purposes - usage(); - } - - # If -v,--version is entered show version. - if ($v) { - version(); - } - - if ($c || $d || $e) { - #Check the permissions for all the reqd files and sets their path - #If not enough permission don't proceed. - check_permissions("r"); - if ($d) { - my $defaults_uf_list_ref = parse_make($FMake_defaults); - print "USE setting in make.defaults: \n"; - print (join (" ", @$defaults_uf_list_ref) . "\n\n"); - } - - if ($c) { - my $conf_uf_list_ref = parse_make($FMake_conf); - print "USE setting in make.conf: \n"; - print (join (" ", @$conf_uf_list_ref) . "\n\n"); - } - - if ($e) { - my $env_uf_list_ref = parse_env($USE); - print "USE setting in environment: \n"; - print (join (" ", @$env_uf_list_ref) . "\n\n"); - } - exit(0); - } - - check_permissions("r"); - - # Read /usr/portage/profiles/use.desc - my %use_flags; - parse_use($FUse_desc, \%use_flags); - - # Read /usr/portage/profiles/use.local.desc - parse_use_local($FUse_local, \%use_flags); - - # Read /etc/make.profile/use.mask, if exists. - parse_use_mask($FUse_mask, \%use_flags) if (-e $FUse_mask); - - # If a -* is found in env, make.conf & make.defaults is skipped. - # If a -* is found in make.conf, make.defaults is skipped. - # If a -* is found in all the elements in front of -* is skipped. - # In each of the case all the elements in front of -* is also skipped. - # Read ENV{USE} - my (@env_uf_list, @conf_uf_list, @defaults_uf_list) = (); - my $env_uf_list_ref = \@env_uf_list; - my $conf_uf_list_ref = \@conf_uf_list; - my $defaults_uf_list_ref = \@defaults_uf_list; - - $env_uf_list_ref = parse_env($USE) if (defined($USE)); - unless (is_all_disabled($env_uf_list_ref)) { - # Read /etc/make.conf - $conf_uf_list_ref = parse_make($FMake_conf); - - unless (is_all_disabled($conf_uf_list_ref)) { - # Read /etc/make.profile/make.defaults - $defaults_uf_list_ref = parse_make($FMake_defaults); - } - } - - # is this the correct way of check the length of an array reference?? - parse_use_flag($defaults_uf_list_ref, \%use_flags, 3) - unless ($#{@$defaults_uf_list_ref} < 0); - parse_use_flag($conf_uf_list_ref, \%use_flags, 1) - unless ($#{@$conf_uf_list_ref} < 0); - parse_use_flag($env_uf_list_ref, \%use_flags, 0) - unless ($#{@$env_uf_list_ref} < 0); - - - # If -i, --info is entered print all USE flags if no arguments given or - # print the description for the given USE flags. - if (defined(@i)) { - - #if -i mozilla mozilla is entered the extra mozilla is removed. - remove_duplicates(\@i); - - my @use_flag_list = (); - my $max_len = 0; - my $curr_key_len = 0; - - # Retrieve the objects to be send to the formatting function as an - # array. - if ($i[0] eq '') { - #Display all USE flags - foreach (sort keys %use_flags) { - $curr_key_len = length($_); - $max_len = $curr_key_len if $curr_key_len > $max_len; - push @use_flag_list, $use_flags{$_}; - } - } - else { - #Display USE flags for given arguments - foreach (sort @i) { - if (exists($use_flags{$_})) { - $curr_key_len = length($_); - $max_len = $curr_key_len if $curr_key_len > $max_len; - push @use_flag_list, $use_flags{$_} ; - } - else { - # Invalid use flag - add_warning($_, "Querying an invalid use flag."); - } - } - } - - format_output(\@use_flag_list, \$max_len); - format_warning(); - exit(0); - } - - # Enable USE flags and disable USE flags - if (defined(@E) || defined(@D)) { - - check_permissions("rw"); - - # Enable the last occurence of the USE flag. Check if already exists - # in make.conf. If exist and enabled leave it alone. If exists and - # disabled enable it. If not found, put an entry at the end. Why end? - # -* may be in effect somewhere in the USE flag. So adding in at the - # end will make sure it gets enabled. euse -E "*" or euse -E all will - # look for a -* in make.conf. If found removes it. - if (defined(@E)) { - remove_duplicates(\@E); - rearrange_args(\@E); - enable_use_flag($conf_uf_list_ref, \%use_flags); - } - - # Disable the last occurence of the USE flag. - # euse -D "*" will put a -* at the end of USE flag setting in make.conf. - if (defined(@D)) { - remove_duplicates(\@D); - rearrange_args(\@D); - disable_use_flag($conf_uf_list_ref, \%use_flags); - } - format_warning(); - exit(0); - } - exit(0); -} -#END Main - -# Show usage. Accepts optional argument. If given prints them as warning msg. -sub usage { - warn "@_\n" if @_; - die < +# Version: 0.2 +# Licensed under the GPL v2 + +PROGRAM_NAME=euse +PROGRAM_VERSION=0.1 + +MAKE_CONF_PATH=/etc/make.conf +MAKE_GLOBALS_PATH=/etc/make.globals +MAKE_PROFILE_PATH=/etc/make.profile +MAKE_CONF_BACKUP_PATH=/etc/make.conf.euse_backup + +MODE="showhelp" # available operation modes: showhelp, showversion, showdesc, showflags, modify + +parse_arguments() { + if [ -z "${1}" ]; then + return + fi + while [ -n "${1}" ]; do + case "${1}" in + -h | --help) MODE="showhelp";; + -v | --version) MODE="showversion";; + -i | --info) MODE="showdesc";; + -l | --local) SCOPE="local";; + -g | --global) SCOPE="global";; + -a | --active) MODE="showflags";; + -E | --enable) MODE="modify"; ACTION="add";; + -D | --disable) MODE="modify"; ACTION="remove";; + -P | --prune) MODE="modify"; ACTION="prune";; + -*) + echo "ERROR: unknown option ${1} specified." + echo + MODE="showhelp" + ;; + *) + ARGUMENTS="${ARGUMENTS} ${1}" + ;; + esac + shift + done } -# clean up reqd -sub handle_unknown -{ - no strict 'refs'; - if (defined $Curr_Arg) { - my $option = $Curr_Arg; - if ($option =~ /[$Args_Wo_Param]/) { - #print "param not required \n"; - #print "Option: $option " . join (",", @_) . "\n"; - push @{$Unknown_Args{$option}}, @_; - } - else { - #print "param is okay \n"; - push @$option, @_; - } - } - else { - #print "curr flag not defined \n"; - push @{$Unknown_Args{$Non_Arg}}, @_; - } +error() { + echo "ERROR: ${1}" + exit 1 } -sub parse_with_args -{ - no strict 'refs'; - my ($option, $value) = @_; - #print "parse with handle: " . $option . " " . $value . "\n"; - - push @$option, $value; #do not allow comma separated. - $Curr_Arg = $option; - +check_sanity() { + # file permission tests + local descdir + + descdir="$(get_portdir)/profiles" + + [ ! -r "${MAKE_CONF_PATH}" ] && error "${MAKE_CONF_PATH} is not readable" + [ ! -r "${MAKE_GLOBALS_PATH}" ] && error "${MAKE_GLOBALS_PATH} is not readable" + [ ! -s "${MAKE_PROFILE_PATH}" ] && error "${MAKE_PROFILE_PATH} is not a symlink" + [ -z "$(get_portdir)" ] && error "\$PORTDIR couldn't be determined" + [ ! -d "${descdir}" ] && error "${descdir} does not exist or is not a directory" + [ ! -r "${descdir}/use.desc" ] && error "${descdir}/use.desc is not readable" + [ ! -r "${descdir}/use.local.desc" ] && error "${descdir}/use.local.desc is not readable" + [ ! -r "$(get_make_defaults)" ] && error "$(get_make_defaults) is not readable" + [ "${MODE}" == "modify" -a ! -w "${MAKE_CONF_PATH}" ] && error ""${MAKE_CONF_PATH}" is not writable" } -sub parse_wo_args -{ - no strict 'refs'; - my ($option, $value) = @_; - #print "parse wo handle: " . $option . " " . $value . "\n"; - $$option = $value; - $Curr_Arg = $option; +showhelp() { + echo "${PROGRAM_NAME} v${PROGRAM_VERSION}" + echo + echo "Syntax: ${PROGRAM_NAME}