home *** CD-ROM | disk | FTP | other *** search
- #/usr/bin/python
- import os, sys, commands, string
-
- import os, popen2, fcntl, fcntl, select
- import fileinput, re
-
- import classes
- import interfaceclasses
- import objects
-
-
- '''CAPTURING UNIX APPS OUTPUT'''
- def makeNonBlocking(fd):
- fl = fcntl.fcntl(fd, fcntl.F_GETFL)
- try:
- fcntl.fcntl(fd, fcntl.F_SETFL, fl | os.O_NDELAY)
- except AttributeError:
- fcntl.fcntl(fd, fcntl.F_SETFL, fl | fcntl.FNDELAY)
-
-
- def getCommandOutput(command):
- child = popen2.Popen3(command, 1) # capture stdout and stderr from command
- child.tochild.close() # don't need to talk to child
- outfile = child.fromchild
- outfd = outfile.fileno()
- errfile = child.childerr
- errfd = errfile.fileno()
- makeNonBlocking(outfd) # don't deadlock!
- makeNonBlocking(errfd)
- outdata = errdata = ''
- outeof = erreof = 0
- while 1:
- ready = select.select([outfd,errfd],[],[]) # wait for input
- if outfd in ready[0]:
- outchunk = outfile.read()
- if outchunk == '': outeof = 1
- outdata = outdata + outchunk
- if errfd in ready[0]:
- errchunk = errfile.read()
- if errchunk == '': erreof = 1
- errdata = errdata + errchunk
- if outeof and erreof: break
- select.select([],[],[],.1) # give a little time for buffers to fill
- err = child.wait()
- if err != 0:
- raise RuntimeError, '%s failed w/ exit code %d\n%s' % (command, err, errdata)
- return outdata
-
- def addmakefile32():
- '''Add a makefile.cpu for 32bit recompiled kernels'''
- kernelv = os.uname()[2]
- makefilepath = '/usr/src/' + 'kernel-headers-' + kernelv + '/arch/i386/Makefile.cpu'
- make32 = open(makefilepath, 'w')
- make32.write('# CPU tuning section - shared with UML.\n\
- # Must change only cflags-y (or [yn]), not CFLAGS! That makes a difference for UML.\n\
- #-mtune exists since gcc 3.4\n\
- HAS_MTUNE := $(call cc-option-yn, -mtune=i386)\n\
- ifeq ($(HAS_MTUNE),y)\n\
- tune = $(call cc-option,-mtune=$(1),)\n\
- else\n\
- tune = $(call cc-option,-mcpu=$(1),)\n\
- endif\n\
- \n\
- align := $(cc-option-align)\n\
- cflags-$(CONFIG_M386) += -march=i386\n\
- cflags-$(CONFIG_M486) += -march=i486\n\
- cflags-$(CONFIG_M586) += -march=i586\n\
- cflags-$(CONFIG_M586TSC) += -march=i586\n\
- cflags-$(CONFIG_M586MMX) += -march=pentium-mmx\n\
- cflags-$(CONFIG_M686) += -march=i686\n\
- cflags-$(CONFIG_MPENTIUMII) += -march=i686 $(call tune,pentium2)\n\
- cflags-$(CONFIG_MPENTIUMIII) += -march=i686 $(call tune,pentium3)\n\
- cflags-$(CONFIG_MPENTIUMM) += -march=i686 $(call tune,pentium3)\n\
- cflags-$(CONFIG_MPENTIUM4) += -march=i686 $(call tune,pentium4)\n\
- cflags-$(CONFIG_MK6) += -march=k6\n\
- # Please note, that patches that add -march=athlon-xp and friends are pointless.\n\
- # They make zero difference whatsosever to performance at this time.\n\
- cflags-$(CONFIG_MK7) += -march=athlon\n\
- cflags-$(CONFIG_MK8) += $(call cc-option,-march=k8,-march=athlon)\n\
- cflags-$(CONFIG_MCRUSOE) += -march=i686 $(align)-functions=0 $(align)-jumps=0 $(align)-loops=0\n\
- cflags-$(CONFIG_MEFFICEON) += -march=i686 $(call tune,pentium3) $(align)-functions=0 $(align)-jumps=0 $(align)-loops=0\n\
- cflags-$(CONFIG_MWINCHIPC6) += $(call cc-option,-march=winchip-c6,-march=i586)\n\
- cflags-$(CONFIG_MWINCHIP2) += $(call cc-option,-march=winchip2,-march=i586)\n\
- cflags-$(CONFIG_MWINCHIP3D) += $(call cc-option,-march=winchip2,-march=i586)\n\
- cflags-$(CONFIG_MCYRIXIII) += $(call cc-option,-march=c3,-march=i486) $(align)-functions=0 $(align)-jumps=0 $(align)-loops=0\n\
- cflags-$(CONFIG_MVIAC3_2) += $(call cc-option,-march=c3-2,-march=i686)\n\
- \n\
- # AMD Elan support\n\
- cflags-$(CONFIG_X86_ELAN) += -march=i486\n\
- \n\
- # Geode GX1 support\n\
- cflags-$(CONFIG_MGEODEGX1) += -march=pentium-mmx\n\
- \n\
- # add at the end to overwrite eventual tuning options from earlier\n\
- # cpu entries\n\
- cflags-$(CONFIG_X86_GENERIC) += $(call tune,generic)\n')
- make32.close()
-
- def addmakefile64():
- '''Add a makefile.cpu for 64bit recompiled kernels'''
- kernelv = os.uname()[2]
- makefilepath = '/usr/src/' + 'kernel-headers-' + kernelv + '/arch/i386/Makefile.cpu'
- make64 = open(makefilepath, 'w')
- make64.write('# CPU tuning section - shared with UML.\n\
- # Must change only cflags-y (or [yn]), not CFLAGS! That makes a difference for UML.\n\
- #-mtune exists since gcc 3.4, and some -mcpu flavors didn\'t exist in gcc 2.95.\n\
- HAS_MTUNE := $(call cc-option-yn, -mtune=i386)\n\
- ifeq ($(HAS_MTUNE),y)\n\
- tune = $(call cc-option,-mtune=$(1),)\n\
- else\n\
- tune = $(call cc-option,-mcpu=$(1),)\n\
- endif\n\
- \n\
- align := $(cc-option-align)\n\
- cflags-$(CONFIG_M386) += -march=i386\n\
- cflags-$(CONFIG_M486) += -march=i486\n\
- cflags-$(CONFIG_M586) += -march=i586\n\
- cflags-$(CONFIG_M586TSC) += -march=i586\n\
- cflags-$(CONFIG_M586MMX) += $(call cc-option,-march=pentium-mmx,-march=i586)\n\
- cflags-$(CONFIG_M686) += -march=i686\n\
- cflags-$(CONFIG_MPENTIUMII) += -march=i686 $(call tune,pentium2)\n\
- cflags-$(CONFIG_MPENTIUMIII) += -march=i686 $(call tune,pentium3)\n\
- cflags-$(CONFIG_MPENTIUMM) += -march=i686 $(call tune,pentium3)\n\
- cflags-$(CONFIG_MPENTIUM4) += -march=i686 $(call tune,pentium4)\n\
- cflags-$(CONFIG_MK6) += -march=k6\n\
- # Please note, that patches that add -march=athlon-xp and friends are pointless.\n\
- # They make zero difference whatsosever to performance at this time.\n\
- cflags-$(CONFIG_MK7) += $(call cc-option,-march=athlon,-march=i686 $(align)-functions=4)\n\
- cflags-$(CONFIG_MK8) += $(call cc-option,-march=k8,$(call cc-option,-march=athlon,-march=i686 $(align)-functions=4))\n\
- cflags-$(CONFIG_MCRUSOE) += -march=i686 $(align)-functions=0 $(align)-jumps=0 $(align)-loops=0\n\
- cflags-$(CONFIG_MEFFICEON) += -march=i686 $(call tune,pentium3) $(align)-functions=0 $(align)-jumps=0 $(align)-loops=0\n\
- cflags-$(CONFIG_MWINCHIPC6) += $(call cc-option,-march=winchip-c6,-march=i586)\n\
- cflags-$(CONFIG_MWINCHIP2) += $(call cc-option,-march=winchip2,-march=i586)\n\
- cflags-$(CONFIG_MWINCHIP3D) += $(call cc-option,-march=winchip2,-march=i586)\n\
- cflags-$(CONFIG_MCYRIXIII) += $(call cc-option,-march=c3,-march=i486) $(align)-functions=0 $(align)-jumps=0 $(align)-loops=0\n\
- cflags-$(CONFIG_MVIAC3_2) += $(call cc-option,-march=c3-2,-march=i686)\n\
- \n\
- # AMD Elan support\n\
- cflags-$(CONFIG_X86_ELAN) += -march=i486\n\
- \n\
- # Geode GX1 support\n\
- cflags-$(CONFIG_MGEODEGX1) += $(call cc-option,-march=pentium-mmx,-march=i486)\n')
- make64.close()
-
- def rmmakefile():
- '''Remove the makefile.cpu for recompiled kernels'''
- kernelv = os.uname()[2]
- makefilepath = '/usr/src/' + 'kernel-headers-' + kernelv + '/arch/i386/Makefile.cpu'
- try:
- os.remove(makefilepath)
- except (OSError):
- pass
-
- #systemname = codename()
- #arca = architecture()
- '''Oggetto che si appoggia alla classe Specsdetect'''
-
-
-
- def remove_nvidia_pkg():
- os.system('sudo apt-get --assume-yes --purge remove nvidia-glx nvidia-kernel-`uname -r` nvidia-glx-dev nvidia-kernel-source')
- os.system('sudo apt-get --assume-yes --purge remove nvidia-glx-new nvidia-new-kernel-`uname -r` nvidia-glx-new-dev nvidia-new-kernel-source libgl1-mesa-dev mesa-common-dev 1>&2')
- os.system('sudo apt-get --assume-yes --purge remove nvidia-glx-legacy nvidia-legacy-kernel-source nvidia-settings 1>&2')
- os.system('sudo rm /usr/src/nvidia*.deb 1>&2')
-
- def remove_ati_pkg():
- os.system('sudo apt-get --assume-yes --purge remove fglrx-control fglrx-kernel-`uname -r` fglrx-kernel-source xorg-driver-fglrx xorg-driver-fglrx-dev fglrx-amdcccle 1>&2')
- os.system('sudo rm /usr/src/fglrx*.deb 1>&2')
-
- def dm_stop():
- os.system('sudo /etc/init.d/gdm stop; sudo /etc/init.d/kdm stop')
-
- def remove_deb():#for both ATI and Nvidia
- os.system('sudo rm *.deb 1>&2')
-
- def atiremovechanges():#removes files such as fglrx-installer_8.33.6-1_i386.changes
- os.system('sudo rm *.changes 1>&2')
- #os.system('sudo rm *.asc')
-
- def nvremovechanges():#removes files such as fglrx-installer_8.33.6-1_i386.changes
- os.system('sudo rm *.changes 1>&2')
- os.system('sudo rm *.asc 1>&2')
-
- def remove_debsrc():#for both ATI and Nvidia
- os.system('sudo rm /usr/src/*.deb 1>&2')
- os.system('sudo rm -R /usr/src/modules/nvidia-kernel 1>&2')
- os.system('sudo rm -R /usr/src/modules/fglrx-kernel 1>&2')
-
- def depmodules():
- os.system('sudo depmod -a')
-
- def restoremesa():
- os.system('sudo apt-get -y install --reinstall libgl1-mesa-glx libglu1-mesa libgl1-mesa-dri')
-
- def pcrestart():
- while 1:
- xsrv = raw_input('Do you want to restart your computer now (Recommended)? (y/n) \ "y" is the default answer\n')
- if xsrv.lower() == 'y' or xsrv.lower() == '' or xsrv.lower() == 'yes':
- os.system('sudo reboot')
- break
- sys.exit()
- elif xsrv.lower() == 'n':
- print 'Remember to restart your computer manually'
- break
- sys.exit()
- elif xsrv.lower() == 'no':
- print 'Remember to restart your computer manually'
- break
- sys.exit()
-
- def dependencies():
- os.system('sudo apt-get --assume-yes install linux-headers-`uname -r`')
- os.system('sudo apt-get --assume-yes install build-essential')
- os.system('sudo apt-get --assume-yes install xserver-xorg-dev')
- os.system('sudo apt-get --assume-yes install pkg-config dpkg-dev')
- os.system('sudo apt-get --assume-yes install gcc dpatch')
- os.system('sudo apt-get --assume-yes install module-assistant fakeroot dh-make debhelper debconf libstdc++5')
-
- def blkresmanager():
- os.system('sudo rm /lib/linux-restricted-modules/.nvidia*')
-
- def xserverstart():
- while 1:
- xsrv = raw_input('Do you want to Start the Xserver now? (y/n) \ "y" is the default answer\n')
- if xsrv.lower() == 'y' or xsrv.lower() == '' or xsrv.lower() == 'yes':
- os.system('sudo /etc/init.d/gdm restart; sudo /etc/init.d/kdm restart')
- sys.exit()
- break
- elif xsrv.lower() == 'n':
- print 'Remember to start the xserver manually'
- break
- #sys.exit()
- elif xsrv.lower() == 'no':
- print 'Remember to start the xserver manually'
- break
- #sys.exit()
-
-
- def xorgset():
- answer = raw_input('Do you want your xorg.conf to be automatically configured? (y/n) \ "y" is the default answer\n')
- while 1:
- if answer == 'y' or answer == '':
- return 'y'
- elif answer == 'n':
- return 'n'
-
-
-
-
-
-