Example #1
0
    def write(self, theText):
        '''
		writes the context of the configurator window to a file
		returns ERROR constant (NOERROR if successful)
		if the parser made any alterations the editedByParser property will be
		set to True
		'''
        self.editedByParser = False
        theText = unicode(theText)
        s = String.Split(theText, '\n')
        # s = str.split(str(theText),'\n')
        tmp = str('')
        errlines = 0
        myParser = parser()
        pre = ''

        s = [line for line in s if str.Trim(line) <> '']

        for line in s:
            myParser.validate(unicode(line))
            if myParser.err:
                pre = myParser.commentedLine(line)
                errlines += 1
                self.editedByParser = True
            else:
                pre = unicode(line)
            tmp += '%s%s' % (pre, System.Environment.NewLine)
        if len(tmp) > 0:
            try:
                File.WriteAllText(self.theFile, tmp)
            except Exception, err:
                return self.ERRORSAVEFILE
Example #2
0
def WriteKey(iniFilePath, strKey, strValue):
    dictKeys = LoadFile(iniFilePath)
    dictKeys[strKey] = strValue
    strFile = ""
    for item in dictKeys:
        strFile += item + ' = ' + dictKeys[item] + System.Environment.NewLine
    File.WriteAllText(iniFilePath, strFile)
    pass
def GetJobInstanceLog():
    """
    <Script>
    <Author>LPE</Author>
    <Description>Please enter script description here</Description>
    </Script>
    """

    # get id of the current instance
    id = JobContext.Instance.JobInstanceID
    print id.ToString()

    # get the currently logged data from the database
    jobMgr = app.Modules.Get("Job Manager")
    ji = jobMgr.JobInstanceList.Fetch(id)

    # output it

    # print ji.Log
    File.WriteAllText(r"c:\temp\ji_" + id.ToString() + ".xml", ji.Log)
Example #4
0
def write_json(metadata, jsonfile='Metadata.json', savepath=r'C:\Temp'):
    jsonfile = Path.Combine(savepath, jsonfile)
    js = JavaScriptSerializer().Serialize(metadata)
    File.WriteAllText(jsonfile, js)

    return jsonfile
 def SaveTestModeData(self, testModeData):
     testModeData = json_util.SerializeObject(testModeData,
                                              prettyPrint=True)
     testModeDataFilePath = self.GetTestModeDataFilePath()
     File.WriteAllText(testModeDataFilePath, testModeData)
     return
items = xmldoc.SelectNodes('Model')
for item in items:
    # get the version attribute
    version_number = item.GetAttribute('Version')
    print('Old version : ', version_number)
    try:
        # set the new version number
        item.SetAttribute('Version', newversion)
        print('Set the Modelversion to: ', newversion)
    except:
        # stop the script execution completely
        sys.exit('Could not update the Version number.')

# get the raw XML and write it to disk
rawXML = xmldoc.OuterXml
File.WriteAllText(modelxml, rawXML)

# zip the folder with the updated XML file
print('Started zipping ...')
zipfile = zipfolder(tempdir, tempdir)
change_dir_sep(zipfile)
print('Finished zipping: ', tempdir)

# rename the new zipfile to *.czmodel
print('Rename *.zip back to *.czmodel')
File.Move(zipfile, Path.ChangeExtension(zipfile, '.czmodel'))

# remover the temp folder from unzipping afterwards
if remove_tmpfolder:
    print('Deleting tempory folder : ', tempdir)
    Directory.Delete(tempdir, True)