# HG changeset patch # User John Schneiderman # Date 1407371017 18000 # Node ID 13f4dad3c9ad2fdffc03217ceeb38189f8ceb0f8 # Parent 1b4a20ee4b42b35b5549da0d2299126ec93e4322 Ability to select what groups to place in the ignore file. IN: - diff -r 1b4a20ee4b42 -r 13f4dad3c9ad INSTALL --- a/INSTALL Thu Jul 31 20:51:22 2014 -0500 +++ b/INSTALL Wed Aug 06 19:23:37 2014 -0500 @@ -24,8 +24,8 @@ How To compile the programme ============================ -1) python setup.py build -2) python setup.py install +1) setup.py build +2) setup.py install Known Issues ============ diff -r 1b4a20ee4b42 -r 13f4dad3c9ad doc/ChangeLog --- a/doc/ChangeLog Thu Jul 31 20:51:22 2014 -0500 +++ b/doc/ChangeLog Wed Aug 06 19:23:37 2014 -0500 @@ -21,6 +21,7 @@ - Unregistering repositories will now only do so on an exact match of the storage name. - Generate default ignore file when creating a new managed repository. +- Write an ignore file to an existing managed repository. 2014-07-29 John Schneiderman 0.2.1 - Fixed issue where the configuration file copy started before it closed. - Fixed issue in Windows locking temporary file and preventing copying. diff -r 1b4a20ee4b42 -r 13f4dad3c9ad doc/TODO --- a/doc/TODO Thu Jul 31 20:51:22 2014 -0500 +++ b/doc/TODO Wed Aug 06 19:23:37 2014 -0500 @@ -27,7 +27,6 @@ *** *** *** Feature Goals *** *** *** -- Allow selection of multiple ignore groups during creation. - Allow plug-ins addition and removal from repositories. - Installation tutorial. - User tutorials. diff -r 1b4a20ee4b42 -r 13f4dad3c9ad setup.cfg --- a/setup.cfg Thu Jul 31 20:51:22 2014 -0500 +++ b/setup.cfg Wed Aug 06 19:23:37 2014 -0500 @@ -1,4 +1,3 @@ -#!/usr/bin/env python # -*- coding: utf-8 -*- #******************************************************************************* #** This file is part of HgWeb Manager. *** diff -r 1b4a20ee4b42 -r 13f4dad3c9ad setup.py diff -r 1b4a20ee4b42 -r 13f4dad3c9ad src/hwm.py --- a/src/hwm.py Thu Jul 31 20:51:22 2014 -0500 +++ b/src/hwm.py Wed Aug 06 19:23:37 2014 -0500 @@ -92,12 +92,16 @@ parser.add_argument("-d", "--description", action="store", nargs='?', default=None, help='The description of the repository.') parser.add_argument("-c", "--contact", action="store", nargs='?', default=None, help='The contact point of a repository.') parser.add_argument("-r", "--rename", action="store", nargs='?', default=None, help='The new storage-name for a repository.') + parser.add_argument("-i", "--ignore", action="store", nargs='+', default=None, help='The groups to place in an ignore file.') args = parser.parse_args() repo = __extract_values(args) - if 'create' == args.action[0]: - if manager.create(repo): + if args.ignore: + ignores = args.ignore + else: + ignores = ['Common'] + if manager.create(repo, ignores): exit(0) else: exit(2) @@ -105,7 +109,7 @@ currentStorageName = repo.StorageName if args.rename: repo.StorageName = args.rename - if manager.modify(repo, currentStorageName): + if manager.modify(repo, currentStorageName, args.ignore): exit(0) else: exit(2) diff -r 1b4a20ee4b42 -r 13f4dad3c9ad src/ignorepo.py --- a/src/ignorepo.py Thu Jul 31 20:51:22 2014 -0500 +++ b/src/ignorepo.py Wed Aug 06 19:23:37 2014 -0500 @@ -32,7 +32,7 @@ """ Provides the mapping between an enumerated filter type and the Mercurial ignore section header. If an invalid argument is supplied, an empty string is given. - + @param[in] filltertype Is the enumerated value to map. @return The string value of the supplied enumerated value. diff -r 1b4a20ee4b42 -r 13f4dad3c9ad src/manager.py --- a/src/manager.py Thu Jul 31 20:51:22 2014 -0500 +++ b/src/manager.py Wed Aug 06 19:23:37 2014 -0500 @@ -25,12 +25,13 @@ from hwm import settings -def create(repository): +def create(repository, ignoreGroup): """ Creates a new repository under HgWeb. @pre The repository to create cannot already exist. @param[in] repository The targeted repository to create. + @param[in] ignoreGroup The list of all ignore groups to add. @post The file system now contains a new directory in the repository path that is the newly generated repository. The new repository is registered @@ -50,7 +51,7 @@ # Create the requested repository. if __addRepository(repository): print "Initialised repository directory." - if not create_ignores(repository): + if not __create_ignores(repository, ignoreGroup): return False else: print >>sys.stderr, "Failed to create repository directory." @@ -100,7 +101,7 @@ print >>sys.stderr, "Failed to register repository." return False -def modify(newRepository, currentStorageName): +def modify(newRepository, currentStorageName, ignoreGroup): """ Changes an existing repository in HgWeb. @pre The repository to modify must already exist. @@ -109,6 +110,7 @@ modify. @param[in] currentStorageName The current storage name of the repository to modify. + @param[in] ignoreGroup The list of all ignore groups to add. @post The repository is changed with the requested modifications. @@ -152,6 +154,14 @@ print >>sys.stderr, "Failed to roll back action." return False + # Update ignore file if requested. + if ignoreGroup is not None: + if __create_ignores(newRepository, ignoreGroup): + print "Successfully modified ignore file." + else: + print >>sys.stderr, "Failed to modify ignore file." + return False + # Add the new repository to the web registry. if __registerRepository(newRepository): print 'Repository modified.' @@ -193,14 +203,21 @@ print >>sys.stderr, "Failed to delete the repository." return False -def create_ignores(repository): + + +#--- Functions for fulfilling repository management. + + + +def __create_ignores(repo, ignoreGroup): """ Generates and commits an ignore file to an existing repository. @pre The repository to create an ignore file must already exist. The list of ignore patterns to use is expected to be in an XML file named "ignores.xml" and be in the hwm-ignore schema. - @param[in] repository The targeted repository for the ignore file. + @param[in] repo The targeted repository for the ignore file. + @param[in] ignoreGroup The list of all ignore groups to add. @post The managed repository now has an ignore file committed by the HgWeb manager. @@ -210,6 +227,7 @@ import os import ignorepo import sys + import xml # Extract Ignore Collection ignores = {} @@ -219,10 +237,18 @@ print >>sys.stderr, "Failed to extract ignores, error: %s" % e.message return False + ignoreFile = settings.RepositoryPath + os.sep + repo.StorageName + os.sep + '.hgignore' + wasCreated = not os.path.isfile(ignoreFile) + if wasCreated: + print "Creating ignore file." + else: + print "Rewriting ignore file." + # Write Ignore File - ignoreFile = settings.RepositoryPath + os.sep + repository.StorageName + os.sep + '.hgignore' with open(ignoreFile, 'w') as hgIgnore: for group,patterns in ignores.items(): + if not "All" in ignoreGroup and not group in ignoreGroup: + continue hgIgnore.write("#\n#\tIgnore Group: %s\n#" % group) # Reverse the sorting order to put the regular expressions first. patterns.sort(key = lambda p: p.Filter, reverse = True) @@ -235,25 +261,20 @@ filteringOn = pattern.Filter hgIgnore.write('\n\n') - if __addFile(repository, '.hgignore'): - print "Successfully added generated ignores." - else: - print >>sys.stderr, "Failed to add generated ignores." - return False + if wasCreated: + if __addFile(repo, '.hgignore'): + print "Successfully added generated ignores." + else: + print >>sys.stderr, "Failed to add generated ignores." + return False - if __commitChanges(repository, 'Created repository and set-up ignores.'): + if __commitChanges(repo, 'Created generated ignores filter.'): print "Successfully committed generated ignores." else: print >>sys.stderr, "Failed to commit generated ignores." return False return True - - -#--- Functions for fulfilling repository management. - - - def __commitChanges(repo, message): """ Commits all changes in a managed Mercurial repository as the HgWeb manager. @@ -276,7 +297,8 @@ except OSError as e: print >>sys.stderr, "Commit Error({0}): {1}".format(e.errno, e.strerror) return False - return (0 == statusCode) + # Zero being a successful commit and one being nothing changed. + return ((0 == statusCode) or (1 == statusCode)) def __addFile(repo, fileName): """ Marks a file as added in a managed Mercurial repository.