scripts/app_image.py
changeset 45 66c450a53786
child 48 39e1c8a54b37
equal deleted inserted replaced
44:9d3a0f98df34 45:66c450a53786
       
     1 #!/usr/bin/python2.5
       
     2 #
       
     3 # Copyright 2008 the Melange authors.
       
     4 #
       
     5 # Licensed under the Apache License, Version 2.0 (the "License");
       
     6 # you may not use this file except in compliance with the License.
       
     7 # You may obtain a copy of the License at
       
     8 #
       
     9 #   http://www.apache.org/licenses/LICENSE-2.0
       
    10 #
       
    11 # Unless required by applicable law or agreed to in writing, software
       
    12 # distributed under the License is distributed on an "AS IS" BASIS,
       
    13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
       
    14 # See the License for the specific language governing permissions and
       
    15 # limitations under the License.
       
    16 
       
    17 """Functions used by multiple scripts to form Google App Engine images.
       
    18 """
       
    19 
       
    20 __authors__ = [
       
    21   # alphabetical order by last name, please
       
    22   '"Todd Larsen" <tlarsen@google.com>',
       
    23 ]
       
    24 
       
    25 
       
    26 from trunk.scripts import svn_helper
       
    27 
       
    28 
       
    29 def getRepoAppPath(repo, app):
       
    30   """Returns path to specified Melange app in the supplied svn repository.
       
    31   """
       
    32   return '%strunk/apps/%s' % (repo, app)
       
    33 
       
    34 
       
    35 def getRepoThirdPartyPath(repo):
       
    36   """Returns path to third-party packages in the supplied svn repository.
       
    37   """
       
    38   return '%sthirdparty/' % repo
       
    39 
       
    40 
       
    41 def getThirdPartyPackageNames(pkg_path, **kwargs):
       
    42   """Returns a list of third-party packages in the supplied URL.
       
    43   """
       
    44   return [pkg for pkg in svn_helper.lsDirs(pkg_path, **kwargs)
       
    45             if not pkg.startswith('_')]
       
    46 
       
    47 
       
    48 def getRepoFrameworksPath(repo):
       
    49   """Returns path to Melange framework packages in the supplied svn repository.
       
    50   """
       
    51   return '%strunk/' % repo
       
    52 
       
    53 
       
    54 def getFrameworksNames():
       
    55   """Returns a list of Melange framework packages (currently a static list).
       
    56   """
       
    57   return ['soc/']
       
    58 
       
    59 
       
    60 def formDefaultAppBranchPath(branch, user, src, dest):
       
    61   """Returns a relative path to a to-be-created App Image branch.
       
    62 
       
    63   Args:
       
    64     branch: explicit branch name, if it was specified (or None, '', etc.
       
    65       instead, if it was not)
       
    66     user: subdirectory of /users/ representing a particular contributor
       
    67     src: sub-directory name of the specific Melange application to branch
       
    68     dest: alternate destination sub-directory name of the Melange application
       
    69       in its new, branched location, if it was specified (or None, '', etc.
       
    70       instead, if it was not)
       
    71 
       
    72   Returns:
       
    73     * branch if it was specified ("non-False"), or
       
    74     * users/user/dest if dest was specified, or
       
    75     * users/user/src otherwise
       
    76   """
       
    77   if not branch:
       
    78     if dest:
       
    79       branch = 'users/%s%s' % (user, dest)
       
    80     else:
       
    81       branch = 'users/%s%s' % (user, src)
       
    82 
       
    83   return branch
       
    84 
       
    85 
       
    86 def branchFromSrcApp(app, repo, dest, verbose=1, **svn_kwargs):
       
    87   """Branch one Melange app in /trunk/apps/ to form basis of App Engine image.
       
    88 
       
    89   Args:
       
    90     app: Melange application name in /trunk/apps/
       
    91     repo: svn repository root URL
       
    92     dest: working copy destination path of the image branch
       
    93     verbose: print status if greater than 0; default is 1
       
    94     **svn_kwargs: keyword arguments passed on to svn_helper.branchDir()
       
    95   """
       
    96   repo_app = getRepoAppPath(repo, app)
       
    97 
       
    98   if verbose > 0:
       
    99     print 'Branching %s from:\n %s\nto:\n %s\n' % (app, repo_app, dest)
       
   100 
       
   101   svn_helper.branchDir(repo_app, dest, **svn_kwargs)
       
   102 
       
   103 
       
   104 def branchFromThirdParty(repo, dest, verbose=1, **svn_kwargs):
       
   105   """Branch all subdirectories in /thirdparty/ into a new App Engine image.
       
   106 
       
   107   Subdirectories (except for those with names beginning with underscores) in
       
   108   /thirdparty/ represent third-party packages that are to be placed in each
       
   109   Google App Engine "image" branch.  Files in the root of /thirdparty/ (that
       
   110   is, not in a package) and, as previously mentioned, subdrectories beginning
       
   111   with underscores, are *not* branched.
       
   112 
       
   113   Args:
       
   114     repo: svn repository root URL
       
   115     dest: working copy destination path of the image branch
       
   116     verbose: print status if greater than 0; default is 1
       
   117     **svn_kwargs: keyword arguments passed on to svn_helper.branchItems()
       
   118   """
       
   119   pkg_dir = getRepoThirdPartyPath(repo)
       
   120   packages = getThirdPartyPackageNames(pkg_dir)
       
   121 
       
   122   if verbose > 0:
       
   123     print 'Branching third-party packages:\n %s\nfrom:\n %s\ninto:\n %s\n' % (
       
   124         '  '.join(packages), pkg_dir, dest)
       
   125 
       
   126   svn_helper.branchItems(pkg_dir, dest, packages, **svn_kwargs)
       
   127 
       
   128 
       
   129 def branchFromFramework(repo, dest, verbose=1, **svn_kwargs):
       
   130   """Branch the SoC framework into a new App Engine image branch.
       
   131 
       
   132   The SoC framework current consists of only the contents of /trunk/soc/.
       
   133 
       
   134   Args:
       
   135     repo: svn repository root URL
       
   136     dest: working copy destination path of the image branch
       
   137     verbose: print status if greater than 0; default is 1
       
   138     **svn_kwargs: keyword arguments passed on to svn_helper.branchItems()
       
   139   """
       
   140   framework_dir = getRepoFrameworksPath(repo)
       
   141   packages = getFrameworksNames()
       
   142 
       
   143   if verbose > 0:
       
   144     print 'Branching framework components:\n %s\nfrom:\n %s\ninto:\n %s\n' % (
       
   145       '  '.join(packages), framework_dir, dest)
       
   146 
       
   147   svn_helper.branchItems(framework_dir, dest, packages, **svn_kwargs)
       
   148 
       
   149 
       
   150 def exportFromSrcApp(app, repo, dest, verbose=1, **svn_kwargs):
       
   151   """Export one Melange app in /trunk/apps/ to form basis of App Engine image.
       
   152 
       
   153   Args:
       
   154     app: Melange application name in /trunk/apps/
       
   155     repo: svn repository root URL
       
   156     dest: local filesystem destination path of the exported image
       
   157     verbose: print status if greater than 0; default is 1
       
   158     **svn_kwargs: keyword arguments passed on to svn_helper.exportDir()
       
   159   """
       
   160   repo_app = getRepoAppPath(repo, app)
       
   161 
       
   162   if verbose > 0:
       
   163     print 'Exporting %s from:\n %s\nto:\n %s\n' % (app, repo_app, dest)
       
   164 
       
   165   svn_helper.exportDir(repo_app, dest, **svn_kwargs)
       
   166 
       
   167 
       
   168 def exportFromThirdParty(repo, dest, verbose=1, **svn_kwargs):
       
   169   """Export all subdirectories in /thirdparty/ into a new App Engine image.
       
   170 
       
   171   Subdirectories (except for those with names beginning with underscores) in
       
   172   /thirdparty/ represent third-party packages that are to be placed in each
       
   173   Google App Engine "image".  Files in the root of /thirdparty/ (that is,
       
   174   not in a package) and, as previously mentioned, subdirectories beginning
       
   175   with underscores, are *not* exported.
       
   176 
       
   177   Args:
       
   178     repo: svn repository root URL
       
   179     dest: local filesystem destination path of the exported image
       
   180     verbose: print status if greater than 0; default is 1
       
   181     **svn_kwargs: keyword arguments passed on to svn_helper.exportItems()
       
   182   """
       
   183   pkg_dir = getRepoThirdPartyPath(repo)
       
   184   packages = getThirdPartyPackageNames(pkg_dir)
       
   185 
       
   186   if verbose > 0:
       
   187     print 'Exporting third-party packages:\n %s\nfrom:\n %s\ninto:\n  %s\n' % (
       
   188         '  '.join(packages), pkg_dir, dest)
       
   189 
       
   190   svn_helper.exportItems(pkg_dir, dest, packages, **svn_kwargs)
       
   191 
       
   192 
       
   193 def exportFromFramework(repo, dest, verbose=1, **svn_kwargs):
       
   194   """Export the SoC framework into a new App Engine image.
       
   195 
       
   196   The SoC framework current consists of only the contents of /trunk/soc/.
       
   197 
       
   198   Args:
       
   199     repo: svn repository root URL
       
   200     dest: local filesystem destination path of the exported image
       
   201     verbose: print status if greater than 0; default is 1
       
   202     **svn_kwargs: keyword arguments passed on to svn_helper.exportItems()
       
   203   """
       
   204   framework_dir = getRepoFrameworksPath(repo)
       
   205   packages = getFrameworksNames()
       
   206 
       
   207   if verbose > 0:
       
   208     print 'Exporting framework components:\n %s\nfrom:\n %s\ninto:\n %s\n' % (
       
   209         '  '.join(packages), framework_dir, dest)
       
   210 
       
   211   svn_helper.exportItems(framework_dir, dest, packages, **svn_kwargs)