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
8 from fabmetheus_utilities import archive
9 from fabmetheus_utilities import settings
10 from skeinforge_application.skeinforge_utilities import skeinforge_profile
13 __author__ = 'Enrique Perez (perez_enrique@yahoo.com)'
14 __date__ = '$Date: 2008/21/04 $'
15 __license__ = 'GNU Affero General Public License http://www.gnu.org/licenses/agpl.html'
18 def getFileOrDirectoryTypes( fileName, fileTypes, wasCancelled ):
19 "Get the gcode files in the directory the file is in if directory setting is true. Otherwise, return the file in a list."
20 if isEmptyOrCancelled( fileName, wasCancelled ):
22 if isDirectorySetting():
23 return archive.getFilesWithFileTypesWithoutWords( fileTypes, [], fileName )
26 def getFileOrDirectoryTypesUnmodifiedGcode(fileName, fileTypes, wasCancelled):
27 "Get the gcode files in the directory the file is in if directory setting is true. Otherwise, return the file in a list."
28 if isEmptyOrCancelled(fileName, wasCancelled):
30 if isDirectorySetting():
31 return archive.getFilesWithFileTypesWithoutWords(fileTypes, [], fileName)
34 def getFileOrGcodeDirectory( fileName, wasCancelled, words = [] ):
35 "Get the gcode files in the directory the file is in if directory setting is true. Otherwise, return the file in a list."
36 if isEmptyOrCancelled( fileName, wasCancelled ):
38 if isDirectorySetting():
39 dotIndex = fileName.rfind('.')
41 print('The file name should have a suffix, like myfile.xml.')
42 print('Since the file name does not have a suffix, nothing will be done')
43 suffix = fileName[ dotIndex + 1 : ]
44 return archive.getFilesWithFileTypeWithoutWords( suffix, words, fileName )
47 def getNewRepository():
49 return PolyfileRepository()
51 def isDirectorySetting():
52 "Determine if the directory setting is true."
53 return settings.getReadRepository( PolyfileRepository() ).directorySetting.value
55 def isEmptyOrCancelled( fileName, wasCancelled ):
56 "Determine if the fileName is empty or the dialog was cancelled."
57 return str(fileName) == '' or str(fileName) == '()' or wasCancelled
60 class PolyfileRepository(object):
61 "A class to handle the polyfile settings."
63 "Set the default settings, execute title & settings fileName."
64 skeinforge_profile.addListsToCraftTypeRepository('skeinforge_application.skeinforge_utilities.skeinforge_polyfile.html', self)
65 self.directoryOrFileChoiceLabel = settings.LabelDisplay().getFromName('Directory or File Choice: ', self )
66 directoryLatentStringVar = settings.LatentStringVar()
67 self.directorySetting = settings.Radio().getFromRadio( directoryLatentStringVar, 'Execute All Unmodified Files in a Directory', self, False )
68 self.fileSetting = settings.Radio().getFromRadio( directoryLatentStringVar, 'Execute File', self, True )