chiark / gitweb /
Move SF into its own directory, to seperate SF and Cura. Rename newui to gui.
[cura.git] / Cura / cura_sf / fabmetheus_utilities / fabmetheus_tools / prepare.py
1 """
2 Prepare is a script to remove the generated files, run wikifier, and finally zip the package.
3
4 """
5
6 from __future__ import absolute_import
7 #Init has to be imported first because it has code to workaround the python bug where relative imports don't work if the module is imported as a main module.
8 import __init__
9
10 from fabmetheus_utilities import archive
11 from fabmetheus_utilities.fabmetheus_tools import wikifier
12 import os
13
14
15 __author__ = 'Enrique Perez (perez_enrique@yahoo.com)'
16 __date__ = '$Date: 2008/21/04 $'
17 __license__ = 'GNU Affero General Public License http://www.gnu.org/licenses/agpl.html'
18
19
20 def prepareWikify():
21         'Remove generated files, then wikify the file comments.'
22         removeGeneratedFiles()
23         wikifier.main()
24         removeZip()
25
26 def removeCSVFile(csvFilePath):
27         'Remove csv file.'
28         if 'alterations' in csvFilePath and 'example_' not in csvFilePath:
29                 os.remove(csvFilePath)
30                 print('removeGeneratedFiles deleted ' + csvFilePath)
31
32 def removeGcodeFile(gcodeFilePath):
33         'Remove gcode file.'
34         if 'alterations' not in gcodeFilePath:
35                 os.remove(gcodeFilePath)
36                 print('removeGeneratedFiles deleted ' + gcodeFilePath)
37                 return
38         if 'example_' not in gcodeFilePath:
39                 os.remove(gcodeFilePath)
40                 print('removeGeneratedFiles deleted ' + gcodeFilePath)
41
42 def removeGeneratedFiles():
43         'Remove generated files.'
44         csvFilePaths = archive.getFilesWithFileTypesWithoutWordsRecursively(['csv'])
45         for csvFilePath in csvFilePaths:
46                 removeCSVFile(csvFilePath)
47         gcodeFilePaths = archive.getFilesWithFileTypesWithoutWordsRecursively(['gcode'])
48         for gcodeFilePath in gcodeFilePaths:
49                 removeGcodeFile(gcodeFilePath)
50         svgFilePaths = archive.getFilesWithFileTypesWithoutWordsRecursively(['svg'])
51         for svgFilePath in svgFilePaths:
52                 removeSVGFile(svgFilePath)
53         xmlFilePaths = archive.getFilesWithFileTypesWithoutWordsRecursively(['xml'])
54         for xmlFilePath in xmlFilePaths:
55                 removeXMLFile(xmlFilePath)
56         archive.removeBackupFilesByTypes(['gcode', 'svg', 'xml'])
57
58 def removeSVGFile(svgFilePath):
59         'Remove svg file.'
60         if archive.getEndsWithList(svgFilePath, ['_bottom.svg', '_carve.svg', '_chop.svg', '_cleave.svg', '_scale.svg', '_vectorwrite.svg']):
61                 os.remove(svgFilePath)
62                 print('removeGeneratedFiles deleted ' + svgFilePath)
63
64 def removeXMLFile(xmlFilePath):
65         'Remove xml file.'
66         if archive.getEndsWithList(xmlFilePath, ['_interpret.xml']):
67                 os.remove(xmlFilePath)
68                 print('removeGeneratedFiles deleted ' + xmlFilePath)
69
70 def removeZip():
71         'Remove the zip file, then generate a new one.zip -r reprap_python_beanshell * -x \*.pyc \*~'
72         zipName = 'reprap_python_beanshell'
73         zipNameExtension = zipName + '.zip'
74         if zipNameExtension in os.listdir(os.getcwd()):
75                 os.remove(zipNameExtension)
76         shellCommand = 'zip -r %s * -x \*.pyc \*~' % zipName
77         if os.system(shellCommand) != 0:
78                 print('Failed to execute the following command in removeZip in prepare.')
79                 print(shellCommand)
80
81 def main():
82         'Run main function.'
83         prepareWikify()
84
85 if __name__ == "__main__":
86         main()