staging.inyokaproject.org

MakeBranchDist - Alle Dateien eines Zweigs versandfertig packen

Status: Ungelöst | Ubuntu-Version: Nicht spezifiziert
Antworten |

domachine

Anmeldungsdatum:
16. Mai 2007

Beiträge: 562

Hallo UUsers,

ich habe ein kleines script entworfen, das ich mittlerweile bei der täglichen Arbeit nicht mehr missen will.

Das Prinzip ist einfach. Es werden alle versions-kontrollierten Dateien eines Bazaar-Zweiges ausgemacht und zusammengepackt. Dabei gibts noch ein kleines Gimmick, das mir als SVN-Umsteiger die Arbeit ebenfalls erleichtert.

Das Skript sucht Textdateien, deren erste Zeile folgende Form hat:

// $Id$
  ... oder ...
# $Id$

Leezeichen sind dabei weitestgehend wurscht. Diese Zeilen werden durch RCS-ähnliche Id-Felder ersetzt (Das Kommentarzeichen bleibt natürlich erhalten). Falls eine Datei solch eine Zeile nicht enthält wird sie einfach vollständig ins Zielverzeichnis kopiert.

Das wird übrigens vorher nach folgendem Schema angelegt: <branch_nick>-r<revisions_nummer>.

Das Script ist ziemlich "Quick&Dirty". Optionen werden nicht unterstützt. Das Script muss aus dem Verzeichnis ausgerufen werden in dem auch der Branch liegt.

Zur Verwendung müssen Bazaar und Perl 5.x installiert sein.

Vielleicht findet ja jemand gefallen dran.

Gruß Domi

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#!/usr/bin/perl -w
# Copyright (C) 2010  Dominik Burgdörfer

# MakeBranchDist 0.1.2 -- This program creates a distribution
#                         based on a bzr-branch. It also searches
#                         for headers in files in the following form:
#                           # $Id$
#                           // $Id$
#
#                         These headers replaced by RCS-like Id-fields.

# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU 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 General Public License for more details.

# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

use strict;
use File::Basename;
use File::Path qw(make_path remove_tree);
use File::Copy;

# Functions to handle bazaar-vcs
package Bzr;

# Returns a hash with info about the
# branch in the current directory.
sub version_info {
    my $bzr = defined($_[0]) ? $_[0] : "bzr";

    my $info_hash = {};

    my $bzr_cmd = "'$bzr' version-info --custom ".
        "--template ".
        "'my \$info_hash = {}; \$info_hash->{\"date\"}='\\''{date}'\\'';".
        "\$info_hash->{\"build_date\"}='\\''{build_date}'\\'';".
        "\$info_hash->{\"revno\"}={revno};".
        "\$info_hash->{\"revision_id\"}='\\''{revision_id}'\\'';".
        "\$info_hash->{\"branch_nick\"}='\\''{branch_nick}'\\'';".
        "\$info_hash->{\"clean\"}={clean};\$info_hash;'";

    # Evaluate the output of bazaar.
    $info_hash = eval(`$bzr_cmd`);
    die($@) if(!$info_hash);

    # Return the hash
    $info_hash;
}

# Returns an array of all versioned files in
# the current directory.
# TODO: Probably not the best solution to pack
#       all files in one big array. Should be
#       replaced with a file-descriptor.
sub versioned_files {
    open(BZR_HANDLE, "bzr ls --versioned -R |") ||
        warn("unable to launch bzr");

    if(wantarray) {
        return <BZR_HANDLE>;
    }
    else {
        return scalar(<BZR_HANDLE>);
    }
}


package main;

my $version_info;
my @versioned_files;

# Retrieve information about the current branch
if(-d ".bzr") {
    $version_info = Bzr::version_info();
    @versioned_files = Bzr::versioned_files();
}
elsif(-d ".svn") {
    die("svn is not yet implemented");
}
else {
    die("could not determine used version-control system.");
}

# Little goodie :-D. Check if the tree has
# uncommitted changes. Maybe useless but looks
# cool :-D
if(!$version_info->{clean}) {
    print STDERR "tree has uncommitted changes.\n";
}

# Create release-directory.
my $release_dir = $version_info->{branch_nick}."-r".
    $version_info->{revno};

-d $release_dir && remove_tree($release_dir);

make_path($release_dir);


# Iterate through all versioned files, to eventually
# edit them and copy to the release-directory.
for(@versioned_files) {
    chomp;
    
    if(-f) {
        open(FILE, "<", $_) || die("unable to read $_: $!");

        my $new_path = $release_dir."/".$_;
        make_path(dirname($new_path));

        my $firstLine = <FILE>;
        chomp($firstLine);

        # Check if first line is an id-comment-line.
        # If so replace it with information about the branch.
        if($firstLine =~ /^([ \t]*(#|\/\/)[ \t]*)\$Id\$[ \t]*$/) {
            open(NEW_FILE, ">", $new_path) ||
                die("unable to create $new_path: $!");

            printf NEW_FILE "$1\$Id: %s %d %s \$\n", basename($_),
                                                     $version_info->{revno},
                                                     $version_info->{build_date};

            while(<FILE>) {
                print NEW_FILE $_;
            }
            
            close(NEW_FILE);
        }
        else {
            # No modifications to do, just copy the file to
            # the release-directory.
            copy($_, $release_dir."/".dirname($_));
        }
    }
}
Antworten |