[MQ-PATCH] ditrack: dt-create-db-support-for-null-backend

Vlad Skvortsov vss at 73rus.com
Sun Jul 8 16:01:34 PDT 2007


Stefan Reichör wrote:
> Hi!
>
> This is my first patch for ditrack ;-)
>
> It adds support for the null backend in dt-createdb
>   

Hey, good start, Stefan! :-)

I've got several comments on the patch.

* Try to separate format changes from functionality changes. I've 
removed the whitespace in r1677.

* The usage note should prominently say if the directory specified 
should exist or will be created by the script.

* Due to indentation in the source, the contents of configuration files 
are also indented (see etc/categories, for example).

* I suggest that the usage note listing the available backends is 
generated based on 'supported_backends' list.

* Updating testcases is also highly desirable, though I don't yet have a 
clear picture on how we want to test against various backends. This is a 
topic for another thread though.

>
> Stefan.
>
>   
> ------------------------------------------------------------------------
>
> diff -r b2f6319d8ad2 dt-createdb
> --- a/dt-createdb	Fri Jul 06 21:30:34 2007 +0200
> +++ b/dt-createdb	Fri Jul 06 23:13:55 2007 +0200
> @@ -7,25 +7,25 @@
>  # $Id: dt-createdb 1669 2007-06-20 18:52:45Z gli $
>  # $HeadURL: http://svn.xiolabs.com/ditrack/src/trunk/dt-createdb $
>  #
> -# Redistribution and use in source and binary forms, with or without 
> +# Redistribution and use in source and binary forms, with or without
>  # modification, are permitted provided that the following conditions are met:
>  #
> -#  * Redistributions of source code must retain the above copyright notice, 
> +#  * Redistributions of source code must retain the above copyright notice,
>  # this list of conditions and the following disclaimer.
> -#  * Redistributions in binary form must reproduce the above copyright notice, 
> -# this list of conditions and the following disclaimer in the documentation 
> +#  * Redistributions in binary form must reproduce the above copyright notice,
> +# this list of conditions and the following disclaimer in the documentation
>  # and/or other materials provided with the distribution.
>  #
> -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 
> -# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
> -# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
> -# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 
> -# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 
> -# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
> -# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 
> -# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
> -# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
> -# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
> +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
> +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
> +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
> +# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
> +# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
> +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
> +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
> +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
> +# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
> +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
>  # POSSIBILITY OF SUCH DAMAGE.
>  #
>  
> @@ -39,90 +39,103 @@ def mkdir(path):
>          sys.stdout.write("Failed to mkdir '%s'\n" % path)
>          sys.exit(1)
>  
> +def init_ditrack_db(dbdir):
> +    mkdir(dbdir)
> +    mkdir("%s/data" % dbdir)
> +    mkdir("%s/etc" % dbdir)
> +    mkdir("%s/meta" % dbdir)
> +
> +    open("%s/README.txt" % dbdir, "w").write(
> +    """This is an issue database maintained by DITrack.
> +    Check out http://www.ditrack.org/ for more information.
> +    """
> +    )
> +
> +    open("%s/etc/categories" % dbdir, "w").write(
> +    """Category: sample
> +    Default-owner: sample-user
> +    Version-set: sample-versions-set
> +    """
> +    )
> +
> +    open("%s/etc/filters" % dbdir, "w").write(
> +    """sample-filter: Status=open,Owned-by=sample-user
> +    """
> +    )
> +
> +    open("%s/etc/users" % dbdir, "w").write(
> +    """sample-user
> +    """
> +    )
> +
> +    open("%s/etc/versions" % dbdir, "w").write(
> +    """sample-versions-set: 0.1 0.2 / 0.3 0.4 / 0.5 0.6
> +    """
> +    )
> +
> +    open("%s/meta/next-id" % dbdir, "w").write("1\n")
> +
> +def ditrack_add_to_svn(dbdir):
> +    if os.system("svn add -q %s" % dbdir):
> +        sys.stdout.write("Can't schedule '%s' for addition\n" % dbdir)
> +        sys.exit(1)
> +
> +    if os.system("svn ps ditrack:format 2 %s" % dbdir):
> +        sys.stdout.write("Can't initialize format field\n")
> +        sys.exit(1)
> +
> +    if os.system("svn ps svn:ignore .ditrack %s" %dbdir):
> +        sys.stdout.write("Can't set the ignore list\n")
> +        sys.exit(1)
> +
> +
>  #############################################################################
>  # ENTRY POINT                                                               #
>  #############################################################################
>  
> -if len(sys.argv) != 4:
> +if len(sys.argv) > 1:
> +    dbdir = sys.argv[1]
> +
> +if len(sys.argv) == 3:
> +    backend_type = sys.argv[2]
> +else:
> +    backend_type = "none"
> +
> +supported_backends = ["svn", "none"]
> +if backend_type not in supported_backends:
> +    sys.stdout.write("Error: unsupported backend %s, supported backends are: %s\n" % (backend_type, supported_backends))
> +    sys.exit(1)
> +
> +if len(sys.argv) not in [2, 3]:
>      sys.stdout.write(
>          """Syntax:
> -    %s <repository-url> <issue-db-dir> <local-wc>
> +    %s <issue-db-dir> [ditrack-backend-type]
>  
> -The script non-recursively checks out <repository-url> into <local-wc> (which
> -should not exist), creates <issue-db-dir> there and schedules it for addition.
> +Create a ditrack issue database in <issue-db-dir>
> +ditrack-backend-type can be one of: svn, none
> +The default ditrack-backend-type is none.
>  
> +IMPORTANT NOTE: the null backend 'none' is not fully supported yet!
>  """ % os.path.basename(sys.argv[0]))
>      sys.exit(1)
>  
> -(repo, dbdir, localwc) = sys.argv[1:4]
>  
> -if os.path.exists(localwc):
> -    sys.stdout.write("'%s' already exists\n" % localwc)
> +if os.path.exists(dbdir):
> +    sys.stdout.write("'%s' already exists\n" % dbdir)
>      sys.exit(1)
>  
> -if os.system("svn co -Nq %s %s" % (repo, localwc)):
> -    sys.stdout.write("Can't check out working copy to %s\n" % localwc)
> -    sys.exit(1)
>  
> -dbdir = os.path.join(localwc, dbdir)
> +init_ditrack_db(dbdir)
>  
> -mkdir(dbdir)
> -mkdir("%s/data" % dbdir)
> -mkdir("%s/etc" % dbdir)
> -mkdir("%s/meta" % dbdir)
> +if backend_type == "svn":
> +    ditrack_add_to_svn(dbdir)
>  
> -open("%s/README.txt" % dbdir, "w").write(
> -"""This is an issue database maintained by DITrack.
> -Check out http://www.ditrack.org/ for more information.
> -"""
> -)
> +sys.stdout.write("Empty issue database created in '%s'\n" % dbdir)
>  
> -open("%s/etc/categories" % dbdir, "w").write(
> -"""Category: sample
> -Default-owner: sample-user
> -Version-set: sample-versions-set
> -"""
> -)
> +if backend_type == "svn":
> +    sys.stdout.write("""
> +    Now you should probably type something like:
>  
> -open("%s/etc/filters" % dbdir, "w").write(
> -"""sample-filter: Status=open,Owned-by=sample-user
> -"""
> -)
> +    svn commit %s
>  
> -open("%s/etc/users" % dbdir, "w").write(
> -"""sample-user
> -"""
> -)
> -
> -open("%s/etc/versions" % dbdir, "w").write(
> -"""sample-versions-set: 0.1 0.2 / 0.3 0.4 / 0.5 0.6
> -"""
> -)
> -
> -open("%s/meta/next-id" % dbdir, "w").write("1\n")
> -
> -if os.system("svn add -q %s" % dbdir):
> -    sys.stdout.write("Can't schedule '%s' for addition\n" % dbdir)
> -    sys.exit(1)
> -
> -
> -if os.system("svn ps ditrack:format 2 %s" % dbdir):
> -    sys.stdout.write("Can't initialize format field\n")
> -    sys.exit(1)
> -
> -
> -if os.system("svn ps svn:ignore .ditrack %s" %dbdir):
> -    sys.stdout.write("Can't set the ignore list\n")
> -    sys.exit(1)
> -
> -
> -
> -sys.stdout.write("""
> -Empty issue database created at:
> -'%s'
> -
> -Now you should probably type something like:
> -
> -svn commit %s
> -
> -""" % (dbdir, dbdir))
> +    """ % dbdir)
>   
> ------------------------------------------------------------------------
>
> _______________________________________________
> Dev mailing list
> Dev at lists.ditrack.org
> http://lists.ditrack.org/mailman/listinfo/dev
>   


-- 
Vlad Skvortsov, vss at 73rus.com, http://vss.73rus.com



More information about the Dev mailing list