aboutsummaryrefslogtreecommitdiff
path: root/releaselog/input.py
blob: 138ba1622af910c66355f687f8d9a18e5ad0aa8d (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
# -*- coding: utf-8 -*-
"""
Various input-based release history classes

ReleaseLogFile
   Read history from a disk file
ReleaseLogURL
   Read history from a URL
"""

from releaselog import ReleaseLog
from sys import version_info

class ReleaseLogFile(ReleaseLog):
    """Read history log entries from a disk file.
    Usage:

      hist = ReleaseLogFile(fmt, file [, args...])

    Arguments:

    fmt    - History format
    file   - Name of the file to read history from
    args   - Additional keyword arguments. See ReleaseLog for a description
             of these.
    """
    
    def __new__(cls, type, file, **kwargs):
        return ReleaseLog.__new__(cls, type, open(file, 'r'), **kwargs)


class ReleaseLogURL(ReleaseLog):
    """Read history log entries from a URL.
    Usage:

      hist = ReleaseLogURL(fmt, url [, args...])

    Arguments:

    fmt    - History format
    url    - URL to read history from
    args   - Additional keyword arguments. See ReleaseLog for a description
             of these.

    Note: URL must return Content-Type: text/plain
    """
    def __new__(cls, type, url, **kwargs):
        if version_info[0] > 2:
            from urllib.request import urlopen
        else:
            from urllib2 import urlopen
        return ReleaseLog.__new__(cls, type, urlopen(url), **kwargs)


    

Return to:

Send suggestions and report system problems to the System administrator.