filmed.py :  » Business-Application » ThanCad » thancad-0.0.9 » p_gfil » Python Open Source

Home
Python Open Source
1.3.1.2 Python
2.Ajax
3.Aspect Oriented
4.Blog
5.Build
6.Business Application
7.Chart Report
8.Content Management Systems
9.Cryptographic
10.Database
11.Development
12.Editor
13.Email
14.ERP
15.Game 2D 3D
16.GIS
17.GUI
18.IDE
19.Installer
20.IRC
21.Issue Tracker
22.Language Interface
23.Log
24.Math
25.Media Sound Audio
26.Mobile
27.Network
28.Parser
29.PDF
30.Project Management
31.RSS
32.Search
33.Security
34.Template Engines
35.Test
36.UML
37.USB Serial
38.Web Frameworks
39.Web Server
40.Web Services
41.Web Unit
42.Wiki
43.Windows
44.XML
Python Open Source » Business Application » ThanCad 
ThanCad » thancad 0.0.9 » p_gfil » filmed.py
# -*- coding: iso-8859-7 -*-

import sys
from p_ggen import path,prg
fw = None
FILNAMMED = "mediate.tmp"
ERRORTEXT = "***ERROR***"
exParams = []

#===========================================================================

def openFileWrmed(nPro, pro):
      "Save information into the intermediate file."
      import openfile

#-----Open intermediate file (mediate.tmp)

      global fw
      fw = None
      try: fw = open(FILNAMMED, "w")               # Truncates the file
      except IOError: return                       # Can not be accessed

#-----Write error message. In case the program stops abnormally, this is
#     correct. If it stops normaly, this error message will be deleted.

      fw.write(ERRORTEXT+"\n")
      fw.write(openfile.descp+"\n")                # Description of the program

#-----Save prefix for next programs in the same batch file

      fw.write("%d\n" % nPro)
      for i in xrange(nPro): fw.write(pro[i]+"\n")
      openfile.openFilePar(2, fw)                  # Write user parameters to file mediate.tmp
      fw.write(ERRORTEXT+"\n")                     # Marks the end of user parameters  

#-----Close and reopen in order to commit written lines

      fw.close(); fw = None
      fw = open(FILNAMMED, "a")                    # open file for append

#===========================================================================

def openFileMed(pro, nPro):
      """This Sr reads prefix from intermediate file."

      nPro : The number of prefixes the program requires
      nProm: The number of prefixes in mediate.tmp (nPro<=nProm)
      """
      import openfile
      try: fr = open(FILNAMMED, "r")
      except IOError: return None
      dline = fr.readline()
      if dline == "": fr.close(); return None    # End of file

#-----check if previous program in batch file finished abnormally

      dline = dline.strip()
      if dline == ERRORTEXT:
          openfile.descp = fr.readline().strip()
          if openfile.descp == "": openfile.descp = openfile.DLNODESC #No description for prev.program)
          prg("File %s: %s\n     %s" % (FILNAMMED, openfile.DLERRPRV, openfile.descp))

          sys.exit(1)

#-----Read number of prefixes

      try: nProm = int(fr.readline().strip())
      except: fr.close(); return None
      if nProm < nPro or nProm > 2: fr.close(); return None

#-----Read prefixes from file FILNAMMED

      pro = [None, None]
      for i in xrange(nProm):
          pro[i] = fr.readline()
    if pro[i] == "": fr.close(); return None
    pro[i] = path(pro[i].strip())
          if pro[i] == "":
              if openfile.prothem1Opt(i, ic) == 0: fr.close(); return None # Prefix not optional
          pro[i] = pro[i].parent / pro[i].basename

#-----Read any program parameters

      prg(' * '+openfile.descp)
      prg(' %s %s.' % (openfile.DLGETPRE, FILNAMMED))
      openfile.openFilePar(1, fr)     #   

#-----Read any extra parameters for following programs

      global exParams
      exParams = fr.readlines()
      fr.close()
      return nProm

#===========================================================================

def errMedFile1():
      "This sr reports error into file mediate.tmp."
      global fw
      if fw == None:
#---------If mediate.tmp was not open, then it could not be accessed.
#         Since the calling program ended abnormally, try to write
#         an error message to it now.
          try: fw = open(FILNAMMED, "w")          # Trucates existing file
          except: sys.exit(1)                     # Could not open it again
          fw.write("\n".join((ERRORTEXT, openfile.descp, ERRORTEXT)))
      fw.close(); fw = None

#===========================================================================

def okMedFile1(): 
      "This sr reports OK into file mediate.tmp."
      import openfile
      global fw
      if fw == None:

#---------If mediate.tmp was not open, then it could not be accessed.
#         Since the calling program ended normally, we try to delete file
#         mediate.tmp. After that we can do nothing, since we do not have
#         the information that should be written to mediate.tmp.

          try: path(FILNAMMED).remove()
          except Exception, why: print why; pass
    return
      if not openfile.fylPro:

#---------Intemediate file is not needed by the following programs. Delete it.

          fw.close()
          try: path(FILNAMMED).remove()
          except Exception, why: print why; pass
    return

#----Ignore the first 2 lines which contain the error sentinel

      fw.close()
      fr = open(FILNAMMED, "r")
      dlines = fr.readlines()
      fr.close()
      del dlines[:2]

#-----Open mediate.tmp again and write the lines read

      fw = open(FILNAMMED, "w")
      fw.writelines(dlines)

#-----Write any extra parameters for following programs

      fw.write("\n".join(exParams))
      fw.close(); fw = None
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.