summarylogtreecommitdiffstats
path: root/0002-Support-osc-copyprj-in-api-by-Islam-Amer-usage-osc-c.patch
blob: 490830a7e81ec32b2adcf473e47e3c0f7d80ab71 (plain)
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
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Marko Lemmetty <marko.lemmetty@jollamobile.com>
Date: Fri, 15 May 2020 14:20:54 +0300
Subject: [PATCH] Support 'osc copyprj' in api by Islam Amer usage: osc copyprj
 SOURCEPRJ DESTPRJ

    A way to copy a project and all packages in it
    It can not yet be done across buildservice instances
    The user must be able to create DESTPRJ
---
 osc/commandline.py | 55 +++++++++++++++++++++++++++++++++++++++++++++-
 osc/core.py        | 28 +++++++++++++++++++++++
 2 files changed, 82 insertions(+), 1 deletion(-)

diff --git a/osc/commandline.py b/osc/commandline.py
index e00d6e68ea4eb96e8eefa14e177934a247de9b6e..2a62febd422a1afcc37a49b3817df20778bc1bbe 100644
--- a/osc/commandline.py
+++ b/osc/commandline.py
@@ -3120,7 +3120,7 @@ Please submit there instead, or use --nodevelproject to force direct submission.
         if opts.repo:
             query["repository"] = opts.repo
         if opts.set_release:
-            query["setrelease"] = opts.set_release
+-            query["setrelease"] = opts.set_release
         if opts.no_delay:
             query["nodelay"] = "1"
         baseurl = ['source', source_project]
@@ -3134,6 +3134,59 @@ Please submit there instead, or use --nodevelproject to force direct submission.
                 break
             sys.stdout.write(decode_it(buf))
 
+    @cmdln.option('-b', '--with-binaries', action='store_true',
+                        help='copy the built binaries over to avoid a rebuild')
+    @cmdln.option('-x', '--with-history', action='store_true',
+                        help='replicate the history of each package.')
+    @cmdln.option('-o', '--make-older', action='store_true',
+                        help='No idea')
+    @cmdln.option('-r', '--re-sign', action='store_true',
+                        help='re-sign the binaries')
+    @cmdln.option('-m', '--message', metavar='TEXT',
+                  help='specify message TEXT')
+    def do_copyprj(self, subcmd, opts, *args):
+        """${cmd_name}: Copy a project
+
+        A way to copy a project and all packages in it
+
+        It can not yet be done across buildservice instances
+
+        The user must be able to create DESTPRJ
+
+        usage:
+            osc copyprj SOURCEPRJ DESTPRJ
+        ${cmd_option_list}
+        """
+
+        args = slash_split(args)
+
+        if not args or len(args) != 2:
+            raise oscerr.WrongArgs('Incorrect number of arguments.\n\n' \
+                  + self.get_cmd_help('copypac'))
+
+        src_project = args[0]
+        dst_project = args[1]
+
+        src_apiurl = conf.config['apiurl']
+
+        if opts.message:
+            comment = opts.message
+        else:
+            comment = 'osc copyprj from project:%s' % ( src_project )
+
+        if src_project == dst_project:
+            raise oscerr.WrongArgs('Source and destination are the same.')
+
+        print("calling cp")
+        r = copy_prj(src_apiurl, src_project, dst_project,
+                     withbinaries = opts.with_binaries,
+                     withhistory = opts.with_history,
+                     makeolder = opts.make_older,
+                     resign = opts.re_sign,
+                     comment = comment)
+        print("done cp")
+        print(r)
+
 
     @cmdln.option('-m', '--message', metavar='TEXT',
                   help='specify message TEXT')
diff --git a/osc/core.py b/osc/core.py
index 2ef744296c65e43adfb0ea60cd0a203ac7173e2c..a3c45884eadc729cc785dd7c9cc3e5723c516b92 100644
--- a/osc/core.py
+++ b/osc/core.py
@@ -5549,6 +5549,34 @@ def copy_pac(src_apiurl, src_project, src_package,
             raise oscerr.APIError('failed to copy: %s' % ', '.join(todo))
         return 'Done.'
 
+def copy_prj(src_apiurl, src_project, dst_project,
+             withbinaries = False,
+             withhistory = False,
+             makeolder = False,
+             resign = False,
+             comment = None):
+    """
+    Create a copy of a project.
+
+    Copying can only be done on the server, in a single api call.
+    """
+
+    print('Copying project...')
+    query = {'cmd': 'copy', 'oproject': src_project }
+    if withbinaries:
+        query['withbinaries'] = '1'
+    if withhistory:
+        query['withhistory'] = '1'
+    if makeolder:
+        query['makeolder'] = '1'
+    if resign:
+        query['resign'] = '1'
+    if comment:
+        query['comment'] = comment
+    u = makeurl(src_apiurl, ['source', dst_project], query=query)
+    print("copyprj ", u, file=sys.stderr)
+    f = http_POST(u)
+    return f.read()
 
 def unlock_package(apiurl, prj, pac, msg):
     query = {'cmd': 'unlock', 'comment': msg}