Revision 866bb9c1 devflow/autopkg.py

b/devflow/autopkg.py
37 37
from sh import mktemp, cd, rm, git_dch, python
38 38
from optparse import OptionParser
39 39

  
40
from devflow.versioning import (get_python_version,
41
                                debian_version_from_python_version)
42

  
40 43
try:
41 44
    from colors import red, green
42 45
except ImportError:
......
55 58

  
56 59
def main():
57 60
    from devflow.version import __version__
58

  
59 61
    parser = OptionParser(usage="usage: %prog [options] mode",
60
                          version="%prog - devflow %s" % __version__)
62
                          version="devflow %s" % __version__)
61 63
    parser.add_option("-k", "--keep-repo",
62 64
                      action="store_true",
63 65
                      dest="keep_repo",
......
79 81

  
80 82
    (options, args) = parser.parse_args()
81 83

  
82
    mode = args[0]
84
    try:
85
        mode = args[0]
86
    except IndexError:
87
        raise ValueError("Mode argument is mandatory. Usage: %s"
88
                         % parser.usage)
83 89
    if mode not in AVAILABLE_MODES:
84 90
        raise ValueError(red("Invalid argument! Mode must be one: %s"
85 91
                         % ", ".join(AVAILABLE_MODES)))
......
118 124
        repo.references[debian_branch]
119 125
    except IndexError:
120 126
        # Branch does not exist
121
        # FIXME: remove hard-coded strings..
122
        if branch == "debian":
123
            repo.git.branch("--track", debian_branch, "origin/debian")
124
        else:
125
            repo.git.branch("--track", debian_branch, "origin/debian-develop")
127
        repo.git.branch("--track", debian_branch, "origin/" + debian_branch)
126 128

  
127 129
    repo.git.checkout(debian_branch)
128 130
    print_green("Changed to branch '%s'" % debian_branch)
......
131 133
    print_green("Merged branch '%s' into '%s'" % (branch, debian_branch))
132 134

  
133 135
    cd(repo_dir)
134
    version = python(repo_dir + "/devflow/version.py", "debian").strip()
135
    print_green("The new debian version will be: '%s'" % version)
136
    python_version = get_python_version()
137
    debian_version = debian_version_from_python_version(python_version)
138
    print_green("The new debian version will be: '%s'" % debian_version)
136 139

  
137 140
    dch = git_dch("--debian-branch=%s" % debian_branch,
138 141
            "--git-author",
139 142
            "--ignore-regex=\".*\"",
140 143
            "--multimaint-merge",
141 144
            "--since=HEAD",
142
            "--new-version=%s" % version)
145
            "--new-version=%s" % debian_version)
143 146
    print_green("Successfully ran '%s'" % " ".join(dch.cmd))
144 147

  
145
    os.system("vim debian/changelog")
146 148
    repo.git.add("debian/changelog")
147 149

  
148 150
    if mode == "release":
151
        os.system("vim debian/changelog")
152
        repo.git.add("debian/changelog")
149 153
        repo.git.commit("-s", "-a", "-m", "Bump new upstream version")
150
        if branch == "master":
151
            repo.git.tag("debian/" + version)
154
        python_tag = python_version
155
        debian_tag = "debian/" + python_tag
156
        repo.git.tag(debian_tag)
157
        repo.git.tag(python_tag, branch)
152 158

  
153 159
    for package in PACKAGES:
154 160
        # python setup.py should run in its directory
155 161
        cd(package)
156 162
        package_dir = repo_dir + "/" + package
157 163
        res = python(package_dir + "/setup.py", "sdist", _out=sys.stdout)
158
        cd("../")
159 164
        print res.stdout
165
        if package != ".":
166
            cd("../")
160 167

  
161 168
    # Add version.py files to repo
162 169
    os.system("grep \"__version_vcs\" -r . -l -I | xargs git add -f")
......
167 174
        print_green("Created directory '%s' to store the .deb files." %
168 175
                     build_dir)
169 176

  
177
    cd(repo_dir)
170 178
    os.system("git-buildpackage --git-export-dir=%s --git-upstream-branch=%s"
171 179
              " --git-debian-branch=%s --git-export=INDEX --git-ignore-new -sa"
172 180
              % (build_dir, branch, debian_branch))
......
178 186
        print_green("Repository dir '%s'" % repo_dir)
179 187

  
180 188
    print_green("Completed. Version '%s', build area: '%s'"
181
                % (version, build_dir))
189
                % (debian_version, build_dir))
190

  
191
    if mode == "release":
192
        TAG_MSG = "Tagged branch %s with tag %s\n"
193
        print_green(TAG_MSG % (branch, python_tag))
194
        print_green(TAG_MSG % (debian_branch, debian_tag))
195

  
196
        UPDATE_MSG = "To update repository %s, go to %s, and run the"\
197
                     " following commands:\n" + "git_push origin %s\n" * 3
198

  
199
        origin_url = repo.remotes['origin'].url
200
        remote_url = original_repo.remotes['origin'].url
201

  
202
        print_green(UPDATE_MSG % (origin_url, repo_dir, debian_branch,
203
                    debian_tag, python_tag))
204
        print_green(UPDATE_MSG % (remote_url, original_repo.working_dir,
205
                    debian_branch, debian_tag, python_tag))
182 206

  
183 207

  
184 208
if __name__ == "__main__":

Also available in: Unified diff