2 Polyfile is a script to choose whether the skeinforge toolchain will operate on one file or all the files in a directory.
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.
10 from fabmetheus_utilities import archive
11 from fabmetheus_utilities import settings
12 from skeinforge_application.skeinforge_utilities import skeinforge_profile
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'
20 def getFileOrDirectoryTypes( fileName, fileTypes, wasCancelled ):
21 "Get the gcode files in the directory the file is in if directory setting is true. Otherwise, return the file in a list."
22 if isEmptyOrCancelled( fileName, wasCancelled ):
24 if isDirectorySetting():
25 return archive.getFilesWithFileTypesWithoutWords( fileTypes, [], fileName )
28 def getFileOrDirectoryTypesUnmodifiedGcode(fileName, fileTypes, wasCancelled):
29 "Get the gcode files in the directory the file is in if directory setting is true. Otherwise, return the file in a list."
30 if isEmptyOrCancelled(fileName, wasCancelled):
32 if isDirectorySetting():
33 return archive.getFilesWithFileTypesWithoutWords(fileTypes, [], fileName)
36 def getFileOrGcodeDirectory( fileName, wasCancelled, words = [] ):
37 "Get the gcode files in the directory the file is in if directory setting is true. Otherwise, return the file in a list."
38 if isEmptyOrCancelled( fileName, wasCancelled ):
40 if isDirectorySetting():
41 dotIndex = fileName.rfind('.')
43 print('The file name should have a suffix, like myfile.xml.')
44 print('Since the file name does not have a suffix, nothing will be done')
45 suffix = fileName[ dotIndex + 1 : ]
46 return archive.getFilesWithFileTypeWithoutWords( suffix, words, fileName )
49 def getNewRepository():
51 return PolyfileRepository()
53 def isDirectorySetting():
54 "Determine if the directory setting is true."
55 return settings.getReadRepository( PolyfileRepository() ).directorySetting.value
57 def isEmptyOrCancelled( fileName, wasCancelled ):
58 "Determine if the fileName is empty or the dialog was cancelled."
59 return str(fileName) == '' or str(fileName) == '()' or wasCancelled
62 class PolyfileRepository:
63 "A class to handle the polyfile settings."
65 "Set the default settings, execute title & settings fileName."
66 skeinforge_profile.addListsToCraftTypeRepository('skeinforge_application.skeinforge_utilities.skeinforge_polyfile.html', self)
67 self.directoryOrFileChoiceLabel = settings.LabelDisplay().getFromName('Directory or File Choice: ', self )
68 directoryLatentStringVar = settings.LatentStringVar()
69 self.directorySetting = settings.Radio().getFromRadio( directoryLatentStringVar, 'Execute All Unmodified Files in a Directory', self, False )
70 self.fileSetting = settings.Radio().getFromRadio( directoryLatentStringVar, 'Execute File', self, True )