home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2007 September / PCWSEP07.iso / Software / Linux / Linux Mint 3.0 Light / LinuxMint-3.0-Light.iso / casper / filesystem.squashfs / usr / share / envy / instun / main.py < prev    next >
Encoding:
Python Source  |  2007-05-13  |  10.3 KB  |  251 lines

  1. #/usr/bin/python
  2. import os, sys, commands, string
  3.  
  4. import os, popen2, fcntl, fcntl, select
  5. import fileinput, re
  6.  
  7. import classes
  8. import interfaceclasses
  9. import objects
  10.  
  11.  
  12. '''CAPTURING UNIX APPS OUTPUT'''
  13. def makeNonBlocking(fd):
  14.     fl = fcntl.fcntl(fd, fcntl.F_GETFL)
  15.     try:
  16.         fcntl.fcntl(fd, fcntl.F_SETFL, fl | os.O_NDELAY)
  17.     except AttributeError:
  18.         fcntl.fcntl(fd, fcntl.F_SETFL, fl | fcntl.FNDELAY)
  19.  
  20.  
  21. def getCommandOutput(command):
  22.     child = popen2.Popen3(command, 1) # capture stdout and stderr from command
  23.     child.tochild.close()             # don't need to talk to child
  24.     outfile = child.fromchild 
  25.     outfd = outfile.fileno()
  26.     errfile = child.childerr
  27.     errfd = errfile.fileno()
  28.     makeNonBlocking(outfd)            # don't deadlock!
  29.     makeNonBlocking(errfd)
  30.     outdata = errdata = ''
  31.     outeof = erreof = 0
  32.     while 1:
  33.         ready = select.select([outfd,errfd],[],[]) # wait for input
  34.         if outfd in ready[0]:
  35.             outchunk = outfile.read()
  36.             if outchunk == '': outeof = 1
  37.             outdata = outdata + outchunk
  38.         if errfd in ready[0]:
  39.             errchunk = errfile.read()
  40.             if errchunk == '': erreof = 1
  41.             errdata = errdata + errchunk
  42.         if outeof and erreof: break
  43.         select.select([],[],[],.1) # give a little time for buffers to fill
  44.         err = child.wait()
  45.         if err != 0:
  46.             raise RuntimeError, '%s failed w/ exit code %d\n%s' % (command, err, errdata)
  47.     return outdata
  48.  
  49. def addmakefile32():
  50.     '''Add a makefile.cpu for 32bit recompiled kernels'''
  51.     kernelv = os.uname()[2]
  52.     makefilepath = '/usr/src/' + 'kernel-headers-' + kernelv + '/arch/i386/Makefile.cpu'
  53.     make32 = open(makefilepath, 'w')
  54.     make32.write('# CPU tuning section - shared with UML.\n\
  55. # Must change only cflags-y (or [yn]), not CFLAGS! That makes a difference for UML.\n\
  56. #-mtune exists since gcc 3.4\n\
  57. HAS_MTUNE    := $(call cc-option-yn, -mtune=i386)\n\
  58. ifeq ($(HAS_MTUNE),y)\n\
  59. tune        = $(call cc-option,-mtune=$(1),)\n\
  60. else\n\
  61. tune        = $(call cc-option,-mcpu=$(1),)\n\
  62. endif\n\
  63. \n\
  64. align := $(cc-option-align)\n\
  65. cflags-$(CONFIG_M386)        += -march=i386\n\
  66. cflags-$(CONFIG_M486)        += -march=i486\n\
  67. cflags-$(CONFIG_M586)        += -march=i586\n\
  68. cflags-$(CONFIG_M586TSC)    += -march=i586\n\
  69. cflags-$(CONFIG_M586MMX)    += -march=pentium-mmx\n\
  70. cflags-$(CONFIG_M686)        += -march=i686\n\
  71. cflags-$(CONFIG_MPENTIUMII)    += -march=i686 $(call tune,pentium2)\n\
  72. cflags-$(CONFIG_MPENTIUMIII)    += -march=i686 $(call tune,pentium3)\n\
  73. cflags-$(CONFIG_MPENTIUMM)    += -march=i686 $(call tune,pentium3)\n\
  74. cflags-$(CONFIG_MPENTIUM4)    += -march=i686 $(call tune,pentium4)\n\
  75. cflags-$(CONFIG_MK6)        += -march=k6\n\
  76. # Please note, that patches that add -march=athlon-xp and friends are pointless.\n\
  77. # They make zero difference whatsosever to performance at this time.\n\
  78. cflags-$(CONFIG_MK7)        += -march=athlon\n\
  79. cflags-$(CONFIG_MK8)        += $(call cc-option,-march=k8,-march=athlon)\n\
  80. cflags-$(CONFIG_MCRUSOE)    += -march=i686 $(align)-functions=0 $(align)-jumps=0 $(align)-loops=0\n\
  81. cflags-$(CONFIG_MEFFICEON)    += -march=i686 $(call tune,pentium3) $(align)-functions=0 $(align)-jumps=0 $(align)-loops=0\n\
  82. cflags-$(CONFIG_MWINCHIPC6)    += $(call cc-option,-march=winchip-c6,-march=i586)\n\
  83. cflags-$(CONFIG_MWINCHIP2)    += $(call cc-option,-march=winchip2,-march=i586)\n\
  84. cflags-$(CONFIG_MWINCHIP3D)    += $(call cc-option,-march=winchip2,-march=i586)\n\
  85. cflags-$(CONFIG_MCYRIXIII)    += $(call cc-option,-march=c3,-march=i486) $(align)-functions=0 $(align)-jumps=0 $(align)-loops=0\n\
  86. cflags-$(CONFIG_MVIAC3_2)    += $(call cc-option,-march=c3-2,-march=i686)\n\
  87. \n\
  88. # AMD Elan support\n\
  89. cflags-$(CONFIG_X86_ELAN)    += -march=i486\n\
  90. \n\
  91. # Geode GX1 support\n\
  92. cflags-$(CONFIG_MGEODEGX1)    += -march=pentium-mmx\n\
  93. \n\
  94. # add at the end to overwrite eventual tuning options from earlier\n\
  95. # cpu entries\n\
  96. cflags-$(CONFIG_X86_GENERIC)     += $(call tune,generic)\n')
  97.     make32.close()
  98.  
  99. def addmakefile64():
  100.     '''Add a makefile.cpu for 64bit recompiled kernels'''
  101.     kernelv = os.uname()[2]
  102.     makefilepath = '/usr/src/' + 'kernel-headers-' + kernelv + '/arch/i386/Makefile.cpu'
  103.     make64 = open(makefilepath, 'w')
  104.     make64.write('# CPU tuning section - shared with UML.\n\
  105. # Must change only cflags-y (or [yn]), not CFLAGS! That makes a difference for UML.\n\
  106. #-mtune exists since gcc 3.4, and some -mcpu flavors didn\'t exist in gcc 2.95.\n\
  107. HAS_MTUNE    := $(call cc-option-yn, -mtune=i386)\n\
  108. ifeq ($(HAS_MTUNE),y)\n\
  109. tune        = $(call cc-option,-mtune=$(1),)\n\
  110. else\n\
  111. tune        = $(call cc-option,-mcpu=$(1),)\n\
  112. endif\n\
  113. \n\
  114. align := $(cc-option-align)\n\
  115. cflags-$(CONFIG_M386)        += -march=i386\n\
  116. cflags-$(CONFIG_M486)        += -march=i486\n\
  117. cflags-$(CONFIG_M586)        += -march=i586\n\
  118. cflags-$(CONFIG_M586TSC)    += -march=i586\n\
  119. cflags-$(CONFIG_M586MMX)    += $(call cc-option,-march=pentium-mmx,-march=i586)\n\
  120. cflags-$(CONFIG_M686)        += -march=i686\n\
  121. cflags-$(CONFIG_MPENTIUMII)    += -march=i686 $(call tune,pentium2)\n\
  122. cflags-$(CONFIG_MPENTIUMIII)    += -march=i686 $(call tune,pentium3)\n\
  123. cflags-$(CONFIG_MPENTIUMM)    += -march=i686 $(call tune,pentium3)\n\
  124. cflags-$(CONFIG_MPENTIUM4)    += -march=i686 $(call tune,pentium4)\n\
  125. cflags-$(CONFIG_MK6)        += -march=k6\n\
  126. # Please note, that patches that add -march=athlon-xp and friends are pointless.\n\
  127. # They make zero difference whatsosever to performance at this time.\n\
  128. cflags-$(CONFIG_MK7)        += $(call cc-option,-march=athlon,-march=i686 $(align)-functions=4)\n\
  129. cflags-$(CONFIG_MK8)        += $(call cc-option,-march=k8,$(call cc-option,-march=athlon,-march=i686 $(align)-functions=4))\n\
  130. cflags-$(CONFIG_MCRUSOE)    += -march=i686 $(align)-functions=0 $(align)-jumps=0 $(align)-loops=0\n\
  131. cflags-$(CONFIG_MEFFICEON)    += -march=i686 $(call tune,pentium3) $(align)-functions=0 $(align)-jumps=0 $(align)-loops=0\n\
  132. cflags-$(CONFIG_MWINCHIPC6)    += $(call cc-option,-march=winchip-c6,-march=i586)\n\
  133. cflags-$(CONFIG_MWINCHIP2)    += $(call cc-option,-march=winchip2,-march=i586)\n\
  134. cflags-$(CONFIG_MWINCHIP3D)    += $(call cc-option,-march=winchip2,-march=i586)\n\
  135. cflags-$(CONFIG_MCYRIXIII)    += $(call cc-option,-march=c3,-march=i486) $(align)-functions=0 $(align)-jumps=0 $(align)-loops=0\n\
  136. cflags-$(CONFIG_MVIAC3_2)    += $(call cc-option,-march=c3-2,-march=i686)\n\
  137. \n\
  138. # AMD Elan support\n\
  139. cflags-$(CONFIG_X86_ELAN)    += -march=i486\n\
  140. \n\
  141. # Geode GX1 support\n\
  142. cflags-$(CONFIG_MGEODEGX1)        += $(call cc-option,-march=pentium-mmx,-march=i486)\n')
  143.     make64.close()
  144.  
  145. def rmmakefile():
  146.     '''Remove the makefile.cpu for recompiled kernels'''
  147.     kernelv = os.uname()[2]
  148.     makefilepath = '/usr/src/' + 'kernel-headers-' + kernelv + '/arch/i386/Makefile.cpu'
  149.     try:
  150.         os.remove(makefilepath)
  151.     except (OSError):
  152.         pass
  153.  
  154. #systemname = codename()
  155. #arca = architecture()
  156. '''Oggetto che si appoggia alla classe Specsdetect'''
  157.  
  158.  
  159.  
  160. def remove_nvidia_pkg():
  161.     os.system('sudo apt-get --assume-yes  --purge remove nvidia-glx nvidia-kernel-`uname -r` nvidia-glx-dev nvidia-kernel-source')
  162.     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')
  163.     os.system('sudo apt-get --assume-yes  --purge remove nvidia-glx-legacy nvidia-legacy-kernel-source nvidia-settings 1>&2')
  164.     os.system('sudo rm /usr/src/nvidia*.deb 1>&2')
  165.  
  166. def remove_ati_pkg():
  167.     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')
  168.     os.system('sudo rm /usr/src/fglrx*.deb 1>&2')
  169.  
  170. def dm_stop():
  171.     os.system('sudo /etc/init.d/gdm stop; sudo /etc/init.d/kdm stop')
  172.  
  173. def remove_deb():#for both ATI and Nvidia
  174.     os.system('sudo rm *.deb 1>&2')
  175.  
  176. def atiremovechanges():#removes files such as fglrx-installer_8.33.6-1_i386.changes
  177.     os.system('sudo rm *.changes 1>&2')
  178.     #os.system('sudo rm *.asc')
  179.  
  180. def nvremovechanges():#removes files such as fglrx-installer_8.33.6-1_i386.changes
  181.     os.system('sudo rm *.changes 1>&2')
  182.     os.system('sudo rm *.asc 1>&2')
  183.  
  184. def remove_debsrc():#for both ATI and Nvidia
  185.     os.system('sudo rm /usr/src/*.deb 1>&2')
  186.     os.system('sudo rm -R /usr/src/modules/nvidia-kernel 1>&2')
  187.     os.system('sudo rm -R /usr/src/modules/fglrx-kernel 1>&2')
  188.  
  189. def depmodules():
  190.     os.system('sudo depmod -a')
  191.  
  192. def restoremesa():
  193.     os.system('sudo apt-get -y install --reinstall libgl1-mesa-glx libglu1-mesa  libgl1-mesa-dri')
  194.  
  195. def pcrestart():
  196.     while 1:
  197.         xsrv = raw_input('Do you want to restart your computer now (Recommended)? (y/n) \ "y" is the default answer\n')
  198.         if xsrv.lower() == 'y' or xsrv.lower() == '' or xsrv.lower() == 'yes':
  199.             os.system('sudo reboot')
  200.             break
  201.             sys.exit()
  202.         elif xsrv.lower() == 'n':
  203.             print 'Remember to restart your computer manually'
  204.             break
  205.             sys.exit()
  206.         elif xsrv.lower() == 'no':
  207.             print 'Remember to restart your computer manually'
  208.             break
  209.             sys.exit()
  210.  
  211. def dependencies():
  212.     os.system('sudo apt-get --assume-yes  install linux-headers-`uname -r`')
  213.     os.system('sudo apt-get --assume-yes  install build-essential')
  214.     os.system('sudo apt-get --assume-yes  install xserver-xorg-dev')
  215.     os.system('sudo apt-get --assume-yes  install pkg-config dpkg-dev')
  216.     os.system('sudo apt-get --assume-yes  install gcc dpatch')
  217.     os.system('sudo apt-get --assume-yes  install module-assistant fakeroot dh-make debhelper debconf libstdc++5')
  218.  
  219. def blkresmanager():
  220.     os.system('sudo rm /lib/linux-restricted-modules/.nvidia*')
  221.  
  222. def xserverstart():
  223.     while 1:
  224.         xsrv = raw_input('Do you want to Start the Xserver now? (y/n) \ "y" is the default answer\n')
  225.         if xsrv.lower() == 'y' or xsrv.lower() == '' or xsrv.lower() == 'yes':
  226.             os.system('sudo /etc/init.d/gdm restart; sudo /etc/init.d/kdm restart')
  227.             sys.exit()
  228.             break
  229.         elif xsrv.lower() == 'n':
  230.             print 'Remember to start the xserver manually'
  231.             break
  232.             #sys.exit()
  233.         elif xsrv.lower() == 'no':
  234.             print 'Remember to start the xserver manually'
  235.             break
  236.             #sys.exit()
  237.  
  238.  
  239. def xorgset():
  240.     answer = raw_input('Do you want your xorg.conf to be automatically configured? (y/n) \ "y" is the default answer\n')
  241.     while 1:
  242.         if answer == 'y' or answer == '':
  243.             return 'y'
  244.         elif answer == 'n':
  245.             return 'n'
  246.  
  247.  
  248.  
  249.  
  250.  
  251.