fork(1) download
  1. #!/usr/bin/env python
  2.  
  3. # Import the required modules
  4.  
  5. # For executing system commands nd getting uid
  6.  
  7. import os
  8.  
  9. # For comparing files to get the firmware in use
  10.  
  11. import filecmp
  12.  
  13. # For the sys.exit function
  14.  
  15. import sys
  16.  
  17. # Check we have root permissions
  18.  
  19. if os.geteuid() != 0:
  20. print ("You need root privilages to use this tool - exiting...")
  21. sys.exit()
  22.  
  23. # We would have exited by now if we weren't root, so carry on
  24.  
  25. # Ceate a dictionary with the RAM use in Linux as the key and the
  26. # firmware file path as the value
  27.  
  28. firmwares = {128:"/boot/arm128_start.elf", 192:"/boot/arm192_start.elf",
  29. 244:"/boot/arm224_start.elf"}
  30.  
  31. # Constants for easier reading when getting a key or value from
  32. # an item in the dictionary
  33.  
  34. Key = 0
  35. Path = 1
  36.  
  37. # Work out which firmware is currently in use by comparing each file
  38. # in the dictionary with start.elf
  39.  
  40. for firmware in firmwares.items():
  41. result = filecmp("/boot/start.elf", firmware[Path], False)
  42.  
  43. # When we find the correct file
  44.  
  45. if result == True:
  46.  
  47. # Work out the RAM allocation of Linux and GPU
  48.  
  49. currentLinux = firmware[Key]
  50. currentGPU = 256 - currentLinux
  51. print (str(currentLinux) +"MB of ram is currently being used by Linux.")
  52. print (str(currentGPU) +"MB of ram is currently being used by the GPU.")
  53.  
  54. # Display a menu
  55.  
  56. print("\nWhat would you like to do?\n")
  57.  
  58. # Print an option for each firmware
  59.  
  60. count = 1
  61. for firmware in firmwares.items():
  62.  
  63. # Work out the RAM allocation of Linux and the GPU
  64.  
  65. firmwareLinux = firmware[Key]
  66. firmwareGPU = 256 - firmwareLinux
  67. print (str(count) + ". Allocate " + str(firmwareLinux) + "MB of RAM to Linux leaving " + str(firmwareGPU) + "MB of RAM for the GPU.")
  68. count += 1
  69.  
  70. # Add an exit option
  71.  
  72. print (str(count) + ".Exit.")
  73.  
  74. # Loop to make sure we get a valid reply
  75.  
  76. validOption = False
  77. while validOption == False:
  78. option = raw_input("\nPlease select an option from above: ")
  79.  
  80. # Try to convert our option to an integer and set isInt either
  81. # way... we don't want to crash on a bad option
  82.  
  83. try:
  84. option = int(option)
  85. isInt = True
  86. except ValueError:
  87. isInt = False
  88. if isInt == True:
  89. if option <= count:
  90.  
  91. # Stop the while loop
  92.  
  93. validOption = True
  94.  
  95. # Deal with our options (only in the range of the count as we
  96. # don't need to handle exit)
  97.  
  98. if option < count:
  99. # Work out the RAM allocation of Linux and GPU
  100. newFirmware = firmwares.keys()[option - 1]
  101. newGPU = 256 - newFirmware
  102. print ("\nUsing the firmware which allocates " + str(newFirmware)
  103. + "MB of RAM to Linux and " + str(newGPU) + "MB of RAM to the GPU...")
  104.  
  105. # Run the cp command with appropriate values
  106. copyResult = os.system("cp " + firmwares[newFirmware] + " " + "/boot/start.elf")
  107. if copyResult != 0:
  108. print (\nThere was an error while copying the requested firmware!") print ("Exiting...")
  109. else:
  110. print ("\nThe requested firmware was copied
  111. successfully.\n")
  112. # Loop to make sure we have a proper response
  113. # for restarting
  114. restartLoop = False
  115. while restartLoop == False:
  116. restartResult = raw_input("The device
  117. needs to restart " "before the changes
  118. take place. Would you like to do this now?
  119. (y/n) ")
  120. if restartResult == "y":
  121. # Stop the while loop
  122. restartLoop = True # We need to
  123. # restart print("The system is going
  124. down for a restart...")
  125.  
  126. os.system("shutdown -r now")
  127. elif restartResult == "n":
  128. # Stop the while loop
  129. restartLoop = True
  130. # We just need to exit (by doing
  131. nothing) print ("\nExiting...")# your code goes here
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Traceback (most recent call last):
  File "/usr/lib/python3.4/py_compile.py", line 124, in compile
    _optimize=optimize)
  File "<frozen importlib._bootstrap>", line 1532, in source_to_code
  File "<frozen importlib._bootstrap>", line 321, in _call_with_frames_removed
  File "./prog.py", line 108
    print (\nThere was an error while copying the requested firmware!") print ("Exiting...")
        ^
IndentationError: expected an indented block

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/usr/lib/python3.4/py_compile.py", line 128, in compile
    raise py_exc
py_compile.PyCompileError: Sorry: IndentationError: expected an indented block (prog.py, line 108)
stdout
Standard output is empty