Mercurial > hgweb.cgi > hwm
changeset 52:27b2e19955c3
Updated to address Pep warnings. IN: -
author | John Schneiderman |
---|---|
date | Thu, 08 Jan 2015 18:58:03 +0100 |
parents | df9b499ac647 |
children | 8ef24a759bf6 |
files | MANIFEST.in setup.py src/__init__.py src/_app_info.py src/config.py src/enum.py src/hwm.py src/ignorepo.py src/manager.py src/manrepo.py |
diffstat | 10 files changed, 395 insertions(+), 368 deletions(-) [+] |
line wrap: on
line diff
--- a/MANIFEST.in Thu Aug 21 19:28:52 2014 -0500 +++ b/MANIFEST.in Thu Jan 08 18:58:03 2015 +0100 @@ -25,4 +25,4 @@ INSTALL \ doc/ChangeLog \ doc/TODO \ - doc/CREDITS + doc/CREDITS
--- a/setup.py Thu Aug 21 19:28:52 2014 -0500 +++ b/setup.py Thu Jan 08 18:58:03 2015 +0100 @@ -1,62 +1,64 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -#******************************************************************************* -#** This file is part of HgWeb Manager. *** -#** *** -#** Copyright (C) 2014 *** -#** CodeGNU Solutions <Licensing _AT_ CodeGNU _DOT_ com> *** -#** *** -#** This program is free software: you can redistribute it and/or modify it *** -#** under the terms of the GNU Affero General Public License as published *** -#** by the Free Software Foundation, either version 3 of the License, or *** -#** (at your option) any later version. *** -#** *** -#** This program is distributed in the hope that it will be useful, but *** -#** WITHOUT ANY WARRANTY; without even the implied warranty of *** -#** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *** -#** See the GNU Affero General Public License for more details. *** -#** *** -#** You should have received a copy of the GNU Affero General Public License*** -#** along with this program. If not, see <http://www.gnu.org/licenses/>. *** -#******************************************************************************* +'''***************************************************************************** +*** This file is part of HgWeb Manager. *** +*** *** +*** Copyright (C) 2014 *** +*** CodeGNU Solutions <Licensing _AT_ CodeGNU _DOT_ com> *** +*** *** +*** This program is free software: you can redistribute it and/or modify it *** +*** under the terms of the GNU Affero General Public License as published *** +*** by the Free Software Foundation, either version 3 of the License, or *** +*** (at your option) any later version. *** +*** *** +*** This program is distributed in the hope that it will be useful, but *** +*** WITHOUT ANY WARRANTY; without even the implied warranty of *** +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *** +*** See the GNU Affero General Public License for more details. *** +*** *** +*** You should have received a copy of the GNU Affero General Public License*** +*** along with this program. If not, see <http://www.gnu.org/licenses/>. *** +*****************************************************************************''' + from distutils.core import setup import sys sys.path.append('./src') -from _app_info import YEARS,VERSION,DESCRIPTION,LONG_DESCRIPTION,SHORT_NAME +from _app_info import VERSION, DESCRIPTION, LONG_DESCRIPTION, SHORT_NAME -required = [ - 'mercurial', - 'mercurial.hg', - 'mercurial.ui', - 'mercurial.error', - 'mercurial.hgweb', - 'filelock' -] +required = \ + [ + 'mercurial', + 'mercurial.hg', + 'mercurial.ui', + 'mercurial.error', + 'mercurial.hgweb', + 'filelock' + ] # Basic package setup information setup( - name = SHORT_NAME, - version = VERSION, - description = DESCRIPTION, - long_description = LONG_DESCRIPTION, - author = 'CodeGNU Solutions', - author_email = 'Licensing@CodeGNU.com', - url = 'http://www.codegnu.com', - download_url = "http://www.codegnu.com/files/hwm-{0}.tar.gz".format(VERSION), - license = 'AGPLv3+', - packages = ['HgWebManager'], - package_dir = {'HgWebManager': 'src'}, - provides = ['HgWebManager'], - requires = required, - platforms = [ + name=SHORT_NAME, + version=VERSION, + description=DESCRIPTION, + long_description=LONG_DESCRIPTION, + author='CodeGNU Solutions', + author_email='Licensing@CodeGNU.com', + url='http://www.codegnu.com', + download_url="http://www.codegnu.com/files/hwm-{0}.tar.gz".format(VERSION), + license='AGPLv3+', + packages=['HgWebManager'], + package_dir={'HgWebManager': 'src'}, + provides=['HgWebManager'], + requires=required, + platforms=[ 'GNU/Linux', 'POSIX', 'Mac OS', 'Windows' ], - classifiers = [ + classifiers=[ 'Development Status :: 3 - Alpha', 'Environment :: Console', 'Environment :: Web Environment', @@ -73,7 +75,7 @@ 'Topic :: Software Development :: Version Control', 'Topic :: System :: Systems Administration' ], - data_files = [ + data_files=[ ( "share/" + SHORT_NAME, [
--- a/src/__init__.py Thu Aug 21 19:28:52 2014 -0500 +++ b/src/__init__.py Thu Jan 08 18:58:03 2015 +0100 @@ -1,32 +1,33 @@ # -*- coding: utf-8 -*- -#******************************************************************************* -#** This file is part of HgWeb Manager. *** -#** *** -#** Copyright (C) 2014 *** -#** CodeGNU Solutions <Licensing _AT_ CodeGNU _DOT_ com> *** -#** *** -#** This program is free software: you can redistribute it and/or modify it *** -#** under the terms of the GNU Affero General Public License as published *** -#** by the Free Software Foundation, either version 3 of the License, or *** -#** (at your option) any later version. *** -#** *** -#** This program is distributed in the hope that it will be useful, but *** -#** WITHOUT ANY WARRANTY; without even the implied warranty of *** -#** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *** -#** See the GNU Affero General Public License for more details. *** -#** *** -#** You should have received a copy of the GNU Affero General Public License*** -#** along with this program. If not, see <http://www.gnu.org/licenses/>. *** -#******************************************************************************* +'''***************************************************************************** +*** This file is part of HgWeb Manager. *** +*** *** +*** Copyright (C) 2014 *** +*** CodeGNU Solutions <Licensing _AT_ CodeGNU _DOT_ com> *** +*** *** +*** This program is free software: you can redistribute it and/or modify it *** +*** under the terms of the GNU Affero General Public License as published *** +*** by the Free Software Foundation, either version 3 of the License, or *** +*** (at your option) any later version. *** +*** *** +*** This program is distributed in the hope that it will be useful, but *** +*** WITHOUT ANY WARRANTY; without even the implied warranty of *** +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *** +*** See the GNU Affero General Public License for more details. *** +*** *** +*** You should have received a copy of the GNU Affero General Public License*** +*** along with this program. If not, see <http://www.gnu.org/licenses/>. *** +*****************************************************************************''' # Files to include when creating the package. -__all__ = [ - '_app_info.py' - , 'config.py' - , 'enum.py' - , 'hwm.py' - , 'ignorepo.py' - , 'manager.py' - , 'manrepo.py' -] +__all__ = \ + [ + '_app_info.py', + 'config.py', + 'enum.py', + 'hwm.py', + 'ignorepo.py', + 'manager.py', + 'manrepo.py' + ]
--- a/src/_app_info.py Thu Aug 21 19:28:52 2014 -0500 +++ b/src/_app_info.py Thu Jan 08 18:58:03 2015 +0100 @@ -1,29 +1,30 @@ # -*- coding: utf-8 -*- -#******************************************************************************* -#** This file is part of HgWeb Manager. *** -#** *** -#** Copyright (C) 2014 *** -#** CodeGNU Solutions <Licensing _AT_ CodeGNU _DOT_ com> *** -#** *** -#** This program is free software: you can redistribute it and/or modify it *** -#** under the terms of the GNU Affero General Public License as published *** -#** by the Free Software Foundation, either version 3 of the License, or *** -#** (at your option) any later version. *** -#** *** -#** This program is distributed in the hope that it will be useful, but *** -#** WITHOUT ANY WARRANTY; without even the implied warranty of *** -#** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *** -#** See the GNU Affero General Public License for more details. *** -#** *** -#** You should have received a copy of the GNU Affero General Public License*** -#** along with this program. If not, see <http://www.gnu.org/licenses/>. *** -#******************************************************************************* +'''***************************************************************************** +*** This file is part of HgWeb Manager. *** +*** *** +*** Copyright (C) 2014 *** +*** CodeGNU Solutions <Licensing _AT_ CodeGNU _DOT_ com> *** +*** *** +*** This program is free software: you can redistribute it and/or modify it *** +*** under the terms of the GNU Affero General Public License as published *** +*** by the Free Software Foundation, either version 3 of the License, or *** +*** (at your option) any later version. *** +*** *** +*** This program is distributed in the hope that it will be useful, but *** +*** WITHOUT ANY WARRANTY; without even the implied warranty of *** +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *** +*** See the GNU Affero General Public License for more details. *** +*** *** +*** You should have received a copy of the GNU Affero General Public License*** +*** along with this program. If not, see <http://www.gnu.org/licenses/>. *** +*****************************************************************************''' + # The shortened name of the application -SHORT_NAME='HWM' +SHORT_NAME = 'HWM' # The full name of the application -LONG_NAME='HgWeb Manager' +LONG_NAME = 'HgWeb Manager' # The current version of the application VERSION = '0.3.0'
--- a/src/config.py Thu Aug 21 19:28:52 2014 -0500 +++ b/src/config.py Thu Jan 08 18:58:03 2015 +0100 @@ -1,23 +1,24 @@ # -*- coding: utf-8 -*- -#******************************************************************************* -#** This file is part of HgWeb Manager. *** -#** *** -#** Copyright (C) 2014 *** -#** CodeGNU Solutions <Licensing _AT_ CodeGNU _DOT_ com> *** -#** *** -#** This program is free software: you can redistribute it and/or modify it *** -#** under the terms of the GNU Affero General Public License as published *** -#** by the Free Software Foundation, either version 3 of the License, or *** -#** (at your option) any later version. *** -#** *** -#** This program is distributed in the hope that it will be useful, but *** -#** WITHOUT ANY WARRANTY; without even the implied warranty of *** -#** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *** -#** See the GNU Affero General Public License for more details. *** -#** *** -#** You should have received a copy of the GNU Affero General Public License*** -#** along with this program. If not, see <http://www.gnu.org/licenses/>. *** -#******************************************************************************* +'''***************************************************************************** +*** This file is part of HgWeb Manager. *** +*** *** +*** Copyright (C) 2014 *** +*** CodeGNU Solutions <Licensing _AT_ CodeGNU _DOT_ com> *** +*** *** +*** This program is free software: you can redistribute it and/or modify it *** +*** under the terms of the GNU Affero General Public License as published *** +*** by the Free Software Foundation, either version 3 of the License, or *** +*** (at your option) any later version. *** +*** *** +*** This program is distributed in the hope that it will be useful, but *** +*** WITHOUT ANY WARRANTY; without even the implied warranty of *** +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *** +*** See the GNU Affero General Public License for more details. *** +*** *** +*** You should have received a copy of the GNU Affero General Public License*** +*** along with this program. If not, see <http://www.gnu.org/licenses/>. *** +*****************************************************************************''' + class Manager(object): """ Manages the configurations for HgWebManager """ @@ -53,11 +54,10 @@ """ Gets the user-name of the web-manager. """ return self.__hgUser - - def __init__(self, path = ['/etc/hwm.ini', '~/.hwm/hwm.ini', './hwm.ini']): + def __init__(self, path=['/etc/hwm.ini', '~/.hwm/hwm.ini', './hwm.ini']): """ Loads the settings values stored in the configuration file. - @param[in] path The path and file name of the configuration file. + @param[in] path The path and file name of the configuration file. """ from ConfigParser import SafeConfigParser, Error
--- a/src/enum.py Thu Aug 21 19:28:52 2014 -0500 +++ b/src/enum.py Thu Jan 08 18:58:03 2015 +0100 @@ -1,31 +1,32 @@ # -*- coding: utf-8 -*- -#******************************************************************************* -#** This file is part of HgWeb Manager. *** -#** *** -#** Copyright (C) 2014 *** -#** CodeGNU Solutions <Licensing _AT_ CodeGNU _DOT_ com> *** -#** *** -#** This program is free software: you can redistribute it and/or modify it *** -#** under the terms of the GNU Affero General Public License as published *** -#** by the Free Software Foundation, either version 3 of the License, or *** -#** (at your option) any later version. *** -#** *** -#** This program is distributed in the hope that it will be useful, but *** -#** WITHOUT ANY WARRANTY; without even the implied warranty of *** -#** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *** -#** See the GNU Affero General Public License for more details. *** -#** *** -#** You should have received a copy of the GNU Affero General Public License*** -#** along with this program. If not, see <http://www.gnu.org/licenses/>. *** -#******************************************************************************* +'''***************************************************************************** +*** This file is part of HgWeb Manager. *** +*** *** +*** Copyright (C) 2014 *** +*** CodeGNU Solutions <Licensing _AT_ CodeGNU _DOT_ com> *** +*** *** +*** This program is free software: you can redistribute it and/or modify it *** +*** under the terms of the GNU Affero General Public License as published *** +*** by the Free Software Foundation, either version 3 of the License, or *** +*** (at your option) any later version. *** +*** *** +*** This program is distributed in the hope that it will be useful, but *** +*** WITHOUT ANY WARRANTY; without even the implied warranty of *** +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *** +*** See the GNU Affero General Public License for more details. *** +*** *** +*** You should have received a copy of the GNU Affero General Public License*** +*** along with this program. If not, see <http://www.gnu.org/licenses/>. *** +*****************************************************************************''' + def create(*sequential, **named): """ Creates a type which mimics the behaviour of an enumeration. - @param[in] sequential - @param[in] named + @param[in] sequential + @param[in] named - @return An object which contains the supplied enumerated values. + @return An object which contains the supplied enumerated values. """ enums = dict(zip(sequential, range(len(sequential))), **named) reverse = dict((value, key) for key, value in enums.iteritems())
--- a/src/hwm.py Thu Aug 21 19:28:52 2014 -0500 +++ b/src/hwm.py Thu Jan 08 18:58:03 2015 +0100 @@ -1,34 +1,34 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -#******************************************************************************* -#** This file is part of HgWeb Manager. *** -#** *** -#** Copyright (C) 2014 *** -#** CodeGNU Solutions <Licensing _AT_ CodeGNU _DOT_ com> *** -#** *** -#** This program is free software: you can redistribute it and/or modify it *** -#** under the terms of the GNU Affero General Public License as published *** -#** by the Free Software Foundation, either version 3 of the License, or *** -#** (at your option) any later version. *** -#** *** -#** This program is distributed in the hope that it will be useful, but *** -#** WITHOUT ANY WARRANTY; without even the implied warranty of *** -#** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *** -#** See the GNU Affero General Public License for more details. *** -#** *** -#** You should have received a copy of the GNU Affero General Public License*** -#** along with this program. If not, see <http://www.gnu.org/licenses/>. *** -#******************************************************************************* +'''***************************************************************************** +*** This file is part of HgWeb Manager. *** +*** *** +*** Copyright (C) 2014 *** +*** CodeGNU Solutions <Licensing _AT_ CodeGNU _DOT_ com> *** +*** *** +*** This program is free software: you can redistribute it and/or modify it *** +*** under the terms of the GNU Affero General Public License as published *** +*** by the Free Software Foundation, either version 3 of the License, or *** +*** (at your option) any later version. *** +*** *** +*** This program is distributed in the hope that it will be useful, but *** +*** WITHOUT ANY WARRANTY; without even the implied warranty of *** +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *** +*** See the GNU Affero General Public License for more details. *** +*** *** +*** You should have received a copy of the GNU Affero General Public License*** +*** along with this program. If not, see <http://www.gnu.org/licenses/>. *** +*****************************************************************************''' + """ - IMPORTS +IMPORTS """ import config -from _app_info import * +import _app_info try: - # Configuration values for HgWebManager. settings = config.Manager() except Exception as e: import sys @@ -40,8 +40,8 @@ def is_hgWeb_user(): """ Determines if the current running user is the expected HgWeb user. - @return Gives true when the user is the expected HgWeb user, false - else-wise. + @return Gives true when the user is the expected HgWeb user, false + else-wise. """ import getpass @@ -54,14 +54,14 @@ def __extract_values(args): """ Pulls the creation arguments out of the command-line. The returned - object is filled with the repository details when it exists and any of the - detail values supplied on the command-line will replace the one found in - the repository details. + object is filled with the repository details when it exists and any of the + detail values supplied on the command-line will replace the one found in + the repository details. - @param[in] args The command-line argument processor containing the + @param[in] args The command-line argument processor containing the creation argument values. - @return A managed repository object. + @return A managed repository object. """ import manrepo @@ -86,6 +86,7 @@ return managed + def main(args): import argparse import manager @@ -95,7 +96,7 @@ print >>sys.stderr, 'Must execute as the Mercurial Web manager.' exit(1) - parser = argparse.ArgumentParser(description=DESCRIPTION) + parser = argparse.ArgumentParser(description=_app_info.DESCRIPTION) parser.add_argument('-l', '--list', action='store_true', help='Outputs a list of all the managed repositories.') manGrp = parser.add_argument_group('Manage', 'Options that operate upon managed repositories.') @@ -139,8 +140,9 @@ import sys # Display license - print "%s %s Copyright (C) %s CodeGNU Solutions" % (LONG_NAME, VERSION, YEARS) - print "%s comes with ABSOLUTELY NO WARRANTY;" % (SHORT_NAME) + print "%s %s Copyright (C) %s CodeGNU Solutions" % \ + (_app_info.LONG_NAME, _app_info.VERSION, _app_info.YEARS) + print "%s comes with ABSOLUTELY NO WARRANTY;" % (_app_info.SHORT_NAME) print 'This is free software, and you are welcome to redistribute it' print 'under certain conditions; see the LICENSE file for details,' print 'or the Free Software Foundation\'s AGPL.\n'
--- a/src/ignorepo.py Thu Aug 21 19:28:52 2014 -0500 +++ b/src/ignorepo.py Thu Jan 08 18:58:03 2015 +0100 @@ -1,26 +1,27 @@ # -*- coding: utf-8 -*- -#******************************************************************************* -#** This file is part of HgWeb Manager. *** -#** *** -#** Copyright (C) 2014 *** -#** CodeGNU Solutions <Licensing _AT_ CodeGNU _DOT_ com> *** -#** *** -#** This program is free software: you can redistribute it and/or modify it *** -#** under the terms of the GNU Affero General Public License as published *** -#** by the Free Software Foundation, either version 3 of the License, or *** -#** (at your option) any later version. *** -#** *** -#** This program is distributed in the hope that it will be useful, but *** -#** WITHOUT ANY WARRANTY; without even the implied warranty of *** -#** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *** -#** See the GNU Affero General Public License for more details. *** -#** *** -#** You should have received a copy of the GNU Affero General Public License*** -#** along with this program. If not, see <http://www.gnu.org/licenses/>. *** -#******************************************************************************* +'''***************************************************************************** +*** This file is part of HgWeb Manager. *** +*** *** +*** Copyright (C) 2014 *** +*** CodeGNU Solutions <Licensing _AT_ CodeGNU _DOT_ com> *** +*** *** +*** This program is free software: you can redistribute it and/or modify it *** +*** under the terms of the GNU Affero General Public License as published *** +*** by the Free Software Foundation, either version 3 of the License, or *** +*** (at your option) any later version. *** +*** *** +*** This program is distributed in the hope that it will be useful, but *** +*** WITHOUT ANY WARRANTY; without even the implied warranty of *** +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *** +*** See the GNU Affero General Public License for more details. *** +*** *** +*** You should have received a copy of the GNU Affero General Public License*** +*** along with this program. If not, see <http://www.gnu.org/licenses/>. *** +*****************************************************************************''' + """ - IMPORTS +IMPORTS """ import enum @@ -28,14 +29,15 @@ # The types of filtering available for an ignore file. FilterType = enum.create('Glob', 'RegularExpression') + def ignore_syntax_name(mapFilterType): """ 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. + Mercurial ignore section header. If an invalid argument is supplied, an + empty string is given. - @param[in] mapFilterType Is the enumerated value to map. + @param[in] mapFilterType Is the enumerated value to map. - @return The string value of the supplied enumerated value. + @return The string value of the supplied enumerated value. """ if FilterType.Glob == mapFilterType: return 'glob' @@ -58,7 +60,7 @@ @property def Description(self): """ A short entry describing the purpose of the ignore entry when - provided, else gives miscellaneous. + provided, else gives miscellaneous. """ if self.__description: return self.__description @@ -78,9 +80,9 @@ def __init__(self, desc, fil, val): """ Initialises the object with the values supplied. - @param[in] desc The description of the ignore entry. - @param[in] fil The type of ignore filtering. - @param[in] val The ignore expression. + @param[in] desc The description of the ignore entry. + @param[in] fil The type of ignore filtering. + @param[in] val The ignore expression. """ self.__description = desc.strip() if fil == 'glob': @@ -91,21 +93,23 @@ raise Exception("Invalid filter type '%s' supplied" % fil) self.__value = val.strip() + def extract(ignoreFile): """ Parses an XML file for ignore file patterns. Generates a dictionary - object whose key is the name of the group for a collection of ignore - patterns. The value in each dictionary is an array of all the ignore - pattern objects within that group. Upon any parsing error, no ignore - patterns are supplied. + object whose key is the name of the group for a collection of ignore + patterns. The value in each dictionary is an array of all the ignore + pattern objects within that group. Upon any parsing error, no ignore + patterns are supplied. - @param[in] ignoreFile The directory path and file name to an XML file - that contains the ignore patterns to extract. + @param[in] ignoreFile The directory path and file name to an XML file + that contains the ignore patterns to extract. - @throw Exception When the name of a group is reused - in the XML file. - @throw xml.parsers.expat.ExpatError When the XML file cannot be parsed. + @throw Exception When the name of a group is reused + in the XML file. - @return The extracted grouped ignore patterns. + @throw xml.parsers.expat.ExpatError When the XML file cannot be parsed. + + @return The extracted grouped ignore patterns. """ from xml.dom import minidom @@ -118,9 +122,8 @@ else: ignores[groupName] = [] for pattern in group.getElementsByTagName('pattern'): - ignores[groupName].append(Pattern( \ - pattern.getAttribute('description'), \ - pattern.getAttribute('type'), \ + ignores[groupName].append(Pattern( + pattern.getAttribute('description'), + pattern.getAttribute('type'), pattern.firstChild.nodeValue)) return ignores -
--- a/src/manager.py Thu Aug 21 19:28:52 2014 -0500 +++ b/src/manager.py Thu Jan 08 18:58:03 2015 +0100 @@ -1,26 +1,27 @@ # -*- coding: utf-8 -*- -#******************************************************************************* -#** This file is part of HgWeb Manager. *** -#** *** -#** Copyright (C) 2014 *** -#** CodeGNU Solutions <Licensing _AT_ CodeGNU _DOT_ com> *** -#** *** -#** This program is free software: you can redistribute it and/or modify it *** -#** under the terms of the GNU Affero General Public License as published *** -#** by the Free Software Foundation, either version 3 of the License, or *** -#** (at your option) any later version. *** -#** *** -#** This program is distributed in the hope that it will be useful, but *** -#** WITHOUT ANY WARRANTY; without even the implied warranty of *** -#** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *** -#** See the GNU Affero General Public License for more details. *** -#** *** -#** You should have received a copy of the GNU Affero General Public License*** -#** along with this program. If not, see <http://www.gnu.org/licenses/>. *** -#******************************************************************************* +'''***************************************************************************** +*** This file is part of HgWeb Manager. *** +*** *** +*** Copyright (C) 2014 *** +*** CodeGNU Solutions <Licensing _AT_ CodeGNU _DOT_ com> *** +*** *** +*** This program is free software: you can redistribute it and/or modify it *** +*** under the terms of the GNU Affero General Public License as published *** +*** by the Free Software Foundation, either version 3 of the License, or *** +*** (at your option) any later version. *** +*** *** +*** This program is distributed in the hope that it will be useful, but *** +*** WITHOUT ANY WARRANTY; without even the implied warranty of *** +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *** +*** See the GNU Affero General Public License for more details. *** +*** *** +*** You should have received a copy of the GNU Affero General Public License*** +*** along with this program. If not, see <http://www.gnu.org/licenses/>. *** +*****************************************************************************''' + """ - IMPORTS +IMPORTS """ from hwm import settings @@ -28,18 +29,18 @@ def create(repository, ignoreGroups, skipCommon): """ Creates a new repository under HgWeb. - @pre The repository to create cannot already exist. + @pre The repository to create cannot already exist. - @param[in] repository The targeted repository to create. - @param[in] ignoreGroups The list of all ignore groups to add. - @param[in] skipCommon A flag that when true indicates the common group - should not be added by default. + @param[in] repository The targeted repository to create. + @param[in] ignoreGroups The list of all ignore groups to add. + @param[in] skipCommon A flag that when true indicates the common group + should not be added by default. - @post The file system now contains a new directory in the repository path - that is the newly generated repository. The new repository is registered - in HgWeb to display and is secured to prevent accidental modification. + @post The file system now contains a new directory in the repository path + that is the newly generated repository. The new repository is registered + in HgWeb to display and is secured to prevent accidental modification. - @return When the creation is successful gives true, else-wise false. + @return When the creation is successful gives true, else-wise false. """ import sys import os @@ -86,17 +87,18 @@ shutil.rmtree(settings.RepositoryPath + os.sep + repository.StorageName) return False + def register(repository): """ Connects an existing repository to the mercurial web registry. - @pre The repository to register must already exist. + @pre The repository to register must already exist. - @param[in] repository The targeted repository to register. + @param[in] repository The targeted repository to register. - @post The new repository is registered in HgWeb to display and is - secured to prevent accidental modification. + @post The new repository is registered in HgWeb to display and is + secured to prevent accidental modification. - @return When the registration is successful gives true, else-wise false. + @return When the registration is successful gives true, else-wise false. """ import sys import filelock as guard @@ -117,23 +119,24 @@ print >>sys.stderr, "Failed to register repository." return False + def modify(newRepository, currentStorageName, ignoreGroups, skipCommon): """ Changes an existing repository in HgWeb. - @pre The repository to modify must already exist. + @pre The repository to modify must already exist. - @param[in] newRepository The new values for the repository to - modify. - @param[in] currentStorageName The current storage name of the - repository to modify. - @param[in] ignoreGroups The list of all ignore groups to add. - @param[in] skipCommon A flag that when true indicates the - common group should not be added by - default. + @param[in] newRepository The new values for the repository to + modify. + @param[in] currentStorageName The current storage name of the + repository to modify. + @param[in] ignoreGroups The list of all ignore groups to add. + @param[in] skipCommon A flag that when true indicates the + common group should not be added by + default. - @post The repository is changed with the requested modifications. + @post The repository is changed with the requested modifications. - @return When the modification is successful gives true, else-wise false. + @return When the modification is successful gives true, else-wise false. """ import sys from manrepo import Repository @@ -199,18 +202,19 @@ print >>sys.stderr, "Failed to register repository." return False + def delete(repository): """ Removes an existing repository. - @pre The repository to remove must already exist. + @pre The repository to remove must already exist. - @param[in] repository The targeted repository to delete. + @param[in] repository The targeted repository to delete. - @post The file system no longer contains a directory in the repository - path that is the supplied repository. The repository is no longer - registered in HgWeb. + @post The file system no longer contains a directory in the repository + path that is the supplied repository. The repository is no longer + registered in HgWeb. - @return When the deletion is successful gives true, else-wise false. + @return When the deletion is successful gives true, else-wise false. """ import sys import filelock as guard @@ -236,10 +240,11 @@ return False print >>sys.stderr, "The HgWeb configuration file does not have a paths section!" + def list(): """ Outputs a listing of all the known managed repositories - @return When the output generation is successful gives true, else-wise false. + @return When the output generation is successful gives true, else-wise false. """ import manrepo @@ -250,31 +255,30 @@ print "\t%s (%s)" % (repo.StorageName, repo.DisplayName) return True except Exception as e: + import sys + print >>sys.stderr, "Listing error({0}): {1}".format(e.errno, e.strerror) return False - - -#--- Functions for fulfilling repository management. - +# Functions for fulfilling repository management. def __create_ignores(repo, ignoreGroups, skipCommon): """ 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. + @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] repo The targeted repository for the ignore file. - @param[in] ignoreGroups The list of all ignore groups to add. - @param[in] skipCommon A flag that when true indicates the common group - should not be added by default. + @param[in] repo The targeted repository for the ignore file. + @param[in] ignoreGroups The list of all ignore groups to add. + @param[in] skipCommon A flag that when true indicates the common group + should not be added by default. - @post The managed repository now has an ignore file committed by the - HgWeb manager. + @post The managed repository now has an ignore file committed by the + HgWeb manager. - @return When the creation is successful gives true, else-wise false. + @return When the creation is successful gives true, else-wise false. """ import os import ignorepo @@ -296,10 +300,10 @@ if skipCommon: del ignores['Common'] - elif not 'common' in [ignoreGroup.lower() for ignoreGroup in ignoreGroups]: + elif 'common' not in [ignoreGroup.lower() for ignoreGroup in ignoreGroups]: ignoreGroups.append('Common') - if not '+' in ignoreGroups: + if '+' not in ignoreGroups: for ignoreGroup in ignoreGroups: if not ignoreGroup.lower() in [ignore.lower() for ignore in ignores]: print >>sys.stderr, "The list of ignores does not have the '%s' group." % ignoreGroup @@ -314,12 +318,12 @@ # Write Ignore File with open(ignoreFile, 'w') as hgIgnore: - for groupName,groupPatterns in ignores.items(): - if not '+' in ignoreGroups and not groupName.lower() in [ignoreGroup.lower() for ignoreGroup in ignoreGroups]: + for groupName, groupPatterns in ignores.items(): + if '+' not in ignoreGroups and not groupName.lower() in [ignoreGroup.lower() for ignoreGroup in ignoreGroups]: continue hgIgnore.write("#\n#\tIgnore Group: %s\n#" % groupName) # Reverse the sorting order to put the regular expressions first. - groupPatterns.sort(key = lambda p: p.Filter, reverse = True) + groupPatterns.sort(key=lambda p: p.Filter, reverse=True) filteringOn = None for pattern in groupPatterns: if pattern.Filter == filteringOn: @@ -345,18 +349,19 @@ return False return True + def __commitChanges(repo, message): """ Commits all changes in a managed Mercurial repository as the HgWeb - manager. + manager. - @pre The requested repository must already exist. + @pre The requested repository must already exist. - @param[in] repo The targeted repository for which to commit. - @param[in] message The text to use as a commit message. + @param[in] repo The targeted repository for which to commit. + @param[in] message The text to use as a commit message. - @post Upon any error the standard error buffer contains an error message. + @post Upon any error the standard error buffer contains an error message. - @return When the process is successful gives true, else-wise false. + @return When the process is successful gives true, else-wise false. """ import subprocess import sys @@ -370,18 +375,19 @@ # 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. - @pre The requested repository must already exist. + @pre The requested repository must already exist. - @param[in] repo The targeted repository for which to add the file. - @param[in] fileName The directory path and the file name to add - relative to the base of the repository. + @param[in] repo The targeted repository for which to add the file. + @param[in] fileName The directory path and the file name to add + relative to the base of the repository. - @post Upon any error the standard error buffer contains an error message. + @post Upon any error the standard error buffer contains an error message. - @return When the process is successful gives true, else-wise false. + @return When the process is successful gives true, else-wise false. """ import subprocess import sys @@ -394,15 +400,16 @@ return False return (0 == statusCode) + def __renameStorage(oldRepo, newName): """ Changes the storage name of an existing repository. - @param[in] oldRepo The existing repository to whose storage name is - expected to be changed. - @param[in] newName The new storage name for the repository. + @param[in] oldRepo The existing repository to whose storage name is + expected to be changed. + @param[in] newName The new storage name for the repository. - @return Gives true when the storage name is successfully renamed, - else-wise gives false. + @return Gives true when the storage name is successfully renamed, + else-wise gives false. """ import os import sys @@ -421,12 +428,13 @@ return False return True + def __doesRepositoryStorageNameExist(repo): """ Checks to see if a repository storage name exists. - @param[in] repo The targeted repository for which to check. + @param[in] repo The targeted repository for which to check. - @return Gives true when it exists, false else-wise. + @return Gives true when it exists, false else-wise. """ import os @@ -437,15 +445,15 @@ else: return False + def __doesRepositoryDisplayNameExist(repo): """ Checks to see if a repository display name exists. - @param[in] repo The targeted repository for which to check. + @param[in] repo The targeted repository for which to check. - @return Gives true when it exists, false else-wise. + @return Gives true when it exists, false else-wise. """ - import os - from manrepo import Repository, ManagedCollection + from manrepo import ManagedCollection if (repo is None) or (repo.StorageName is None) or (repo.DisplayName is None): return False @@ -456,16 +464,17 @@ return True return False + def __unregisterRepository(repo): """ Removes the registration of the supplied repository. - @param[in] repo The targeted repository for which to unregister. + @param[in] repo The targeted repository for which to unregister. - @post The HgWeb configuration file does not contain the repository details - and is returned to a read-only state. Upon any error the standard error - buffer contains an error message. + @post The HgWeb configuration file does not contain the repository details + and is returned to a read-only state. Upon any error the standard error + buffer contains an error message. - @return When the process is successful gives true, else-wise false. + @return When the process is successful gives true, else-wise false. """ from ConfigParser import SafeConfigParser import os @@ -490,16 +499,17 @@ print >>sys.stderr, "The HgWeb configuration file does not have a paths section!" return False + def __removeRepository(repo): """ Removes an existing Mercurial repository. - @pre The requested repository to delete must already exist. + @pre The requested repository to delete must already exist. - @param[in] repo The targeted repository for which to delete. + @param[in] repo The targeted repository for which to delete. - @post Upon any error the standard error buffer contains an error message. + @post Upon any error the standard error buffer contains an error message. - @return When the process is successful gives true, else-wise false. + @return When the process is successful gives true, else-wise false. """ import shutil import os @@ -517,16 +527,17 @@ shutil.rmtree(settings.RepositoryPath + os.sep + repo.StorageName) return True + def __addRepository(repo): """ Initialises a new Mercurial repository. - @pre The requested repository to create cannot already exist. + @pre The requested repository to create cannot already exist. - @param[in] repo The targeted repository for which to create. + @param[in] repo The targeted repository for which to create. - @post Upon any error the standard error buffer contains an error message. + @post Upon any error the standard error buffer contains an error message. - @return When the process is successful gives true, else-wise false. + @return When the process is successful gives true, else-wise false. """ import subprocess import sys @@ -543,17 +554,18 @@ return False return (0 == statusCode) + def __writeRepositoryDetails(repo): """ Writes the details of a repository to the repository's - configuration file. + configuration file. - @param[in] repo The targeted repository for which to write the - configuration details. + @param[in] repo The targeted repository for which to write the + configuration details. - @post The HgWeb configuration file contains the new repository details and - is returned to a read-only state. + @post The HgWeb configuration file contains the new repository details and + is returned to a read-only state. - @return When the process is successful gives true, else-wise false. + @return When the process is successful gives true, else-wise false. """ import os import stat @@ -584,12 +596,13 @@ return False return True + def __guardWindowsRepository(repo): """ Guards the supplied repository for a repository on a Windows system. - @param[in] repo The targeted repository for which to secure. + @param[in] repo The targeted repository for which to secure. - @return When the process is successful gives true, else-wise false. + @return When the process is successful gives true, else-wise false. """ import subprocess import os @@ -598,20 +611,23 @@ print 'Securing for Windows ...' status = subprocess.call(["attrib.exe", '+H', '+I', '+S', settings.RepositoryPath + os.sep + repo.StorageName + os.sep + '.hg']) except OSError as e: + import sys + print >>sys.stderr, "Windows Guard error({0}): {1}".format(e.errno, e.strerror) return False return (0 == status) + def __registerRepository(repo): """ Adds the registration details of the repository. - @param[in] repo The targeted repository for which to register in HgWeb. + @param[in] repo The targeted repository for which to register in HgWeb. - @post The HgWeb configuration file contains the new repository details and - is returned to a read-only state. Upon any error the standard error - buffer contains an error message. + @post The HgWeb configuration file contains the new repository details and + is returned to a read-only state. Upon any error the standard error + buffer contains an error message. - @return When the process is successful gives true, else-wise false. + @return When the process is successful gives true, else-wise false. """ from ConfigParser import SafeConfigParser import os
--- a/src/manrepo.py Thu Aug 21 19:28:52 2014 -0500 +++ b/src/manrepo.py Thu Jan 08 18:58:03 2015 +0100 @@ -1,33 +1,34 @@ # -*- coding: utf-8 -*- -#******************************************************************************* -#** This file is part of HgWeb Manager. *** -#** *** -#** Copyright (C) 2014 *** -#** CodeGNU Solutions <Licensing _AT_ CodeGNU _DOT_ com> *** -#** *** -#** This program is free software: you can redistribute it and/or modify it *** -#** under the terms of the GNU Affero General Public License as published *** -#** by the Free Software Foundation, either version 3 of the License, or *** -#** (at your option) any later version. *** -#** *** -#** This program is distributed in the hope that it will be useful, but *** -#** WITHOUT ANY WARRANTY; without even the implied warranty of *** -#** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *** -#** See the GNU Affero General Public License for more details. *** -#** *** -#** You should have received a copy of the GNU Affero General Public License*** -#** along with this program. If not, see <http://www.gnu.org/licenses/>. *** -#******************************************************************************* +'''***************************************************************************** +*** This file is part of HgWeb Manager. *** +*** *** +*** Copyright (C) 2014 *** +*** CodeGNU Solutions <Licensing _AT_ CodeGNU _DOT_ com> *** +*** *** +*** This program is free software: you can redistribute it and/or modify it *** +*** under the terms of the GNU Affero General Public License as published *** +*** by the Free Software Foundation, either version 3 of the License, or *** +*** (at your option) any later version. *** +*** *** +*** This program is distributed in the hope that it will be useful, but *** +*** WITHOUT ANY WARRANTY; without even the implied warranty of *** +*** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *** +*** See the GNU Affero General Public License for more details. *** +*** *** +*** You should have received a copy of the GNU Affero General Public License*** +*** along with this program. If not, see <http://www.gnu.org/licenses/>. *** +*****************************************************************************''' + """ - IMPORTS +IMPORTS """ from hwm import settings class Repository(object): """ Describes the properties of a repository managed by HWM and served up - by HgWeb. + by HgWeb. """ # The directory name of the managed repository. @@ -41,7 +42,6 @@ # The Mercurial repository interface. __repo = None - @property def StorageName(self): """ Gets the name of the directory where the managed repository is located. """ @@ -51,6 +51,7 @@ def DisplayName(self): """ Gets the name to display for the managed repository. """ return self.__displayName + @DisplayName.setter def DisplayName(self, value): """ Sets the name of the managed repository to display. """ @@ -60,6 +61,7 @@ def Description(self): """ Gets the description of the managed repository. """ return self.__description + @Description.setter def Description(self, value): """ Sets the description of the managed repository to display. """ @@ -69,6 +71,7 @@ def Contact(self): """ Gets the contact point for the managed repository. """ return self.__contact + @Contact.setter def Contact(self, value): """ Sets the contact point for the managed repository. """ @@ -77,8 +80,8 @@ def __init__(self, repoName=None): """ Initialises the object with the values from a managed repository - @param[in] repoName The storage name of the managed repository - to load. + @param[in] repoName The storage name of the managed repository + to load. """ from mercurial import ui, hg, error import os @@ -96,20 +99,20 @@ def __eq__(self, other): """ Determines if two repositories are the same repository. - @param[in] other The repository on the right-hand-side of the - equality operator to compare against. + @param[in] other The repository on the right-hand-side of the + equality operator to compare against. - @return Gives true when both repositories represent the same one, - else-wise gives false. + @return Gives true when both repositories represent the same one, + else-wise gives false. """ return self.__storageName == other.__storageName def save(self): """ Commits the repository detail properties to the repository - configuration file. + configuration file. - @throws IOError When the configuration file for the repository - fails to be written. + @throws IOError When the configuration file for the repository + fails to be written. """ import os @@ -137,26 +140,24 @@ self.__contact = self.__repo.ui.config('web', 'contact', default=None) - class ManagedCollection(object): """ A container of all the managed repositories. """ # All the managed repositories __repositories = [] - @property def Repositories(self): """A collection of all managed repositories. - @return An array of the managed repositories. + @return An array of the managed repositories. """ return self.__repositories def __init__(self): """ Initialises the container with all the managed repositories. - @throws Exception When the HgWeb configuration cannot be read. + @throws Exception When the HgWeb configuration cannot be read. """ from ConfigParser import SafeConfigParser import os @@ -165,5 +166,5 @@ if not parser.read(settings.HgWebPath + os.sep + 'hgweb.config'): raise Exception("Failed to read HgWeb configuration.") - for name,path in parser.items('paths'): + for name, path in parser.items('paths'): self.__repositories.append(Repository(name))