~jcsackett/charmworld/bac-tag-constraints

« back to all changes in this revision

Viewing changes to charmworld/jobs/lp.py

  • Committer: Aaron Bentley
  • Date: 2013-02-12 18:57:02 UTC
  • mfrom: (149 charmworld)
  • mto: This revision was merged to the branch mainline in revision 150.
  • Revision ID: aaron@canonical.com-20130212185702-9gnf40ao17a7uw7v
Merged trunk into mongo-urls.

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
# licensed under the GNU Affero General Public License version 3 (see
3
3
# the file LICENSE).
4
4
 
5
 
import urllib
6
 
import json
7
5
import logging
8
6
 
9
 
from utils import parse_branch
10
 
 
11
 
from config import CHARM_IMPORT_FILTER
12
 
from config import CHARM_IMPORT_LIMIT
13
7
from config import LP_OUT_QUEUE
14
8
from utils import get_queues
15
 
 
16
 
BRANCH_TIPS = "https://api.launchpad.net/devel/charm?ws.op=getBranchTips"
17
 
CHARM_DIR = ""
18
 
 
19
 
log = logging.getLogger("charm.launchpad")
20
 
 
21
 
 
22
 
def available_charms(charm_data=None):
23
 
    if not charm_data:
24
 
        charm_data = urllib.urlopen(BRANCH_TIPS).read()
25
 
        charm_data = json.loads(charm_data)
26
 
 
27
 
    count = 0
28
 
 
29
 
    for repo, commit, series in charm_data:
30
 
        _, branch_name = repo.rsplit("/", 1)
31
 
 
32
 
        try:
33
 
            data = parse_branch(repo, series, commit)
34
 
        except ValueError:
35
 
            log.warning("Unable to parse repo %s", repo)
36
 
            continue
37
 
 
38
 
        if CHARM_IMPORT_FILTER and not data['branch_spec'].startswith(
39
 
                CHARM_IMPORT_FILTER):
40
 
            continue
41
 
 
42
 
        if data["bname"] not in ("trunk", "trunk-1"):
43
 
            log.debug("Skipped branch %s", repo)
44
 
            continue
45
 
 
46
 
        log.info("Queueing %s", data['branch_spec'])
47
 
        yield data
48
 
 
49
 
        count += 1
50
 
 
51
 
        if CHARM_IMPORT_LIMIT and count >= CHARM_IMPORT_LIMIT:
52
 
            log.info("Import limit reached (%d)... stopping",
53
 
                     CHARM_IMPORT_LIMIT)
54
 
            break
55
 
 
56
 
 
57
 
def queue_charms(out_queue):
58
 
    for charm in available_charms():
59
 
        added = out_queue.put(charm)
60
 
        if added and 0:
61
 
            log.info("Queued %s", charm)
62
 
 
63
 
 
64
 
def main():
 
9
from worker import queue_charms
 
10
 
 
11
 
 
12
if __name__ == '__main__':
65
13
    logging.basicConfig(
66
14
        level=logging.INFO,
67
15
        format="%(asctime)s: %(name)s@%(levelname)s: %(message)s")
68
16
    out_queue = get_queues(LP_OUT_QUEUE)
69
17
    queue_charms(out_queue)
70
 
 
71
 
 
72
 
if __name__ == '__main__':
73
 
    main()