-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbrewprogram.py
More file actions
68 lines (58 loc) · 1.89 KB
/
brewprogram.py
File metadata and controls
68 lines (58 loc) · 1.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import subprocess
import re
# Class representing a basic brew program.
class BrewProgram(object):
def __init__(self, name):
'''
Initializes the brew program
'''
self.name = name # the name of the program
self.deps = [] # the program's dependencies
self.uses = [] # the program's uses
def build_deps(self):
'''
Gets the dependencies of the program and stores them in deps
'''
output = subprocess.check_output(["brew", "deps", str(self.name)])
self.deps = output.split("\n")
self.deps.pop()
def build_uses(self):
'''
Gets the uses of the program and stores them in uses
'''
# `brew uses` returns all the uses for the program. Obviously, that
# information is not needed in the database object, but that information
# is retained in the brewprogram object to preserve OOP purity. The
# filtering is done on creation of a database
output = subprocess.check_output(["brew", "uses", str(self.name)])
self.uses = output.split("\n")
self.uses.pop()
def get_deps(self):
'''
Returns the program's dependencies
'''
return self.deps
def get_uses(self):
'''
Returns the program's uses
'''
return self.uses
def get_name(self):
'''
Returns the program's name
'''
return self.name
def number_of_deps(self):
'''
Returns the number of dependencies that the program has
'''
return len(self.deps)
def number_of_uses(self):
'''
Returns the number of uses that the program has
'''
return len(self.uses)
def __repr__(self):
return str(self.name)
def __str__(self):
return self.name