OpenSUSE post install Python script

Hi Guys,

Just writing up a python script for post install on openSUSE machines. Just thought I would share on here. Currently it just updates your machine post install but im looking to add more features to it possibly with argparse for adding specific packages.

Linky to Github here

Just working on it when I can, if you have anything you always do after fresh install feel free to suggest here, or create an issue on Github. Its very experimental just now and will be broken and fixed regularly.

Thanks
William

On 2014-02-03, williamfleming <williamfleming@no-mx.forums.opensuse.org> wrote:
> Just writing up a python script for post install on openSUSE machines.
> Just thought I would share on here. Currently it just updates your
> machine post install but im looking to add more features to it possibly
> with argparse for adding specific packages.
>
> ‘Linky to Github here’ (https://github.com/william20111/opensusepy)

Dear William,

For those who are interested, I’ve postscripted the contributed code to this message.

William - thanks for your contribution. I just have three questions:

  1. Exactly who are your target users for this code?
  2. What advantage did you envisage using Python rather than simple bash?
  3. If you intending to make life easier for new openSUSE users, have you considered programming for YaST (which has
    recently been ported from YCP to Ruby)? It would mean coding in Ruby rather than Python but they are very similar.

Fly.

P.S. William’s Python code (indentation on HTML broken because of openSUSE’s borked NNTP->HTML conversion for code - a
particularly rubbish bug for Python code!):


#!/usr/bin/python
#
# Post install script for opensuse 13.1
#
# William Fleming
# http://kerneltalk.co.uk

import argparse
import os
import sys
import logging
import datetime
import platform
from subprocess import Popen, PIPE


_LOGFILE = "/tmp/opensusepy"
_SPLIT = "---------------------------------------"
_FAIL = "[FAIL]"
_PASS = "[PASS]"

class bcolors():
HEADER = '\033[95m'
OKBLUE = '\033[94m'
OKGREEN = '\033[92m'
WARNING = '\033[93m'
FAIL = '\033[91m'
ENDC = '\033[0m'

def disable(self):
self.HEADER = ''
self.OKBLUE = ''
self.OKGREEN = ''
self.WARNING = ''
self.FAIL = ''
self.ENDC = ''

class methods():

def checkver(self):
plt = platform.linux_distribution()
if plt[1] == "12.3":
print(bcolors.OKGREEN + "You are running " + plt[0] + " " + _PASS + bcolors.ENDC)
else:
print(bcolors.FAIL + "Your not running a supported version of Opensuse " + _FAIL + bcolors.ENDC)
sys.exit(0)

def checkroot(self):
uid = os.geteuid()
if uid == 0:
print(bcolors.OKGREEN + "You have root privileges " + _PASS + bcolors.ENDC)
else:
print(bcolors.FAIL + "You do not have root privileges " + _PASS + bcolors.ENDC)
sys.exit(0)

def updateopensuserepo():
with open(os.devenull, 'w') as tempf:
upgrd = Popen("zypper", "up", "--non-interactive", "--quiet"], stdout=tempf).communicate()
print(bcolors.FAIL + " " + _FAIL + bcolors.ENDC)

def pythontools():
with open(os.devnull, 'w') as tempf:
pydev = Popen("zypper", "in","python3","python-pip","--non-interactive", "quiet"], stdout=tempf).communicate()



""" Start the script"""

if __name__ == "__main__":
print("This is version 0.1 of opensuse.py" + "
" + _SPLIT)
m = methods()
m.checkver()
m.checkroot()
m.updateopensuserepo()
m.pythontools()