~cprov/uci-engine/tarmac-multienv

« back to all changes in this revision

Viewing changes to cupstream2distro/tests/mocks/offline/sudo

  • Committer: Francis Ginther
  • Date: 2014-06-10 20:42:46 UTC
  • mto: This revision was merged to the branch mainline in revision 571.
  • Revision ID: francis.ginther@canonical.com-20140610204246-b1bsrik7nlcolqy7
Import lp:cupstream2distro rev 605.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env python
 
2
# -*- coding: utf-8 -*-
 
3
# Copyright: (C) 2013 Canonical
 
4
#
 
5
# Authors:
 
6
#  Didier Roche
 
7
#
 
8
# This program is free software; you can redistribute it and/or modify it under
 
9
# the terms of the GNU General Public License as published by the Free Software
 
10
# Foundation; version 3.
 
11
#
 
12
# This program is distributed in the hope that it will be useful, but WITHOUT
 
13
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 
14
# FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
 
15
# details.
 
16
#
 
17
# You should have received a copy of the GNU General Public License along with
 
18
# this program; if not, write to the Free Software Foundation, Inc.,
 
19
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
20
 
 
21
import os
 
22
import shutil
 
23
import sys
 
24
 
 
25
def copy_data_file(filename, dest, dest_filename=None):
 
26
    '''copy filename to dest'''
 
27
    if dest_filename:
 
28
        dest = os.path.join(dest, dest_filename)
 
29
    shutil.copy(os.path.join(os.path.dirname(__file__), 'data', filename), dest)
 
30
 
 
31
if __name__ == '__main__':
 
32
 
 
33
 
 
34
    if os.environ.get("MOCK_ERROR_MODE") == "1":
 
35
        sys.exit(1)
 
36
 
 
37
    args = sys.argv
 
38
    command = " ".join(args[1:])
 
39
    if command.startswith("-E cowbuilder --execute"):
 
40
        # check we have two bindmounts
 
41
        if (sys.argv[1:].count("--bindmounts") != 2):
 
42
            sys.exit(1)
 
43
 
 
44
        if args[18] == "invalidkey":
 
45
            sys.exit(1)
 
46
 
 
47
        dest_dir = args[5]
 
48
        distro_version = args[20]
 
49
        serie = os.environ['DIST']
 
50
 
 
51
        # this mode should have the ppa call
 
52
        if os.environ.get("MOCK_MODE") == "1":
 
53
            if "--ppa ubuntu-unity/next" in command:
 
54
                copy_data_file("foo_1.2-0ubuntu1_source.changes.lastcontent", dest_dir, dest_filename="foo_1.2-0ubuntu1_source.changes")
 
55
                sys.exit(0)
 
56
 
 
57
        else:
 
58
            if serie == "precise":
 
59
                copy_data_file("foo_1.2-0ubuntu1_source.changes.onprecise", dest_dir, dest_filename="foo_1.2-0ubuntu1_source.changes")
 
60
                sys.exit(0)
 
61
            elif serie == "raring":
 
62
                if distro_version == "1.1-0ubuntu1":
 
63
                    copy_data_file("foo_1.2-0ubuntu1_source.changes.lastcontent", dest_dir, dest_filename="foo_1.2-0ubuntu1_source.changes")
 
64
                    sys.exit(0)
 
65
                elif distro_version == "1.0-0ubuntu1":
 
66
                    copy_data_file("foo_1.2-0ubuntu1_source.changes.sincedistroversion", dest_dir, dest_filename="foo_1.2-0ubuntu1_source.changes")
 
67
                    sys.exit(0)
 
68
 
 
69
    # unhandled case
 
70
    sys.exit(1)