Ejemplo n.º 1
0
				zf = ZipManager.Zip(fileName)

				### create or update fileName
				if os.path.exists(fileName):

					zf.Update(replace_files = [fn, python_path, image_path])
				else:
					zf.Create(add_files = [fn, python_path, image_path])

				os.remove(fn)

				## chemin absolu du repertoir contenant le fichier a exporter (str() pour eviter l'unicode)
				newExportPath = str(os.path.dirname(fileName))

				mainW = getTopLevelWindow()
				### si export dans un repertoir local on insert le chemin dans le fichier de config
				if not os.path.basename(DOMAIN_PATH) in newExportPath.split(os.sep):
					### mise a jour du fichier .devsimpy
					mainW.exportPathsList = eval(mainW.cfg.Read("exportPathsList"))
					if newExportPath not in mainW.exportPathsList:
						mainW.exportPathsList.append(str(newExportPath))
					mainW.cfg.Write("exportPathsList", str(eval("mainW.exportPathsList")))

				### si la librairie est deja charger dans l'environnement on met à jour ces modeles
				mainW.tree.UpdateDomain(newExportPath)

			except Exception, info:

				sys.stderr.write(_("Problem saving (during the zip handling): %s -- %s\n")%(str(fileName),info))
				return False
Ejemplo n.º 2
0
                zf = ZipManager.Zip(fileName)

                ### create or update fileName
                if os.path.exists(fileName):

                    zf.Update(replace_files=[fn, python_path, image_path])
                else:
                    zf.Create(add_files=[fn, python_path, image_path])

                os.remove(fn)

                ## chemin absolu du repertoir contenant le fichier a exporter (str() pour eviter l'unicode)
                newExportPath = str(os.path.dirname(fileName))

                mainW = getTopLevelWindow()
                ### si export dans un repertoir local on insert le chemin dans le fichier de config
                if not os.path.basename(DOMAIN_PATH) in newExportPath.split(
                        os.sep):
                    ### mise a jour du fichier .devsimpy
                    mainW.exportPathsList = eval(
                        mainW.cfg.Read("exportPathsList"))
                    if newExportPath not in mainW.exportPathsList:
                        mainW.exportPathsList.append(str(newExportPath))
                    mainW.cfg.Write("exportPathsList",
                                    str(eval("mainW.exportPathsList")))

                ### si la librairie est deja charger dans l'environnement on met à jour ces modeles
                mainW.tree.UpdateDomain(newExportPath)

            except Exception, info:
Ejemplo n.º 3
0
	def Save(self, obj_dumped, fileName = None):
		""" Function that save the codeblock on the disk.
		"""
		assert(fileName.endswith(tuple(DumpZipFile.ext)))

		### local copy of paths
		python_path = obj_dumped.python_path
		image_path = obj_dumped.image_path

		### Now, file paths are in the compressed file
		if os.path.isabs(python_path):
			path = os.path.join(fileName, os.path.basename(obj_dumped.python_path))
			if os.path.exists(path):
				obj_dumped.python_path = path

		if os.path.isabs(image_path):
			obj_dumped.image_path = os.path.join(fileName, os.path.basename(obj_dumped.image_path))

		obj_dumped.model_path = fileName

		### args is constructor args and we save these and not the current value
		if hasattr(obj_dumped, 'args'):
			obj_dumped.args = Components.GetArgs(Components.GetClass(obj_dumped.python_path))
		try:

			fn = 'DEVSimPyModel.dat'

			### dump attributes in fn file
			pickle.dump(	obj = PickledCollection(obj_dumped),
							file = open(fn, "wb"),
							protocol = 0)

		except Exception as info:

			sys.stderr.write(_("Problem saving (during the dump): %s -- %s\n")%(str(fileName),info))
			return False
		else:

			try:

				zf = ZipManager.Zip(fileName)

				### create or update fileName
				if os.path.exists(fileName):
					zf.Update(replace_files = [fn, python_path, image_path])
				else:
					zf.Create(add_files = [fn, python_path, image_path])

				os.remove(fn)

				## abs path of the directory that contains the file to export (str() to avoid unicode)
				newExportPath = str(os.path.dirname(fileName))

				mainW = getTopLevelWindow()
				### if export on local directory, we insert the path in the config file
				if not os.path.basename(DOMAIN_PATH) in newExportPath.split(os.sep):
					### update of .devsimpy config file
					mainW.exportPathsList = eval(mainW.cfg.Read("exportPathsList"))
					if newExportPath not in mainW.exportPathsList:
						mainW.exportPathsList.append(str(newExportPath))
					mainW.cfg.Write("exportPathsList", str(eval("mainW.exportPathsList")))

				### if lib is already in the lib tree, we update the tree
				mainW.tree.UpdateDomain(newExportPath)
				### to sort lib tree
				mainW.tree.SortChildren(mainW.tree.root)

			except Exception as info:
				sys.stderr.write(_("Problem saving (during the zip handling): %s -- %s\n")%(str(fileName),info))
				return False
			else:

				return True