"""
A helper file to check which parts of the code have documentation and which are lacking documentation.
-This because much of the Cura code is currently undocumented which needs to be improved.'
+This because much of the Cura code is currently undocumented which needs to be improved.
"""
import os
import traceback
moduleDocCount = 0
functionCount = 0
functionDocCount = 0
+ memberCount = 0
+ memberDocCount = 0
typeCount = 0
typeDocCount = 0
undocList = []
functionCount += 1
if inspect.getdoc(a):
functionDocCount += 1
- # else:
- # undocList.append('%s.%s' % (module.__name__, name))
+ else:
+ undocList.append('%s.%s' % (module.__name__, name))
elif type(a) is types.TypeType:
typeCount += 1
if inspect.getdoc(a):
if type(a2) is types.MethodType:
if hasattr(a.__bases__[0], name2):
continue
- functionCount += 1
+ memberCount += 1
if inspect.getdoc(a2):
- functionDocCount += 1
+ memberDocCount += 1
# else:
# undocList.append('%s.%s.%s' % (module.__name__, name, name2))
print '%d/%d modules have documentation.' % (moduleDocCount, len(moduleList))
- print '%d/%d functions have documentation.' % (functionDocCount, functionCount)
print '%d/%d types have documentation.' % (typeDocCount, typeCount)
- print '%.1f%% documented.' % (float(moduleDocCount + functionDocCount + typeDocCount) / float(len(moduleList) + functionCount + typeCount) * 100.0)
+ print '%d/%d functions have documentation.' % (functionDocCount, functionCount)
+ print '%d/%d member functions have documentation.' % (memberDocCount, memberCount)
+ print '%.1f%% documented.' % (float(moduleDocCount + functionDocCount + typeDocCount + memberDocCount) / float(len(moduleList) + functionCount + typeCount + memberCount) * 100.0)
print ''
print 'You might want to document:'
for n in xrange(0, 10):
## Profile functions
def getBasePath():
+ """
+ :return: The path in which the current configuration files are stored. This depends on the used OS.
+ """
if platform.system() == "Windows":
basePath = os.path.normpath(os.path.join(os.path.dirname(os.path.abspath(__file__)), ".."))
#If we have a frozen python install, we need to step out of the library.zip
return basePath
def getAlternativeBasePaths():
+ """
+ Search for alternative installations of Cura and their preference files. Used to load configuration from older versions of Cura.
+ """
paths = []
basePath = os.path.normpath(os.path.join(getBasePath(), '..'))
for subPath in os.listdir(basePath):
return paths
def getDefaultProfilePath():
+ """
+ :return: The default path where the currently used profile is stored and loaded on open and close of Cura.
+ """
return os.path.join(getBasePath(), 'current_profile.ini')
def loadProfile(filename, allMachines = False):
+ """
+ Read a profile file as active profile settings.
+ :param filename: The ini filename to save the profile in.
+ :param allMachines: When False only the current active profile is saved. If True all profiles for all machines are saved.
+ """
global settingsList
- #Read a configuration file as global config
profileParser = ConfigParser.ConfigParser()
try:
profileParser.read(filename)
set.setValue(unicode(profileParser.get(section, set.getName()), 'utf-8', 'replace'))
def saveProfile(filename, allMachines = False):
+ """
+ Save the current profile to an ini file.
+ :param filename: The ini filename to save the profile in.
+ :param allMachines: When False only the current active profile is saved. If True all profiles for all machines are saved.
+ """
global settingsList
- #Save the current profile to an ini file
profileParser = ConfigParser.ConfigParser()
if allMachines:
for set in settingsList:
profileParser.write(open(filename, 'w'))
def resetProfile():
- #Read a configuration file as global config
+ """ Reset the profile for the current machine to default. """
global settingsList
for set in settingsList:
if not set.isProfile():
putProfileSetting('retraction_enable', 'True')
def setProfileFromString(options):
+ """
+ Parse an encoded string which has all the profile settings stored inside of it.
+ Used in combination with getProfileString to ease sharing of profiles.
+ """
options = base64.b64decode(options)
options = zlib.decompress(options)
(profileOpts, alt) = options.split('\f', 1)
settingsDictionary[key].setValue(value)
def getProfileString():
+ """
+ Get an encoded string which contains all profile settings.
+ Used in combination with setProfileFromString to share settings in files, forums or other text based ways.
+ """
p = []
alt = []
global settingsList
return '\n'.join(lines)
def getPreferencesString():
+ """
+ :return: An encoded string which contains all the current preferences.
+ """
p = []
global settingsList
for set in settingsList:
def getProfileSetting(name):
+ """
+ Get the value of an profile setting.
+ :param name: Name of the setting to retrieve.
+ :return: Value of the current setting.
+ """
if name in tempOverride:
return tempOverride[name]
global settingsDictionary
return 0.0
def putProfileSetting(name, value):
- #Check if we have a configuration file loaded, else load the default.
+ """ Store a certain value in a profile setting. """
global settingsDictionary
if name in settingsDictionary and settingsDictionary[name].isProfile():
settingsDictionary[name].setValue(value)
def isProfileSetting(name):
+ """ Check if a certain key name is actually a profile value. """
global settingsDictionary
if name in settingsDictionary and settingsDictionary[name].isProfile():
return True
## Preferences functions
def getPreferencePath():
+ """
+ :return: The full path of the preference ini file.
+ """
return os.path.join(getBasePath(), 'preferences.ini')
def getPreferenceFloat(name):
+ """
+ Get the float value of a preference, returns 0.0 if the preference is not a invalid float
+ """
try:
setting = getPreference(name).replace(',', '.')
return float(eval(setting, {}, {}))
return 0.0
def getPreferenceColour(name):
+ """
+ Get a preference setting value as a color array. The color is stored as #RRGGBB hex string in the setting.
+ """
colorString = getPreference(name)
return [float(int(colorString[1:3], 16)) / 255, float(int(colorString[3:5], 16)) / 255, float(int(colorString[5:7], 16)) / 255, 1.0]
def loadPreferences(filename):
+ """
+ Read a configuration file as global config
+ """
global settingsList
- #Read a configuration file as global config
profileParser = ConfigParser.ConfigParser()
try:
profileParser.read(filename)