Changeset 3650

Show
Ignore:
Timestamp:
11/10/07 20:39:22 (1 year ago)
Author:
chrisz
Message:

Improved tg-admin quickstart and update in regard of projects stored in SVN.
Added option --svn=REPOS for automatically creating an SVN project.
Removed an unnecessary hack for creating empty directories that confused SVN.
Regard SVN when deleting unnecessary files or adding additional directories.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/1.0/turbogears/command/quickstart.py

    r3646 r3650  
    1717beginning_letter = re.compile(r"^[^a-z]*") 
    1818valid_only = re.compile(r"[^a-z0-9_]") 
     19 
    1920 
    2021class TGTemplate(templates.Template): 
     
    3334        super(TGTemplate, self).run(command, output_dirs, vars) 
    3435 
     36 
    3537class BaseTemplate(TGTemplate): 
    3638    egg_plugins = ["TurboGears"] 
     
    4244    use_cheetah = True 
    4345 
     46 
    4447class TurbogearsTemplate(TGTemplate): 
    4548    required_templates = ["tgbase"] 
     
    4952    summary = "web framework" 
    5053    use_cheetah = True 
     54 
    5155 
    5256class TGBig(TGTemplate): 
     
    7276                print "There is currently a controllers package and a" 
    7377                print "controllers module, which would get confusing." 
    74             if controllerstext == roottext or \ 
    75                     query_interactive(controllersfile, rootfile, 
    76                     controllerstext, roottext, False): 
     78            if not command.simulate and (controllerstext == roottext 
     79                    or query_interactive(controllersfile, rootfile, 
     80                        controllerstext, roottext, False)): 
    7781                shutil.copyfile(controllersfile, rootfile) 
    78                 os.unlink(controllersfile) 
     82                try: 
     83                    if not os.path.exists(os.path.join(os.path.dirname( 
     84                            os.path.abspath(controllersfile)), '.svn')): 
     85                        raise OSError 
     86                    command.run_command('svn', 'delete', controllersfile) 
     87                except OSError: 
     88                    os.unlink(controllersfile) 
    7989                controllerspyc = controllersfile + "c" 
    8090                if os.path.exists(controllerspyc): 
    8191                    os.unlink(controllerspyc) 
     92 
    8293 
    8394class TGWidgetTemplate(TGTemplate): 
     
    8899    summary = "TurboGears widget projects" 
    89100 
     101 
    90102class quickstart: 
    91103    "Implementation of quickstart." 
     
    96108    package = None 
    97109    templates = "turbogears" 
     110    svn_repository = None 
    98111    sqlalchemy = False 
    99112    sqlobject = False 
     
    111124            help="dry run (don't actually do anything)", 
    112125            action="store_true", dest="dry_run") 
     126        parser.add_option("--svn", metavar="REPOS", 
     127            help="Create new project at given repository location", 
     128            dest="svn_repository", default = self.svn_repository) 
    113129        parser.add_option("-t", "--templates", 
    114130            help="user specific templates", 
     
    127143            action="store_true", dest="identity", default = False) 
    128144 
    129         (options, args) = parser.parse_args() 
     145        options, args = parser.parse_args() 
    130146        self.__dict__.update(options.__dict__) 
    131147        if not True in [self.elixir, self.sqlalchemy, self.sqlobject]: 
     
    175191        env = pkg_resources.Environment() 
    176192        if self.name.lower() in env: 
    177             print "the name %s is already in use by" %self.name, 
     193            print 'The name "%s" is already in use by' % self.name, 
    178194            for dist in env[self.name]: 
    179195                print dist 
     
    183199        try: 
    184200            if imp.find_module(self.package): 
    185                 print "the package name %s is already in use" % self.package 
     201                print 'The package name "%s" is already in use' % self.package 
    186202                return 
    187203        except ImportError: 
     
    189205 
    190206        if os.path.exists(self.name): 
    191             print("A directory called '%s' already exists. Exiting." 
    192                       % self.name) 
     207            print 'A directory called "%s" already exists. Exiting.' % self.name 
    193208            return 
    194209 
     
    197212        for template in self.templates.split(" "): 
    198213            cmd_args.append("--template=%s" % template) 
     214        if self.svn_repository: 
     215            cmd_args.append("--svn-repository=%s" % self.svn_repository) 
    199216        cmd_args.append(self.name) 
    200217        cmd_args.append("package=%s" % self.package) 
     
    210227        if not self.dry_run: 
    211228            os.chdir(self.name) 
    212             sodir = '%s/sqlobject-history' % self.package 
    213             if self.sqlobject and not os.path.exists(sodir): 
    214                 os.mkdir(sodir) 
     229            if self.sqlobject: 
     230                # Create the SQLObject history directory only when needed. 
     231                # With paste.script it's only possible to skip files, but 
     232                # not directories. So we are handling this manually. 
     233                sodir = '%s/sqlobject-history' % self.package 
     234                if not os.path.exists(sodir): 
     235                    os.mkdir(sodir) 
     236                try: 
     237                    if not os.path.exists(os.path.join(os.path.dirname( 
     238                            os.path.abspath(sodir)), '.svn')): 
     239                        raise OSError 
     240                    command.run_command('svn', 'add', sodir) 
     241                except OSError: 
     242                    pass 
    215243            startscript = "start-%s.py" % self.package 
    216244            if os.path.exists(startscript): 
     
    222250            imp.load_module("setup", *imp.find_module("setup", ["."])) 
    223251 
    224             # dirty hack to allow "empty" dirs 
    225             for base,path,files in os.walk("./"): 
    226                 for file in files: 
    227                     if file  == "empty": 
    228                         os.remove(os.path.join(base, file)) 
    229252 
    230253class update: 
     
    258281            help="provide Identity support", 
    259282            action="store_true", dest="identity", default = False) 
    260         (options, args) = parser.parse_args() 
     283        options, args = parser.parse_args() 
    261284        self.__dict__.update(options.__dict__) 
    262285        self.turbogearsversion = version 
     
    293316        currentdir = os.path.basename(os.getcwd()) 
    294317        if not currentdir == self.name: 
    295             print 'it looks like your project dir "%s" is named wrongly. Please rename it to "%s"' %(currentdir, self.name) 
     318            print 'It looks like your project dir "%s" is named wrongly.' % currentdir 
     319            print 'Please rename it to "%s".' % self.name 
    296320            return 
    297321 
     
    317341        import imp 
    318342        imp.load_module("setup", *imp.find_module("setup", ["."])) 
    319  
    320         # dirty hack to allow "empty" dirs 
    321         for base,path,files in os.walk("./"): 
    322             for file in files: 
    323                 if file  == "empty": 
    324                     os.remove(os.path.join(base, file))