-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update code style, documentation and copyright.
Signed-off-by: Rudá Moura <[email protected]>
- Loading branch information
Showing
4 changed files
with
25 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. | ||
|
@@ -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 | ||
|
@@ -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() | ||
|
@@ -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) | ||
|
@@ -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) | ||
|
@@ -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) | ||
|
@@ -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: | ||
|
@@ -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()) |