put2pdf.py :  » UML » Python-UML-Tool » pyut-1.4.0 » src » 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 » UML » Python UML Tool 
Python UML Tool » pyut 1.4.0 » src » put2pdf.py
#!/usr/bin/env python
# -*- coding: UTF-8 -*-
__version__ = "$Revision: 1.3 $"
__author__ = "EI5, eivd, Group Burgbacher - Waelti"
__date__ = "2001-11-14"
#import pychecker.checker   #Uncomment this to test PyUt
import os, sys

exePath = None              # the pyut's path
userPath = os.getcwd()      # where the user launched pyut from


#>----------------------------------------------------------------------------
def getExePath():
    """
    Return the absolute path currently used

    @return string the path
    @since 1.5.2.19
    @author C.Dutoit
    """
    import sys, os
    print sys.argv[0]
    if sys.argv[0][0]==os.sep or sys.argv[0].find(":")>0:
        # Absolute path
        exePath = sys.argv[0]
    else: 
        # Relative path
        exePath = os.getcwd() + os.sep + sys.argv[0]
    return os.path.split(exePath)[0]
    


#>----------------------------------------------------------------------------
def goToPyutDirectory():
    """
    Go to the pyut directory

    @since 1.5.2.19
    @author C.Dutoit
    """
    import sys, os
    # Change current directory to pyut's directory
    exePath = getCurrentAbsolutePath()
    sys.path.append(exePath)
    print "Executing PyUt from exepath ", exePath
    os.chdir(exePath)

#>----------------------------------------------------------------------------

def main(script=None):
    """
    main pyut function; create and run app

    @param string name : init name with the name
    @since 1.0
    @author C.Dutoit
    """
    import os, sys
    global exePath, userPath

    # Path
    sys.path.append(exePath)
    os.chdir(exePath)

    # Define last open directory ?
    #  - default is current directory
    #  - last opened directory for developers (pyut/src present)
    from PyutPreferences import PyutPreferences
    prefs = PyutPreferences()    # Prefs handler
    if (userPath.find('pyut/src')==-1) and (userPath.find('pyut2/src')==-1):
        # (User-mode)
        prefs["LastDirectory"] = userPath
    del prefs

    import lang
    from PyutApp import PyutApp
    app = PyutApp(0, splash=0, show=0)

    if script is not None:
        s = script(app.frame)
        params = [
            "/home/lb/docs/pysimul/src/puts/splitters.put",
            "/home/lb/docs/pyut2/src/essai.ps"
        ]
        s.setParams(params)
        s.run()


#>----------------------------------------------------------------------------

def treatArguments():
    """
    Treat arguments, display helps, ...

    @since 1.5.2.15
    @author C.Dutoit
    @return 1 if an arguments was found and PyUt must be stopped
    """
    import sys

    # Exit if no arguments
    if len(sys.argv)<2:
        return 0

    # Treat command line arguments
    if sys.argv[1] == "--version":
        from pyutVersion import getPyUtVersion
        print "PyUt, version %s" % getPyUtVersion()
        print
        return 1
    elif sys.argv[1] == "--help":
        from pyutVersion import getPyUtVersion
        print "PyUt, version %s" % getPyUtVersion()
        print "Syntaxe : pyut.pyw [filename] [--version] [--help]" \
              "[--start_directory=xxx]"
        print
        print "i.e. :    pyut.pyw --version             display version number"
        print "          pyut.pyw --help                display this help"
        print "          pyut.pyw file1 file2           load files"
        print "          pyut.pyw --start_directory=/   start with '/' as"
        print "                                         default directory"
        print
        return 1
    for param in sys.argv[1:]:
        if param[:18] == "--start_directory=":
            import os
            print "Starting with directory ", param[18:]
            global userPath
            userPath = param[18:]
    return 0
    

#>------------------------------------------------------------------------
#>------------------------------------------------------------------------

# this is where you can put your script
from PyutScripting import PyutScripting
class Put2Pdf(PyutScripting):
    """
    Needs params = ["src_file_name", "dst_file_name"]
    """
    def run(self):
        src, dst = self._params
        self.openFile(src)
        self.exportToPS(dst)

#>------------------------------------------------------------------------
#>------------------------------------------------------------------------

# Program entry point
if __name__ == "__main__":
    # Get exe path
    exePath = getExePath()

    # Launch pyut
    if treatArguments()<>1:
        main(Put2Pdf)
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.