Welcome to mirror list, hosted at ThFree Co, Russian Federation.

mkmaintdir « calm - cygwin.com/git/cygwin-apps/calm.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 88c385acc5aada873818580e9f9105f8450590f7 (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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
#!/usr/bin/env python3
#
# Copyright (c) 2015 Jon Turney
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
#

#
# create maintainer upload directories
#
# a re-implementation of the mkpkgdir perl script in python
# intended to be run from crontab every 5 minutes
#
# - Read existing maintainer directories, build a list of maintainer
# - Read cygwin-pkg-maint, add to list of maintainers, and build a list of
#   packages for each maintainer
# - Assign orpahaned packages to the project lead(s)
# - For each maintainer, create a home directory, set permissions, and write a
#   !packages file
# - Report if the maintainer has no packages and mark with !defunct
#

import argparse
import grp
import logging
import os
import pwd
import re
import sys

import common_constants
import maintainers

#
#
#

cygwin_uid = pwd.getpwnam('cygwin').pw_uid
cygstage_gid = grp.getgrnam('cygstage').gr_gid

# different values to be used when we are not running on sourceware.org, but my
# test system...
if os.uname()[1] == 'tambora':
    cygwin_uid = pwd.getpwnam('jon').pw_uid
    cygstage_gid = grp.getgrnam('None').gr_gid


#
#
#

def main(args):
    # clear the umask in case it is set
    os.umask(0)

    # create maintainer list
    mlist = {}
    mlist = maintainers.add_directories(mlist, args.homedir)
    mlist = maintainers.add_packages(mlist, args.pkglist, args.orphanmaint)

    # create or suggest removal for each maintainer directory
    for name in sorted(mlist.keys()):
        m = mlist[name]
        dirpath = m.homedir()

        # if the path exists, but isn't a directory
        if os.path.exists(dirpath) and not os.path.isdir(dirpath):
            logging.error("%s exists and isn't a directory!" % dirpath)
            continue

        # ensure the upload directory exists, with appropriate permissions, owner and contents
        logging.info('processing %s' % dirpath)
        if not args.dryrun:
            os.makedirs(dirpath, exist_ok=True)
            os.chown(dirpath, cygwin_uid, cygstage_gid)
            os.chmod(dirpath, 0o2775)
            # write !packages file (we don't use this for anything anymore, but
            # keep it around for information)
            with open(os.path.join(dirpath, '!packages'), 'w') as fd:
                os.fchown(fd.fileno(), cygwin_uid, cygstage_gid)
                print('|'.join([re.escape(p) for p in m.pkgs]), file=fd)
            # and create arch subdirectories, with appropriate owner
            for subdir in common_constants.ARCHES:
                os.makedirs(os.path.join(dirpath, subdir, 'release'), exist_ok=True)
                os.chown(os.path.join(dirpath, subdir, 'release'), cygwin_uid, cygstage_gid)

        # create/remove !defunct as appropriate
        defunct = os.path.join(dirpath, '!defunct')
        if len(m.pkgs) == 0:
            # if they have no packages, suggest removing their upload directory (once)
            if not os.path.exists(defunct):
                logging.warning("defunct maintainer %s, consider removing their directory?" % name)
                if not args.dryrun:
                    open(defunct, 'w').close()
        else:
            # remove defunct marker if no longer defunct
            if os.path.exists(defunct):
                logging.info("maintainer %s no longer defunct" % name)
                if not args.dryrun:
                    os.unlink(defunct)


#
#
#

if __name__ == "__main__":
    homedir_default = common_constants.HOMEDIR
    orphanmaint_default = common_constants.ORPHANMAINT
    pkglist_default = common_constants.PKGMAINT

    parser = argparse.ArgumentParser(description='Create maintainer upload directories')
    parser.add_argument('--homedir', action='store', metavar='DIR', help="maintainer home directory (default: " + homedir_default + ")", default=homedir_default)
    parser.add_argument('--orphanmaint', action='store', metavar='NAMES', help="orphan package maintainers (default: '" + orphanmaint_default + "')", default=orphanmaint_default)
    parser.add_argument('--pkglist', action='store', metavar='FILE', help="package maintainer list (default: " + pkglist_default + ")", default=pkglist_default)
    parser.add_argument('-n', '--dry-run', action='store_true', dest='dryrun', help="don't do anything")
    parser.add_argument('-v', '--verbose', action='count', dest='verbose', help='verbose output')
    (args) = parser.parse_args()

    if args.verbose:
        logging.getLogger().setLevel(logging.INFO)

    logging.basicConfig(format=os.path.basename(sys.argv[0]) + ': %(message)s')

    main(args)