Commit c958de8d authored by onny's avatar onny

p2pacman: rootless db syncing

parent ac5b2937
......@@ -104,26 +104,22 @@ class threadstart(threading.Thread):
package = torrent(self.path, self.link)
packages.append(package)
os.system("pacman -Sy")
print(":: Starting full system upgrade...")
process = subprocess.Popen(['pacman', '-Sup'], shell=False, stdout=subprocess.PIPE)
processret = str(process.communicate()[0]) # get python stdout
processret = processret.replace("pkg.tar.xz","pkg.tar.xz.torrent") # append to every link .torrent
matchObject = re.search(r'(http://.*.pkg.tar.xz.torrent)', processret) # match all links
if matchObject:
torrentlinks = matchObject.group(1).split("\\n") # split links into a tuple
else:
os.system("if [ -d /tmp/p2pacman ]; then fakeroot pacman -Sy --dbpath /tmp/p2pacman; else mkdir /tmp/p2pacman && ln -s /var/lib/pacman/local /tmp/p2pacman && fakeroot pacman -Sy --dbpath /tmp/p2pacman; fi")
packages = os.popen("fakeroot pacman -Supb /tmp/p2pacman").readlines()[1:]
if len(packages) == 0:
print("no updates available")
exit(0)
print(" Downloading torrent metadata ...")
print(":: Downloading torrent metadata ...")
for link in torrentlinks:
for link in packages:
link = link.replace('pkg.tar.xz\n','pkg.tar.xz.torrent')
print(link)
try:
r = requests.get(link)
except:
print("error: mirror refues the connection, aborting.")
print("ERROR: Mirror refues the connection, aborting.")
exit(1)
if r.status_code == 200:
with open("/var/cache/pacman/pkg/"+link.split('/')[-1], 'wb') as f:
......@@ -131,13 +127,13 @@ for link in torrentlinks:
f.write(chunk)
f.close
else:
print("error: your mirror doesn't have proper torrent support")
print("ERROR: Your mirror doesn't have proper torrent support, aborting.")
exit(1)
thread = threadstart("/var/cache/pacman/pkg/"+link.split('/')[-1],link)
thread.start()
time.sleep(5)
print(" Starting torrents ...")
print(":: Starting torrents ...")
package_count = len(packages)
widgets = [PackageStat(), ' ', FileTransferSpeed(), '' ,
......@@ -173,7 +169,7 @@ pbar.finish()
print(" All downloads finished!")
print(" Installing packages ...")
print(":: Starting full system upgrade...""")
links = ""
for n, torrentlink in enumerate(torrentlinks):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment