Advertisement
clockworkpc

Bash and Python Script Generators

Mar 13th, 2012
198
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.75 KB | None | 0 0
  1. #!/usr/bin/python
  2.  
  3. import os
  4.  
  5. bin_path_name = os.getenv("HOME")+"/bin/"
  6. usr_bin_path_name = "/usr/local/bin/"
  7.  
  8. print bin_path_name
  9.  
  10. if not os.path.isdir == bin_path_name:
  11.     os.mkdir(bin_path_name)
  12. else:
  13.     print bin_path_name
  14.  
  15. #BASH Generator
  16.  
  17. bashGen = '''#!/bin/bash
  18. #cpcbash.sh
  19.  
  20. # Released under a GPLv3 Licence by Clockwork PC 2012
  21. # www.clockworkpc.com.au
  22.  
  23. # You are entitled to the following four freedoms:
  24. # Freedom 0: To run this program for any purpose
  25. # Freedom 1: To study how this program works and change it to make it do what you wish
  26. # Freedom 2: To redistribute copies so you can help your neighbour
  27. # Freedom 3: To distribute copies of your modified version to others
  28.  
  29. echo "What do you want to call your BASH script?"
  30. read RESPONSE
  31.  
  32. echo "#!/bin/bash" | tee $RESPONSE.sh
  33. echo "#Filename:$RESPONSE.sh" | tee -a $RESPONSE.sh
  34. echo "#Released under a GPLv3 Licence by Clockwork PC" | tee -a $RESPONSE.sh
  35.  
  36. chmod +x $RESPONSE.sh
  37.  
  38. sudo ln -s ~/bin/$RESPONSE.sh /usr/local/bin/$RESPONSE.sh
  39. sudo chmod +x /usr/local/bin/$RESPONSE.sh
  40.  
  41. gedit $RESPONSE.sh
  42.  
  43. '''
  44.  
  45. pythonGen = '''#!/usr/bin/python
  46.  
  47. # Released under a GPLv3 Licence by Clockwork PC 2012
  48. # www.clockworkpc.com.au
  49.  
  50. # You are entitled to the following four freedoms:
  51. # Freedom 0: To run this program for any purpose
  52. # Freedom 1: To study how this program works and change it to make it do what you wish
  53. # Freedom 2: To redistribute copies so you can help your neighbour
  54. # Freedom 3: To distribute copies of your modified version to others
  55.  
  56. import os
  57.  
  58. filename=raw_input("What do you want to call your Python file? ")
  59.  
  60. folder = os.getenv("HOME")+"/bin/"
  61. pythonfile = folder + filename + ".py"
  62.  
  63. print folder
  64. print pythonfile
  65.  
  66. os.system('echo "#!/usr/bin/python" | tee ' + pythonfile)
  67.  
  68. f = open(pythonfile, "a")
  69.  
  70. f.write("#"+pythonfile+"""
  71.  
  72. # Released under a GPLv3 Licence by Clockwork PC 2012
  73. # www.clockworkpc.com.au
  74.  
  75. # You are entitled to the following four freedoms:
  76. # Freedom 0: To run this program for any purpose
  77. # Freedom 1: To study how this program works and change it to make it do what you wish
  78. # Freedom 2: To redistribute copies so you can help your neighbour
  79. # Freedom 3: To distribute copies of your modified version to others
  80. """)
  81. f.close()
  82.  
  83. os.system("chmod -v +x " + pythonfile)
  84. os.system("sudo ln -sv " + pythonfile + " /" + "usr/local/bin/" + filename + ".py")
  85. os.system("gedit " + pythonfile)
  86. os.system("xcowsay 'Your Python script is ready!'")
  87. '''
  88.  
  89. bashGenName = "cpcbash.sh"
  90. bashGenFile = bin_path_name + bashGenName
  91. bashGenUsr = usr_bin_path_name+bashGenName
  92.  
  93. pythonGenName = "cpcpython.py"
  94. pythonGenFile = bin_path_name + pythonGenName
  95. pythonGenUsr = usr_bin_path_name+pythonGenName
  96.  
  97. rmScriptsName = "rmscripts.sh"
  98. rmScriptsFile = bin_path_name + rmScriptsName
  99. rmScriptsUsr = usr_bin_path_name+rmScriptsName
  100.  
  101. #Remove scripts and symlinks
  102.  
  103. rmScripts = "#!/bin/bash"+"""
  104. """+"sudo rm"+ " " + bashGenFile + " " + bashGenUsr + " " + pythonGenFile + " " + pythonGenUsr
  105.  
  106. print bashGenFile
  107. print pythonGenFile
  108. print rmScriptsFile
  109.  
  110. os.system("touch " + bashGenFile)
  111. os.system("touch " + pythonGenFile)
  112. os.system("touch " + rmScriptsFile)
  113.  
  114. os.system("sudo apt-get install xcowsay && xcowsay how do you like them apples")
  115.  
  116. f = open(bashGenFile, "a")
  117. f.write(bashGen)
  118. os.system ("sudo ln -s " + bashGenFile + " " + bashGenUsr)f.close()
  119. os.system("chmod +x " + bashGenFile)
  120.  
  121. g = open(pythonGenFile, "a")
  122. g.write(pythonGen)
  123. g.close()
  124. os.system("chmod +x " + pythonGenFile)
  125. os.system ("sudo ln -s " + pythonGenFile + " " + pythonGenUsr)
  126.  
  127. h = open(rmScriptsFile, "a")
  128. h.write(rmScripts)
  129. h.close()
  130. os.system("chmod +x " + rmScripts)
  131. os.system ("sudo ln -s " + rmScriptsFile + " " + rmScriptsUsr)
  132.  
  133. os.system("xcowsay Your scripts are ready")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement