PageRenderTime 54ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/Common/cpu-type.py

https://github.com/billy3321/lazyscripts_pool_debian_ubuntu
Python | 58 lines | 31 code | 9 blank | 18 comment | 15 complexity | 9abe8060e9162baf1351c460485683a4 MD5 | raw file
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. # Copyright (C) 2007 洪任諭 Hong Jen Yee (PCMan) <pcman.tw@gmail.com>
  4. # Released under GNU General Public License
  5. # This script is used to detect cpu type for swiftfox
  6. # print 'pentium3', 'pentium-m', 'pentium4', 'prescott',
  7. # 'athlon-xp', 'athlon64' to stdout
  8. # if the cpu is not supported, the program prints nothing
  9. #References:
  10. # http://www.sandpile.org/ia32/cpuid.htm
  11. # http://download.intel.com/design/processor/applnots/24161831.pdf
  12. # @maintaner '林哲瑋 Zhe-Wei Lin (billy3321,雨蒼) <bill3321 -AT- gmail.com>'
  13. # @author '洪任諭 Hong Jen Yee (PCMan) <pcman.tw@gmail.com>'
  14. # @license 'GPL'
  15. # @parent 'Networking/swiftfox'
  16. # @hide
  17. import sys, os, re
  18. f=open('/proc/cpuinfo', 'r')
  19. info=f.read()
  20. f.close()
  21. match=re.search('vendor_id[^\w]*(\w+)', info)
  22. if not match:
  23. exit(1)
  24. vender=match.group(1)
  25. match=re.search('cpu family[^\d]*(\d+)', info)
  26. if not match:
  27. exit(1)
  28. family=int(match.group(1))
  29. match=re.search('model[^\d]*(\d+)', info)
  30. if not match:
  31. exit(1)
  32. model=int(match.group(1))
  33. if vender=='GenuineIntel': # Intel
  34. if family==6: # Intel P6, P2, P3, PM, Core 2
  35. if model==9 or model==13: #PM
  36. print 'pentium-m'
  37. elif model>=7 and model<=11: # P3
  38. print 'pentium3'
  39. elif model>=14: # CD, C2D
  40. print 'prescott'
  41. elif family==15: # P4 series
  42. print 'pentium4'
  43. elif vender=='AuthenticAMD': # AMD
  44. if family==6: # AMD K7: Athlon, Duron
  45. print 'athlon-xp'
  46. elif family==15 or family==0: # extended family, treated as K8??
  47. # FIXME: I'm not sure if this is correct
  48. # FIXME: 64 bit environment is not currently supported
  49. print 'athlon-64-32bit'