33
37
self.project = project
34
38
# The project directory
35
self.project_folder_dir = 'projects/'
39
self.project_folder_dir = "projects/"
36
40
#if not os.path.exists(self.project_folder_dir):
37
41
# os.mkdir(self.project_folder_dir)
39
43
# Create the project in the project folder
40
self.project_dir = self.project_folder_dir + self.project + '/'
44
self.project_dir = self.project_folder_dir + self.project + "/"
41
45
#if not os.path.exists(self.project_dir):
42
46
# os.mkdir(self.project_dir)
44
48
# Create the directory to store the package lists
45
49
# from the internet
46
self.lists_dir = self.project_dir + 'lists/'
50
self.lists_dir = self.project_dir + "lists/"
47
51
#if not os.path.exists(self.lists_dir):
48
52
# os.mkdir(self.lists_dir)
50
54
# The location where the package lists are stored.
51
self.package_list_path = '/var/lib/apt/lists/'
55
self.package_list_path = "/var/lib/apt/lists/"
53
57
# create a new project and add it
54
project = Project('a','b','c','d','e')
55
project.relations = [Relation("type", "target")]
56
self.session.add(project)
58
#project = Project('a','b','c','d','e')
59
#project.relations = [Relation("type", "target")]
60
#self.session.add(project)
59
63
def on_create(self):
64
"""Create the project"""
65
# Test to see if aptitude is installed
66
if commands.getstatusoutput("aptitude --version")[0] == 0:
67
project = Project(self.project, platform.machine(),
68
platform.node(), "dpkg",
71
self.session.add(project)
72
self.project_entry = self.session.query(Project).filter(Project.name==self.project).all()[0]
74
# Add repos and relationships for them
77
raise OSError, "Aptitude is not installed on this machine."
60
79
#plm = PackageListManager('local', self.project_folder_dir)
61
80
#while not plm.at_end():
62
81
# plm.get_next_record()
85
"""Add /etc/apt/ list files into database"""
86
for root, dirs, files in os.walk("/etc/apt"):
89
test = re.compile(".list$", re.IGNORECASE)
90
lists = filter(test.search, files)
92
# TODO: Clean up, add line if contains content and doesn't start with #
93
lines = [line.strip() for line in open(os.path.join(root, file), "rb").readlines() if not line.strip().startswith("#") and line.strip()]
100
sections = " ".join(parts[3:])
102
# Check for existence
103
found = self.session.query(Repo).filter(Repo.url==url).filter(Repo.type==type).filter(Repo.url==url).filter(Repo.dist==dist).filter(Repo.sections==sections).all()
106
raise IOError, "Duplicate repository lines in database"
110
repo = Repo(type, url, dist, sections)
111
self.session.add(repo)
113
# Get the id for the newly created repo
114
found = self.session.query(Repo).filter(Repo.url==url).filter(Repo.type==type).filter(Repo.url==url).filter(Repo.dist==dist).filter(Repo.sections==sections).all()
116
# Create new relation
117
repo_rel = Relation("repo", found[0].id)
118
self.project_entry.relations.append(repo_rel)
65
121
def update_internet(self):
66
122
query = self.session.query(General)
70
126
pm = PackageManager()
71
127
pm.fetch_from_internet(['a', 'b'], 'lists')
73
130
class PackageListManager:
75
def __init__(self, option, lists_dir, sources_file='/etc/apt/sources.list', package_list_dir='/var/lib/apt/lists/'):
133
def __init__(self, option, lists_dir, sources_file="/etc/apt/sources.list", package_list_dir="/var/lib/apt/lists/"):
76
134
self.option = option
77
135
self.lists_dir = lists_dir
78
136
self.sources_file = sources_file