1 import os
2 import subprocess
3 from subprocess import Popen
4
5 from .helpers import get_auto_createrepo_status
6
7
9 """
10 Run createrepo_c on the given path
11
12 Warning! This function doesn't check user preferences.
13 In most cases use `createrepo(...)`
14
15 :param string path: target location to create repo
16 :param lock: [optional]
17 :param str dest_dir: [optional] relative to path location for repomd, in most cases
18 you should also provide base_url.
19 :param str base_url: optional parameter for createrepo_c, "--baseurl"
20
21 :return tuple: (return_code, stdout, stderr)
22 """
23
24 comm = ['/usr/bin/createrepo_c', '--database', '--ignore-lock']
25 if os.path.exists(path + '/repodata/repomd.xml'):
26 comm.append("--update")
27 if "epel-5" in path:
28
29 comm.extend(['-s', 'sha', '--checksum', 'md5'])
30
31 if dest_dir:
32 dest_dir_path = os.path.join(path, dest_dir)
33 comm.extend(['--outputdir', dest_dir_path])
34 if not os.path.exists(dest_dir_path):
35 os.makedirs(dest_dir_path)
36
37 if base_url:
38 comm.extend(['--baseurl', base_url])
39
40 comm.append(path)
41
42 if lock:
43 with lock:
44 cmd = Popen(comm, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
45 out, err = cmd.communicate()
46 else:
47 cmd = Popen(comm, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
48 out, err = cmd.communicate()
49
50 return cmd.returncode, out, err
51
52
53 -def createrepo(path, front_url, username, projectname, base_url=None, lock=None):
54 """
55 Creates repo depending on the project setting "auto_createrepo".
56 When enabled creates `repodata` at the provided path, otherwise
57
58 :param path: directory with rpms
59 :param front_url: url to the copr frontend
60 :param username: copr project owner username
61 :param projectname: copr project name
62 :param base_url: base_url to access rpms independently of repomd location
63 :param Multiprocessing.Lock lock: [optional] global copr-backend lock
64
65 :return: tuple(returncode, stdout, stderr) produced by `createrepo_c`
66 """
67
68
69 base_url = base_url or ""
70
71 if get_auto_createrepo_status(front_url, username, projectname):
72 return createrepo_unsafe(path, lock)
73 else:
74 return createrepo_unsafe(path, lock, base_url=base_url, dest_dir="devel")
75