A python implementation of pacman -Rs for groups

I've created a simple python script which implements the pacman -Rs feature for package groups.
Here's the code:
#!/usr/bin/python
# Copyright (C) 2005 Shahar Weiss <[email protected]>
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
# This script is a wrap for pacman which allows for removing package groups using the -Rs flag.
# It works by checking which packages of the group were explicitly installed and makes sure these packages are not
# needed by any other out-of-group packages. It then uses pacman and it's -Rs feature to remove the remaining packages
# in the list.
# Version 0.0.4
import os, sys
def returnIndex(_list, _string):
"""Returns the index in _list which contains _string, returns -1 is _string was not found"""
for i in range(len(_list)):
if _list[i].find(_string)!=-1:
return i
return -1
def removeRequiredForOtherPackages(packageList):
"""Returns a list of all the packages which are not required for other packages meant for removal."""
tempList = packageList[:]
for i in range(len(packageList)):
Output = os.popen('pacman -Qi ' + packageList[i]).readlines()
startIndex = returnIndex(Output, 'Required By')
stopIndex = returnIndex(Output, 'Conflicts With')
requiredList = Output[startIndex:stopIndex]
tempReqList = requiredList[0].split(' ')
for j in range(1,len(requiredList)):
tempReqList.extend( requiredList[j].split(' '))
requiredList = tempReqList[:]
# Cleans requiredList from unneeded strings
removeAllStrings(requiredList, '')
removeAllStrings(requiredList, 'n')
requiredList = requiredList[3:]
if requiredList==['Nonen']:
continue
else:
for j in range(len(requiredList)):
# if there are packages who require the current package, check if they are enlisted for removal.
# if not, then remove the current package from the list
if requiredList[j] not in tempList:
tempList.remove( packageList[i] )
break
return tempList
def removeNonExplicit(packageList):
"""Returns a list of all the packages which were explicitly installed."""
# Creating a temporary list because removing an element from the original list instead
# might cause us going out of bounds in the loop.
tempList = packageList[:]
for i in range(len(packageList)):
packageInfoString = os.popen('pacman -Qi ' + packageList[i]).readlines()[11]
# if the package was not explicitly installed, remove it from the list
if packageInfoString.find('explicitly installed')==-1:
tempList.remove(packageList[i])
return tempList
def removeAllStrings(_list, _string):
"""Removes all instances of given _string from _list"""
while _string in _list:
_list.remove(_string)
def getGroupPackages(group_name):
"""Returns a list of the packages contained by a certain group"""
tempList = os.popen('pacman -Qg ' + group_name + ' 2>/dev/null').readlines()
# if there's no such group, quit.
if tempList==['n']:
print "No such group exists."
sys.exit(1)
packageList = []
for i in range(len(tempList)):
# Each element in tempList contains a string in the form of 'group packagen'.
# The parsing we do adds only the 'package' part to packageList.
packageList.append( tempList[i].split(' ')[1].split('n')[0] )
return packageList
def main(args):
if os.getuid()!=0:
print "This program should be run as root."
sys.exit(1)
if len(args)==1:
print "You did not provide a group for removal."
sys.exit(1)
packagesToRemove = getGroupPackages(args[-1])
packagesToRemove = removeNonExplicit(packagesToRemove)
packagesToRemove = removeRequiredForOtherPackages(packagesToRemove)
if packagesToRemove==[]:
print "No package was marked for removal."
sys.exit(1)
packageRemoveString=''
for i in range(len(packagesToRemove)):
packageRemoveString += packagesToRemove[i] + ' '
os.system('pacman -Rs ' + packageRemoveString)
if __name__=="__main__":
main(sys.argv)
Hope you like it and that it works well.
Enjoy.

If you like, you could put this in the scripts section of the wiki:
http://wiki2.archlinux.org/index.php/Scripts
Dusty

Similar Messages

  • Pacman port for minix

    Hello Forums,
    lately I discovered minix3, that cool microkernel OS. Here is an Wikipedia article about it.
    I gave it a shot and ran it in vmware (needs to be workstation 5 compatible or it fails), but the packagemanager ("packman"), honestly,  just sucked compared to arch's pacman. Then I thought about what was if there was a minix distribution with arch's features like pacman, rolling release, aur etc?
    What do you think about this idea?
    Also notice, that both minix and arch follow KISS ideas.
    PS: I already tried to compile pacman, but its not that easy. I couldn't even get libdownload running, a dependency of pacman, because it depends on glibc - which isn't ported yet (if it will ever be ported). Maybe a rewrite would be better - either of libdownload or a full one of pacman, but with its features (not saying that I have the skillz to do this yet, just thoughts).
    regards, thoughtcrime
    EDIT: Porting pacman to minix
    Pacman's dependencies: libarchive, libdownload (i'm planning to use libfetch instead as it does not depend on glibc(?))
    Note: I downloaded all the tar.gz files on my host Archlinux, repacked them to tar files and downloaded them with the VM from my host machine via wget (apache server). Then I could extract them with
    tar x archive.tar
    Before getting started:
    chmem =10000000 /usr/local/bin/bash
    chmem =10000000 /usr/bin/make
    export GREP=/usr/bin/grep
    export PATH=/usr/gnu/i386-pc-minix/bin:/usr/gnu/bin:$PATH
    1. libarchive
    depends on: zlib, bzip2
    1.1 zlib (tested with zlib-1.2.3.3)
    This one works out of the box:
    download the sources
    ./configure
    make
    make install
    1.2 bzip2 (tested with 1.0.5)
    download the source
    apply this hack:
    In bzip2.c, comment these lines out: 1067-1078
    make
    make install
    1.3 libarchive (tested with 2.5.5)
    download the source
    do these hacks:
    libarchive/archive_read_support_format_mtree.c:30
    add #define S_IFSOCK 0140000
    libarchive/archive_write_disc.c:505
    block_size = 4*1024;
    NOTE: This isn't really how it sould be. 4kb is just the default value for Minix; core-ix on #minix (freenode) suggested finding a relation between st_size (file size) and st_blksize
    libarchive/archive_write_set_format_pax.c:44
    add #define EILSEQ      (_SIGN 92)
    tar/siginfo.c:117
    safe_fprintf(stderr, "%s %s (%ju / %PRId64 )",
    NOTE: This one isn't great, too. Suggestions?
    then type
    ./configure
    make
    - this is how far i got it working
    2. libfetch
    3. pacman
    i'll try to complete this howto and get it really ported when I have time
    Last edited by thoughtcrime (2009-01-01 16:40:52)

    Ranguvar wrote:Minix is still more of an undergrad playground and proof that ridiculously stable OSen can be made than a desktop or even server/workstation OS. The vast majority of Linux software needs changes to work well with the Minix kernel. And for the people it targets, a distro isn't really necessary or helpful. Don't get me wrong - Minix is fricking awesome. It's beyond stable, (go ahead, try and make it crash - the devs are working on being able to repeatedly kill various drivers during a networked file transfer and STILL have it finish perfect, if that gives you an idea of what a rock it is) and is the kernel Linus used when writing Linux. I really hope ideas and code from it enter more mainsteam kernels, or it itself becomes more mainstream. But a distro won't really enhance that yet, I would say... and would require massive effort.
    I think at least a proper package manager like pacman can be very, very helpful. You know how many software there is in arch's AUR - so what if we had something like that for minix? More users would patch more software and everybody could install them  -> more mainstream, more popularity, more software ported etc
    catwell wrote:
    I still love the idea. I used Minix3 for a while and really enjoyed it. What made me stop is the lack of a real package manager. There are already some important applications that have been ported such as Apache, Python or X, so I think Minix3 is ready to be used, at least on a server. Linux was not really better at the end of the nineties, and still a lot of people already used it.
    EDIT: If somebody wants to port Pacman to Minix, it would be a good idea to either port glibc (which would probably be difficult), or use one of the Python implementations of Pacman around. I think this would be the the best solution for now.
    Thanks for telling me that there are python implementations of pacman. I'll have a look at them.
    wuischke wrote:I believe you can use bsd libfetch instead of libdownload. I compiled pacman with libfetch on OpenBSD using the native C library and without installing glibc (At least not consciously ), therefore I believe it is very well possible.
    This would be awesome, i'll give this a try when I have time
    Ranguvar wrote:Some nfo: http://sourceware.org/ml/libc-ports/200 … 00026.html
    "When will be glibc under MINIX 3?"
    - "Probably never."
    I've already read that before (not hard to find with google). Please note that this answer was given by the glibc team afaik, so this means that they may not want to do a port to minix at this point (maybe when its more popular). It does not mean, that it is not possible - so the community could do it.
    Thanks for your great feedback everybody. I'll try your ideas out and report if one of them works

  • Need suggestion on how to implement UNIX SSH connector for various server

    Hi everyone,
    We have various unix servers like ubantu, redhat and mandrake . each unix type have serveral machines around 50+ each.
    I want to have one resource object for each server type
    ex: ubantu, redhat, mandrake.
    User will select on the server type and this will bring all itresources under this type.
    Also when we install the connector it gives us one schedule task for group and user reconciliation. If i plan to have one RO for each of the server type what should I do to have one schedule task for each server type
    How difficult it would be to implement this? any guidance on how to proceed with this?
    Thanks,
    asat

    Hope that this could help you.
    Managing 100s of Unix Servers using OIM.
    -INIYA

  • Find the Manager for Group

    If this isn't a good place to ask this question I applogize in adavance if you could provide a link to the correct area I should ask/post this I would appreciate it. Otherwise...
    The end goal is to fill in the Managedby atribute for a lot of secuirty groups with a correct manager. I have a list of a 2100 groups and I have a data share that has like 10 petabytes of data in 3000 different directories, roughly. The point is there is
    a lot. At this point I'm just trying to identify who should be the manager for group.
    I'm trying to figure out the best way to approach this any and all advice/suggestions is apprecited. Even it is go pound sand, newby...hopefully not but I'll understand if it is :-)
    Found
    this searching
    Thanks in Adavance

    Fair enough...Sorry for wasteing your time, but thank you for your help
    Thanks in Adavance
    You are not wasting anyone's time it is just that there is no way to answer your question.  These decisions are based on your organization.  Scripts cannot decide who manages who.  You need to get with your management and implement an org
    chart.  The org chart gets directly tied to groups.  It starts with the org chart.  Each position gets a group and the manager or exec is the owner of the group.
    In most companies this may be delegated since so many managers and execs are computer illiterate.  The delegate becomes the group manager and manages resource allocation through group membership.
    This is Active Directory deployment 101.  I recommend contacting a certified consultant to help you set this up.  It is fundamental and critical.  I cannot understand how you can have a large AD deployment without having a formal design document. 
    It probably exists but those that know it have been let go to save money.  Now you are lost in limbo.
    Do more research.  Ask a lot of questions.  Be a detective and see if you can find the original documents.  If you succeed you will be a hero.
    ¯\_(ツ)_/¯

  • Checking Executable Permission for Group

    Hi All,
    Is there a command to check if a file has executable permission for group? I am aware that it can be checked looking at permissions using "ls". But, if the same functionality is implemented in a shell script, is there a command to achieve this? For example, "find" commad with "-perm" option...
    Thanks in advance

    There are several ways to accomplish the task if you want to check a specific file.
    For instance:
    $ touch testfile1
    $ touch testfile2
    $ chmod 740 testfile1
    $ chmod 750 testfile2
    $ ls -l testfile?
    -rwxr-----. 1 dude dude 0 May 13 11:51 testfile1
    -rwxr-x---. 1 dude dude 0 May 13 11:51 testfile2
    $ [ $(ls -l testfile1 | cut -c 7 | grep x ) ] && echo "yes" || echo "no"
    no
    $ [ $(ls -l testfile2 | cut -c 7 | grep x ) ] && echo "yes" || echo "no"
    yes

  • How  to add a new option for group by in a excel report

    Hi,
    there is a enhancement in a excel report
    I need to add a new option for group by
    help me
    Regards,
    Raghu

    k

  • Need a Suggestion For implementing the Digital Signature For the Documents

    Hi,
    Currently I am working in a Document Management System. I need a Good Suggestion for how to implement a Digital Signature For the Documents.
    Thanks in Advance
    Sabarish V

    Hmm, if you are not using Oracle Payroll, what are you using for payroll? I am wondering why you could not use your payroll system, whatever it is, to handle this reimbursement program.
    Well, you may want to talk to Oracle support about how to handle this in Oracle iExpense. You can certainly handle advances for Expense Reports. You would then apply the advance to the expense report items. The catch is I don't think you can stop expense item entry after the adavance is satisfied. You would have to set up a work flow process of some kind to have the expense reports reviewed and only approve expenses that are applied to the advance, is what I am thinking. Not your ideal solution, but something to think about. It could be the Oracle folks might know of a sneaky way to handle this. What you are trying to do is unusual. Employee advances are common, but the idea of not being able to exceed the advance amount is what unusual about this. Normally you will accept any expenses over the advance amount and reimburse the employee for those extra amounts not advanced.
    Good luck.
    John Dickey

  • How difficult is it to implement indirect sales tax for India?

    Dear All,
    What is the level of difficulty to implement indirect sales taxes for India? Is this a low, medium, or high level of difficulty implementation?
    Does India offer a nationalization package, and is it necessary to install India's nationalization?
    Ultimately, I need to get an estimate for the number of people and days of work involved in order to determine the expected cost.
    Kind regards,
    Mark

    Hi Mark,
    The level of difficulty to implement indirect sales taxes for India is high level of difficulty implementation?
    Country India Version is along with ECC. No need to implement any other package.
    Depend on the requirement it takes 2-3 months of implementation for CIN. And Two consultants are required to configure this implementation. If A consultant has 2-3 years in the CIN Configuration then 1 Consultant is enough. Cost vary from organization to organization.
    Regards,
    Srinivas Muthyala
    sap fi/co consultant

  • Calculation of Depreciation for Group Asset

    Hi Experts,
    I am getting a problem while doing depreciation for group asset
    Ex:  80,000;  Rate 10%
    total depreiaiton p.a is Rs 8000/-
    as per the Indian standards if it is below 180 days it should take Rs 4000/-, but in my system it is showing Rs 3333.33
    my depreciation start date & capitlization date is 01.11.2007.
    Regards,
    Satya Vani.

    Dear,
    Reshma.
    Looking at your Questions let us take explanation for Group Assets :-
    1 ) We need to create new different asset class for Group Class in OAOA. Then permit the depreciation area for only Group Asset in OAYM as it is in your current scenario India  is Depreciation Area 15 Just select your company code in OAYM and check the Grp Asset field for respective area 15. Then go to OAAX here we have to maintain the assets classes particularly for Group Assets. So check your Group Asset classes for Group Assets. Cerate different Group asset classes for your said requirement.
    In these depreciation areas, it is then possible to make an assignment to a group asset.  You make this assignment in the specifications for the depreciation area in the asset master record.  When you post an acquisition to this kind of asset, the system duplicates the line items from this depreciation area on the given group asset.
    2 ) According to me you have to create different depreciation keys for Group Asset classes. Assign the Depreciation keys to your newly created Group Asset Classes in OAYZ and make sure you are deactivating 01 area which is Book Depreciation area.
    3 ) As far as I know this is the only functionality available to handle Group Assets. How ever SAP does not have any standard Group Assets functionality. SAP does not supply asset classes to be used solely for group assets. It is we have to determine as per varying Business Process.
    I hope this will clear your doubt makes you to understand. Please revert back for further clarification. Welcome you.
    Regards,
    Pankaj A Bhalerao.
    Edited by: pankaj_ab on Feb 3, 2010 8:26 AM

  • MANUAL DEPRECIATION FOR GROUP ASSET

    dear sap gurus
    i want to post manual depreciaiton to an asset which is attached to a group asset
    could anyone tell the ways to do it please
    regards
    srini

    Hi
    Please check Transaction Code: OAYM - Specify Depreciation Areas for Group Assets
    Thanks and Regards
    P.V.S.R.Gupta

  • How do you change the volume used for group folders in Lion Server?

    So I'm slowly acclimating to Lion Server, however, I'm not able to determine how to specify the parent folder for Groups.  By default it's the /Groups root directory on the boot volume however I'm trying to change it to an alternate drive on a separate volume.  I've tried removing the sharepoint from the 'Server' admin utility and adding the alternate Group folder (on a separate volume) but to no avail.
    Has anyone else worked with this?

    Hey,
    Open Workgroup Manager app, from the ServerAdminTools, (link) enter your domain name for your server (FQDN), enter your OpenDirectory administrator user and password, go to Groups > Groups Folder.
    Hope this helps.

  • [Forum FAQ] The Value drop down list is grayed out when you perform search for Group Policy Objects in GPMC

    Symptom
    On Windows Server 2012 or Windows Server 2012 R2, when you use the Search for Group Policy Objects feature in GPMC, the “Value” field is not populated when you choose “User Configuration” as the Search Item. (See Figure 1.)
    <Figure 1>
    Cause
    The happens because the  Data of the (Default) value of the following Registry Key is not correct.
    [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\GPExtensions\{4D2F9B6F-1E52-4711-A382-6A8B1A003DE6}]
    By default the Data is (value not set). (see Figure 2)
    <Figure 2>
    Resolution
    The registry keys under [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\GPExtensions] are the Group Policy Preference Client Side Extensions. The CSE name of the GUID {4D2F9B6F-1E52-4711-A382-6A8B1A003DE6} is
    RemoteApp and Desktop Connections. Please follow the steps below to resolve the issue.
    1. Locate the registry key: [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\GPExtensions\{4D2F9B6F-1E52-4711-A382-6A8B1A003DE6}]
    2. Take the ownership of this key: Right click on the registry key and choose Permissions option and click the Advanced button on the dialogue window. Then on the Advanced Security Settings dialogue window, click Change button to take the ownership
    of the key for the current logon account and make the current logon account Full Control permission with the registry key. (See Figure 3.)
    <Figure 3> 
    3. Change the data of (Default) value from "(value not set)" to
    "RemoteApp and Desktop Connection Component". (See Figure 4)
    <Figure 4>
    4. Once the steps above are completed, the Value drop down list will be populated again when you perform Search in GPMC. (See Figure 5)
    <figure 5>
    This article has been created as a TechNet Wiki
    here.
    Please click to vote if the post helps you. This can be beneficial to other community members reading the thread.

    thanks for the tip - but you should create this as a wiki article as it will be easier to reference in the future
    Regards,
    Denis Cooper
    MCITP EA - MCT
    Help keep the forums tidy, if this has helped please mark it as an answer
    My Blog
    LinkedIn:

  • Location of security xml files for groups

    We are having some issues migrating security(only) from one sysmte to another in EPM 11.1.2 for a planning application. Is there any other way to migrate security?
    Where are the xmls for each group's security stored?

    John,
    We are working with Oracle on an MSAD issue in one of our environments. One of their suggestions is to recreate the essbase.sec file. Since all security needs to be rebuilt from scratch after this happens(and we have A LOT of security), we were wondering if we could somehow save all the groups etc if we locate the xml's for the same. Would it be possible to save all the security for groups etc in shared services somehow?

  • Implementing Custom Validation Logic for Payment Disbursements

    Hi All,
    Is there anyone here, who has implemented Custom Validation Logic for disbursements in Oracle payments.
    Theory: Under Payments Setup Administrator -> Formats -> Formats, we can setup a payment format and even attach a XML template. Apart from this we can setup Pre-defined validations or user Defined validations.
    For Pre-defined validations / seeded validations, Oracle has provided an API
    IBY_VALIDATIONSETS_PUB.evaluateCondition. We can use this API, and call a custom package by using the keyword 'CUSTOM' in the call.
    Has anyone played around with this package and successfully implemented custom validations. Does anyone have a sample code on how to implement this. The Payment Manager Implementation guide is of little help.
    Thanks

    This document was very helpful to me in creating a custom validation.
    http://docs.oracle.com/cd/E18727_01/doc.121/e13416/T387353T419293.htm

  • How to accout unplanned depreciation for group assets

    Friends,
    Unplanned depreciation is accounted for group assets few years ago.This is for special depreciation areas.
    Now i would like to reverse this amount as write up unpalnned depreciation,  but system is throwing eror message that: This  function is not possible for group assets.
    OR
    The issue what we are facing is special dep areas has one cent as -ve acquisition due to which we are unable to deactivate the asset. This one cent was accounted as unplanned dep few years ago. How do we make the APC as zero when it has -ve APC in special dep areas.
    pl,  suggest how to go about this.
    Thank
    NNS

    Hi,
    This is not possible in the standard and this is not a from SAP intended and provided solution. Therefore I ask you to be really careful and test it bevore on a test system.  (and perhaps to discuss this with your SAP consultant)
    The workaround to remove the group asset from table  ANLB-ANLGR from the asset could be done by creating your own program.
    Regards Bernhard

Maybe you are looking for