Created
September 12, 2010 20:32
-
-
Save garretraziel/576423 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#! /usr/bin/env python | |
import sys, string | |
def analyze_log(path): | |
logfile = open(path,"r") | |
cont = logfile.readlines() | |
logfile.close() | |
cont = parse_log(cont) | |
toinstall = {} | |
while cont: | |
endpos = cont.index("End") | |
cut = cont[1:endpos] | |
toinstall[cont[0]] = cut | |
del cont[:endpos+1] | |
toinstall = dict([(key, toinstall[key]) for key in toinstall if toinstall[key]]) | |
return toinstall | |
def parse_log(cont): | |
cont_new = [] | |
for x in cont: | |
if x[:5] == "Start": | |
cont_new.append(string.strip(x)) | |
elif x[:3] == "End": | |
cont_new.append("End") | |
elif x[:7] == "Install": | |
progs = string.split(x," ") | |
for prog in progs: | |
if prog != "Install:" and prog[0] != '(' and prog[0] not in '0123456789': | |
cont_new.append(prog) | |
elif x[:7] == "Upgrade": | |
pass | |
elif x[:6] == "Remove" or x[:5] == "Purge": | |
progs = string.split(x," ") | |
for prog in progs: | |
while cont_new.count(prog): | |
cont_new.remove(prog) | |
return cont_new | |
def create_script(path,progs): | |
script = open(path,"w") | |
script.write("#! /bin/bash\n\n") | |
script.write("# autocreated installation file with movescript.py\n") | |
script.write("# comment files you don't want to install with sharp\n\n") | |
for key in progs: | |
script.write("# "+key+"\n") | |
script.write("apt-get install "+string.join(progs[key],' ')+"\n") | |
script.close() | |
def main(args): | |
log = "/var/log/apt/history.log" | |
if len(args) == 1: | |
log = args[1] | |
out = args[2] | |
else: | |
out = args[1] | |
progs = analyze_log(log) | |
create_script(out,progs) | |
#print "Script created!" | |
if __name__ == "__main__": | |
if len(sys.argv) == 1: | |
print "run as 'python movescript.py [infile] outfile'" | |
else: main(sys.argv) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
So it is similar to
pacman -Qqe
on Arch Linux.