replacer.py :  » Ajax » pyjamas » src » contrib » pyjamas_0.4-0.5_upgrade » 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 » Ajax » pyjamas 
pyjamas » src » contrib » pyjamas_0.4 0.5_upgrade » replacer.py
#!/usr/bin/env python

""" This is a Pre-0.5 to Post-0.5 Application Upgrade Script.

    This program REWRITES your application - everything in the
    entire current working directory - modifying the import statements.
    The task of adapting applications is boring and laborious, so
    why waste time when you can run this script, and it'll be done
    in seconds.

    Please ensure that you do not have any import statements in the following
    syntax (do NOT use backslashes):
                                            v
    from pyjamas.ui import HorizontalPanel, \ <--
                           HTML             ^

    Older style statements such as 'from ui import HTML' are NOT covered but
    if you wish to adapt this code to do so, make a second 'searchfor'
    using 'from ui import ' instead of 'from pyjamas.ui import ' below.


    *****************
    **** WARNING ****

    You are expected to take your own precautions to mitigate the destruction
    of your source code, by utilising suitable protection measures such as
    source revision control.

    Absolutely no responsibility WHATSOEVER is, will or can be accepted for
    your failure to take basic precautions, whether you have or have not
    read, or have or have not accepted this warning.

    *****************
    *****************
"""

import sys
import os

def is_in_top_level_ui(modname):
    """ these can be imported 'from pyjamas.ui import modname'
        everything else must be imported
        'from pyjamas.ui.modname import classname', where modname happens
        to be the same as classname
    """
    if modname == 'Focus':
        return True
    if modname == 'Event':
        return True
    if modname == 'MouseListener':
        return True
    if modname == 'KeboardListener':
        return True
    if modname == 'FocusListener':
        return True
    if modname.startswith("Has") and modname.endswith("Alignment"):
        return True
    return False

def rewritefile(p):
    f = open(p)
    res = ''
    searchfor = "from pyjamas.ui import "
    sl = len(searchfor)
    for l in f.readlines():
        if l.startswith(searchfor):
            mods = l[sl:-1]
            l = ''
            for modname in mods.split(","):
                modname = modname.strip()
                if is_in_top_level_ui(modname):
                    l += "from pyjamas.ui import %s\n" % (modname)
                else:
                    l += "from pyjamas.ui.%s import %s\n" % (modname, modname)
        res += l
    f = open(p, "w")
    f.write(res)
    f.close()

for p in os.listdir("."):
    if p.endswith(".py"):
        rewritefile(p)


www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.