Advertisement
clockworkpc

Generator of Python and BASH script generators

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