Skip to content

Commit

Permalink
Update code style, documentation and copyright.
Browse files Browse the repository at this point in the history
Signed-off-by: Rudá Moura <[email protected]>
  • Loading branch information
ruda committed Mar 22, 2017
1 parent a54c9c6 commit c91151f
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 16 deletions.
3 changes: 1 addition & 2 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
Copyright (c) 2011-2016, Rudá Moura <[email protected]>
All rights reserved.
Copyright (c) 2011-2017, Rudá Moura <[email protected]>. All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

Expand Down
4 changes: 2 additions & 2 deletions README
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Poof is a command line utility to list and uninstall/remove OS X packages.
Poof is a command line utility to list and uninstall/remove macOS packages.

*NO WARRANTY* DON'T BLAME ME if you destroy your installation!
NEVER REMOVE com.apple.* packages unless you know what you are doing.
Expand All @@ -10,7 +10,7 @@ then forget the metadata (the receipt data).

Get poof:

$ curl -O https://raw.github.com/ruda/poof/master/poof.py
$ curl -O https://raw.githubusercontent.com/ruda/poof/master/poof.py
$ chmod +x poof.py

Usage:
Expand Down
8 changes: 4 additions & 4 deletions poof.1
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
.\" Manpage for poof
.Dd January 15, 2016
.Dd March 21, 2017
.Dt poof 1
.Os OS X
.Os macOS
.Sh NAME
.Nm poof
.Nd List and uninstall/remove OS X packages
.Nd List or uninstall/remove OS X packages
.Sh SYNOPSIS
.Nm Ar package-id
.Sh DESCRIPTION
The
.Nm
command line utility list and uninstall/remove OS X packages in a low-level manner,
command line utility list or uninstall/remove macOS packages in a low-level manner,
it first removes all files and directories declared by the package and
then forget the metadata (the receipt data).
.Sh EXAMPLES
Expand Down
26 changes: 18 additions & 8 deletions poof.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
#
# Poof: List and uninstall/remove OS X packages
# Copyright (c) 2011-2016 Rudá Moura <[email protected]>
# Poof: List and uninstall/remove macOS packages
# Copyright (c) 2011-2017 Rudá Moura <[email protected]>
#

"""Poof is a command line utility to list and uninstall/remove OS X packages.
"""Poof is a command line utility to list and uninstall/remove macOS packages.
*NO WARRANTY* DON'T BLAME ME if you destroy your installation!
NEVER REMOVE com.apple.* packages unless you know what you are doing.
Expand Down Expand Up @@ -40,12 +40,15 @@
"""

from subprocess import Popen, PIPE
import sys, os
import sys
import os


class Shell(object):
def __getattribute__(self, attr):
return Command(attr)


class Command(object):
def __init__(self, command):
self.command = command
Expand All @@ -55,7 +58,7 @@ def __call__(self, params=None):
if params:
args += params.split()
return self.run(args)

def run(self, args):
p = Popen(args, stdout=PIPE, stderr=PIPE)
out, err = p.communicate()
Expand All @@ -64,11 +67,13 @@ def run(self, args):
else:
return False, err.strip().split('\n')


def package_list():
sh = Shell()
sts, out = sh.pkgutil('--pkgs')
return out


def package_info(package_id):
sh = Shell()
ok, info = sh.pkgutil('--pkg-info ' + package_id)
Expand All @@ -77,6 +82,7 @@ def package_info(package_id):
info = [x.split(': ') for x in info]
return dict(info)


def package_files(package_id):
sh = Shell()
ok, files = sh.pkgutil('--only-files --files ' + package_id)
Expand All @@ -89,11 +95,13 @@ def package_files(package_id):
break
return files, dirs


def package_forget(package_id):
sh = Shell()
ok, msg = sh.pkgutil('--verbose --forget ' + package_id)
return msg


def package_remove(package_id, force=True, verbose=False):
try:
info = package_info(package_id)
Expand All @@ -104,15 +112,15 @@ def package_remove(package_id, force=True, verbose=False):
if info['location']:
prefix += info['location'] + os.sep
files, dirs = package_files(package_id)
files = [prefix+x for x in files]
files = [prefix + x for x in files]
clean = True
for path in files:
try:
os.remove(path)
except OSError as e:
clean = False
print e
dirs = [prefix+x for x in dirs]
dirs = [prefix + x for x in dirs]
dirs.sort(lambda p1, p2: p1.count('/') - p2.count('/'),
reverse=True)
for dir in dirs:
Expand All @@ -128,15 +136,17 @@ def package_remove(package_id, force=True, verbose=False):
print msg[0]
return clean


def main(argv=None):
if argv == None:
argv = sys.argv
if len(argv) == 1:
for pkg in package_list():
print pkg
for arg in argv[1:]:
for arg in argv[1:]:
package_remove(arg)
return 0


if __name__ == '__main__':
sys.exit(main())

0 comments on commit c91151f

Please sign in to comment.