Skip to content

Commit

Permalink
allow recommendations backports to actually add the repo #94
Browse files Browse the repository at this point in the history
  • Loading branch information
fossfreedom committed Mar 1, 2017
1 parent 0d2338e commit 3e887f2
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 35 deletions.
36 changes: 32 additions & 4 deletions budgie-welcome
Original file line number Diff line number Diff line change
Expand Up @@ -177,10 +177,10 @@ class AppView(WebKit2.WebView):
if installed:
app.update_page('#' + code + '-remove', 'show')
else:
app.update_page('#' + code + '-install', 'show')
app.update_page('#' + code + '-install', 'show')
# Sort recommendations after checking installation status
if current_page == 'recommendations':
self.run_javascript("sortList()")
self.run_javascript("sortList()")
# Checking on cache will take sometime. So run it on a
# separate thread.
thread = Thread(target = checkInstallationStatus)
Expand Down Expand Up @@ -547,7 +547,6 @@ class AppView(WebKit2.WebView):
systemstate.addIntermediateActions(fname, actions)

pmentry = PMEntry(operation, fname, code, actions)

pm_queue.put(pmentry)

app.update_page('#status-btn', 'fadeIn')
Expand Down Expand Up @@ -662,7 +661,30 @@ class PackageManager(Thread):

packages = pdata.getPackages(current_page, code)

if not packages: return
if not packages:
# assume we are just dealing with ppa's
repos = pdata.getRepos(current_page, code)
found = False

if repos:
# for the first element of the codename (e.g. zesty)
# repo split by the / character to get an array
# first element is the ppa organisation and second
# is the ppa name
ppa = repos[systemstate.codename][0][4:].split('/')

filename = ppa[0] + "-ubuntu-" + ppa[1] + "-" + \
systemstate.codename + ".list"
filename = '/etc/apt/sources.list.d/' + filename

p = subprocess.Popen(['grep', '^deb\ http', filename])
retval = p.wait()

if retval == 0:
found = True


return found

installed = True

Expand Down Expand Up @@ -803,6 +825,12 @@ class PackageData(object):
except KeyError:
return None

def getRepos(self, filename, code):
try:
return self.data[filename][code]["repos"]
except KeyError:
return None

class PMEntry(object):
INSTALL = 0
REMOVE = 1
Expand Down
59 changes: 28 additions & 31 deletions budgie-welcome-privileged-actions
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def add_repos(repos, key_commands):
if not repos: return 0

release_code = platform.dist()[2] # → xenial, yakkety, zesty

if "all" in repos : repos = repos["all"]
else : repos = repos.get(release_code)

Expand All @@ -37,93 +37,90 @@ def add_repos(repos, key_commands):
else:
sp.add_source_from_shortcut(shortcut_handler(repo))
sp.sourceslist.save()

if key_commands:
for key_command in key_commands:
subprocess.call(key_command, shell=True)

# Update always. Ideally, this should be done only if a new repo is added
# to list
p = subprocess.Popen(['apt', 'update'])

return p.wait()

def install(fname, code):
info = pdata.getPackageInfo(fname, code)
repos = info.get("repos")
packages = info.get("packages")
excludes = info.get("excludes")
key_commands = info.get("key-commands")

# Possibly enable repo
if not packages: return

retval = add_repos(repos, key_commands)

if excludes != None:
for exclude in excludes:
packages.append(exclude + '-')
process = subprocess.Popen(['apt', 'install', '--allow-unauthenticated', '-y'] + packages)

retval += process.wait()

if packages:
process = subprocess.Popen(['apt', 'install', '--allow-unauthenticated', '-y'] + packages)
retval += process.wait()

return retval

def remove(fname, code):
info = pdata.getPackageInfo(fname, code)
packages = info["packages"]

process = subprocess.Popen(['apt', 'remove', '-y'] + packages)

retval = process.wait()

return retval

def run_script(fname):

process = subprocess.Popen(['sh', fname])

retval = process.wait()

return retval

class PackageData(object):

def __init__(self, json_path):
# app._data_path + "/config/packages.json"
with open(json_path) as file:
self.data = json.load(file)
self.data = json.load(file)


def getPackageInfo(self, filename, code):
try:
return self.data[filename][code]
except KeyError as e:
print(e)
return None

if __name__ == "__main__":
'''
args[1] action to perform (INSTALL/REMOVE/SCRIPT)
args[2] file name in which package is listed
args[3] code name for package
args[4] path to json file containing package details
'''

args = sys.argv

if len(args) < 5:
print("Expected arguments not found")
sys.exit(-1)

action = args[1]
fname = args[2]
code = args[3]
json_path = args[4]

pdata = PackageData(json_path)

if action == 'INSTALL':
retval = install(fname, code)
elif action == 'REMOVE':
Expand Down

0 comments on commit 3e887f2

Please sign in to comment.