Skip to content

Commit

Permalink
Adds support for querying packages
Browse files Browse the repository at this point in the history
  • Loading branch information
idealrealism committed Jul 25, 2017
1 parent f306849 commit 95e261e
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 4 deletions.
49 changes: 49 additions & 0 deletions import.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#!/usr/bin/env bash

#Checks for archlinux
OS_INFO=$(cat /etc/os-release | grep -i 'archlinux')
if [ "$?" -eq 0 ]; then
pkg_srch=$(pacman -Ss | grep ${1})

if [ "$?" -eq 0 ]; then
sudo pacman -Syu ${1} 2> /dev/null
else
exit 1
fi
fi

#Checks for Ubuntu
OS_INFO=$(cat /etc/os-release | grep -i 'Ubuntu')
if [ "$?" -eq 0 ]; then
pkg_srch=$(apt-get update && apt list | grep ${1})

if [ "$?" -eq 0 ]; then
sudo apt-get install -y ${1} 2> /dev/null
else
exit 1
fi
fi

#Checks for fedora
OS_INFO=$(cat /etc/os-release | grep -i 'fedora')
if [ "$?" -eq 0 ]; then
pkg_srch=$(yum list | grep ${1})

if [ "$?" -eq 0 ]; then
sudo yum update && yum install -y ${1} 2> /dev/null
else
exit 1
fi
fi

#Will Check for gentoo
# OS_INFO=$(cat /etc/os-release | grep -i 'gentoo')
# if [ "$?" -eq 0 ]; then
# emerge -s ${1}
#
# if [ "$?" -eq 0 ]; then
# emerge ${1} 2> /dev/null
# else
# exit 1
# fi
# fi
16 changes: 12 additions & 4 deletions zpyi.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import sys
import os
from math import *
import subprocess

if 'ZPYI_IMPORTS' in os.environ:
for module in os.environ['ZPYI_IMPORTS'].split(','):
Expand Down Expand Up @@ -38,10 +39,17 @@ def cleanup():
# Use try catch to return only after cleanup
try:
if len(code) == 1 and not code[0].startswith('print'):
# Commands like:
# '1+2'
# Also should display output
print (eval(code[0]))

#Call to import script to check if it's a package and installable
_import_call_result = subprocess.call(['./import.sh', code[0]])

#If the above call exits with non-zero status than the usual eval
# is called so that
# Commands like:
# '1+2'
# Also display output
if(_import_call_result!=0):
print (eval(code[0]))
else:
# Bigger commands
# 'a = 2
Expand Down

0 comments on commit 95e261e

Please sign in to comment.