コード例 #1
0
        def create_json_overlay_source(source_):
            _src = source_['#text']
            _type = source_['@type']
            if '@branch' in source_:
                _sub = source_['@branch']
            else:
                _sub = ''

            self.ovl_type = _type

            try:
                _class = self.module_controller.get_class(_type)
            except InvalidModuleName:
                _class = self.module_controller.get_class('stub')

            _location = encode(_src)
            if _sub:
                self.branch = encode(_sub)
            else:
                self.branch = None

            return _class(parent=self,
                          config=self.config,
                          _location=_location,
                          ignore=ignore)
コード例 #2
0
ファイル: overlay.py プロジェクト: dwfreed/layman
        def create_dict_overlay_source(source_):
            _src, _type, _sub = source_
            try:
                _class = OVERLAY_TYPES[_type]
            except KeyError:
                raise Exception('Overlay from_dict(), "' + self.name +
                    'Unknown overlay type "%s"!' % _type)
            _location = encode(_src)
            if _sub:
                self.branch = encode(_sub)
            else:
                self.branch = None

            return _class(parent=self, config=self.config,
                _location=_location, ignore=ignore)
コード例 #3
0
ファイル: overlay.py プロジェクト: dewey/layman
        def create_dict_overlay_source(source_):
            _src, _type, _sub = source_
            self.ovl_type = _type
            try:
                _class = self.module_controller.get_class(_type)
            except InvalidModuleName:
                _class = self.module_controller.get_class('stub')

            _location = encode(_src)
            if _sub:
                self.branch = encode(_sub)
            else:
                self.branch = None

            return _class(parent=self, config=self.config,
                _location=_location, ignore=ignore)
コード例 #4
0
ファイル: output.py プロジェクト: jmesmon/layman
    def status (self, message, status, info = 'ignored'):

        if type(message) != str:#not in types.StringTypes:
            message = encode(message)

        lines = message.split('\n')

        if not len(lines):
            return

        for i in lines[0:-1]:
            print >> self.std_out, " %s %s" % (self.color_func('green', '*'),i)

        i = lines[-1]

        if len(i) > 58:
            i = i[0:57]

        if status == 1:
            result = '[' + self.color_func('green', 'ok') + ']'
        elif status == 0:
            result = '[' + self.color_func('red', 'failed') + ']'
        else:
            result = '[' + self.color_func('yellow', info) + ']'

        print >> " %s %s %s %S" % (self.color_func('green', '*'), i,
            ('.' * (58 - len(i))), result)
コード例 #5
0
ファイル: output.py プロジェクト: fatman2021/layman
    def status(self, message, status, info="ignored"):

        message = encode(message)

        lines = message.split("\n")

        if not len(lines):
            return

        for i in lines[0:-1]:
            print(" %s %s" % (self.color_func("green", "*"), i), file=self.std_out)

        i = lines[-1]

        if len(i) > 58:
            i = i[0:57]

        if status == 1:
            result = "[" + self.color_func("green", "ok") + "]"
        elif status == 0:
            result = "[" + self.color_func("red", "failed") + "]"
        else:
            result = "[" + self.color_func("yellow", info) + "]"

        print(file=" %s %s %s %S" % (self.color_func("green", "*"), i, ("." * (58 - len(i))), result))
コード例 #6
0
    def status(self, message, status, info='ignored'):

        message = encode(message)

        lines = message.split('\n')

        if not len(lines):
            return

        for i in lines[0:-1]:
            print(" %s %s" % (self.color_func('green', '*'), i),
                  file=self.std_out)

        i = lines[-1]

        if len(i) > 58:
            i = i[0:57]

        if status == 1:
            result = '[' + self.color_func('green', 'ok') + ']'
        elif status == 0:
            result = '[' + self.color_func('red', 'failed') + ']'
        else:
            result = '[' + self.color_func('yellow', info) + ']'

        print(file=" %s %s %s %S" % (self.color_func('green', '*'), i,
                                     ('.' * (58 - len(i))), result))
コード例 #7
0
    def die(self, error):

        error = encode(error)

        for i in error.split('\n'):
            self.error(self.color_func('red', 'Fatal error: ') + i)
        self.error(self.color_func('red', 'Fatal error(s) - aborting'))
        sys.exit(1)
コード例 #8
0
ファイル: output.py プロジェクト: fatman2021/layman
    def die(self, error):

        error = encode(error)

        for i in error.split("\n"):
            self.error(self.color_func("red", "Fatal error: ") + i)
        self.error(self.color_func("red", "Fatal error(s) - aborting"))
        sys.exit(1)
コード例 #9
0
ファイル: output.py プロジェクト: jmesmon/layman
    def die (self, error):

        if type(error) != str:#not in types.StringTypes:
            error = encode(error)

        for i in error.split('\n'):
            self.error(self.color_func('red', 'Fatal error: ') + i)
        self.error(self.color_func('red', 'Fatal error(s) - aborting'))
        sys.exit(1)
コード例 #10
0
ファイル: output.py プロジェクト: fatman2021/layman
    def warn(self, warn, level=WARN_LEVEL):

        warn = encode(warn)

        if level > self.warn_lev:
            return

        for i in warn.split("\n"):
            print(" %s %s" % (self.color_func("yellow", "*"), i), file=self.std_out)
コード例 #11
0
ファイル: output.py プロジェクト: fatman2021/layman
    def info(self, info, level=INFO_LEVEL):

        info = encode(info)

        if level > self.info_lev:
            return

        for i in info.split("\n"):
            print(" %s %s" % (self.color_func("green", "*"), i), file=self.std_out)
コード例 #12
0
 def _check_repo_type(repos, caller):
     """internal function that validates the repos parameter,
     converting a string to a list[string] if it is not already a list.
     produces and error message if it is any other type
     returns repos as list always"""
     if isinstance(repos, STR):
         repos = [repos]
     # else assume it is an iterable, if not it will error
     return [encode(i) for i in repos]
コード例 #13
0
        def create_dict_overlay_source(source_):
            _src, _type, _sub = source_
            self.ovl_type = _type
            try:
                _class = self.module_controller.get_class(_type)
            except InvalidModuleName:
                _class = self.module_controller.get_class('stub')

            _location = encode(_src)
            if _sub:
                self.branch = encode(_sub)
            else:
                self.branch = None

            return _class(parent=self,
                          config=self.config,
                          _location=_location,
                          ignore=ignore)
コード例 #14
0
ファイル: api.py プロジェクト: wking/layman
 def _check_repo_type( repos, caller):
     """internal function that validates the repos parameter,
     converting a string to a list[string] if it is not already a list.
     produces and error message if it is any other type
     returns repos as list always"""
     if isinstance(repos, STR):
         repos = [repos]
     # else assume it is an iterable, if not it will error
     return [encode(i) for i in repos]
コード例 #15
0
    def info(self, info, level=INFO_LEVEL):

        info = encode(info)

        if level > self.info_lev:
            return

        for i in info.split('\n'):
            print(" %s %s" % (self.color_func('green', '*'), i),
                  file=self.std_out)
コード例 #16
0
ファイル: output.py プロジェクト: jmesmon/layman
    def info (self, info, level = INFO_LEVEL):

        if type(info) != str:#not in types.StringTypes:
            info = encode(info)

        if level > self.info_lev:
            return

        for i in info.split('\n'):
            print  >> self.std_out, " %s %s" % (self.color_func('green', '*'),i)
コード例 #17
0
ファイル: output.py プロジェクト: jmesmon/layman
    def warn (self, warn, level = WARN_LEVEL):

        if type(warn) != str:#not in types.StringTypes:
            warn = encode(warn)

        if level > self.warn_lev:
            return

        for i in warn.split('\n'):
            print >> self.std_out, " %s %s" % (self.color_func('yellow', '*'),i)
コード例 #18
0
    def warn(self, warn, level=WARN_LEVEL):

        warn = encode(warn)

        if level > self.warn_lev:
            return

        for i in warn.split('\n'):
            print(" %s %s" % (self.color_func('yellow', '*'), i),
                  file=self.std_out)
コード例 #19
0
ファイル: output.py プロジェクト: fatman2021/layman
    def debug(self, info, level=OFF):
        """empty debug function, does nothing,
        declared here for compatibility with DebugMessage
        """
        info = encode(info)

        if level > self.debug_lev:
            return

        for i in info.split("\n"):
            print(self.color_func("yellow", "DEBUG: ") + i, file=self.std_out)
コード例 #20
0
    def debug(self, info, level=OFF):
        """empty debug function, does nothing,
        declared here for compatibility with DebugMessage
        """
        info = encode(info)

        if level > self.debug_lev:
            return

        for i in info.split('\n'):
            print(self.color_func('yellow', 'DEBUG: ') + i, file=self.std_out)
コード例 #21
0
ファイル: output.py プロジェクト: jmesmon/layman
    def debug(self, info, level = OFF):
        """empty debug function, does nothing,
        declared here for compatibility with DebugMessage
        """
        if type(info) != str:#not in types.StringTypes:
            info = encode(info)

        if level > self.debug_lev:
            return

        for i in info.split('\n'):
            print  >> self.std_out, self.color_func('yellow', 'DEBUG: ') + i
コード例 #22
0
ファイル: output.py プロジェクト: fatman2021/layman
    def error(self, error, level=None):

        error = encode(error)

        for i in error.split("\n"):
            # NOTE: Forced flushing ensures that stdout and stderr
            # stay in nice order.  This is a workaround for calls like
            # "layman -L |& less".
            self.std_out.flush()
            self.error_out.flush()
            print(" %s %s" % (self.color_func("red", "*"), i), file=self.std_out)
            self.std_out.flush()
        self.do_error_callback(error)
コード例 #23
0
ファイル: output.py プロジェクト: jmesmon/layman
    def error (self, error):

        if type(error) != str:#not in types.StringTypes:
            error = encode(error)

        for i in error.split('\n'):
            # NOTE: Forced flushing ensures that stdout and stderr
            # stay in nice order.  This is a workaround for calls like
            # "layman -L |& less".
            self.std_out.flush()
            self.error_out.flush()
            print >> self.std_out, " %s %s" % (self.color_func('red', '*'), i)
            self.std_out.flush()
        self.do_error_callback(error)
コード例 #24
0
    def error(self, error, level=None):

        error = encode(error)

        for i in error.split('\n'):
            # NOTE: Forced flushing ensures that stdout and stderr
            # stay in nice order.  This is a workaround for calls like
            # "layman -L |& less".
            self.std_out.flush()
            self.error_out.flush()
            print(" %s %s" % (self.color_func('red', '*'), i),
                  file=self.std_out)
            self.std_out.flush()
        self.do_error_callback(error)
コード例 #25
0
ファイル: overlay.py プロジェクト: dewey/layman
        def create_json_overlay_source(source_):
            _src = source_['#text']
            _type = source_['@type']
            if '@branch' in source_:
                _sub = source_['@branch']
            else:
                _sub = ''

            self.ovl_type = _type

            try:
                _class = self.module_controller.get_class(_type)
            except InvalidModuleName:
                _class = self.module_controller.get_class('stub')

            _location = encode(_src)
            if _sub:
                self.branch = encode(_sub)
            else:
                self.branch = None

            return _class(parent=self, config=self.config,
                _location=_location, ignore=ignore)
コード例 #26
0
ファイル: overlay.py プロジェクト: dewey/layman
        def create_overlay_source(source_elem):
            _branch = ''
            _type = source_elem.attrib['type']
            self.ovl_type = _type

            if 'branch' in source_elem.attrib:
                _branch = source_elem.attrib['branch']

            try:
                _class = self.module_controller.get_class(_type)
            except InvalidModuleName:
                _class = self.module_controller.get_class('stub')

            _location = encode(strip_text(source_elem))
            self.branch = _branch

            return _class(parent=self, config=self.config,
                _location=_location, ignore=ignore)
コード例 #27
0
ファイル: overlay.py プロジェクト: dwfreed/layman
        def create_overlay_source(source_elem):
            _branch = ''
            _type = source_elem.attrib['type']
            if 'branch' in source_elem.attrib:
                _branch = source_elem.attrib['branch']
                
            try:
                _class = OVERLAY_TYPES[_type]
            except KeyError:
                raise Exception('Overlay from_xml(), "' + self.name + \
                    'Unknown overlay type "%s"!' % _type)

            _location = encode(strip_text(source_elem))

            self.branch = _branch

            return _class(parent=self, config=self.config,
                _location=_location, ignore=ignore)
コード例 #28
0
        def create_overlay_source(source_elem):
            _branch = ''
            _type = source_elem.attrib['type']
            self.ovl_type = _type

            if 'branch' in source_elem.attrib:
                _branch = source_elem.attrib['branch']

            try:
                _class = self.module_controller.get_class(_type)
            except InvalidModuleName:
                _class = self.module_controller.get_class('stub')

            _location = encode(strip_text(source_elem))
            self.branch = _branch

            return _class(parent=self,
                          config=self.config,
                          _location=_location,
                          ignore=ignore)
コード例 #29
0
    def from_json(self, json, ignore):
        '''
        Process a json overlay definition
        '''
        msg = 'Overlay from_json(); overlay %(ovl)s' % {'ovl': str(json)}
        self.output.debug(msg, 6)

        _name = json['name']
        if _name != None:
            self.name = encode(_name)
        else:
            msg = 'Overlay from_json(), "name" entry missing from json!'
            raise Exception(msg)

        if 'source' in json:
            _sources = json['source']
        else:
            _sources = None

        if _sources == None:
            msg = 'Overlay from_json(), "%(name)s" is missing a "source" '\
                  'entry!' % {'name': self.name}
            raise Exception(msg)

        def create_json_overlay_source(source_):
            _src = source_['#text']
            _type = source_['@type']
            if '@branch' in source_:
                _sub = source_['@branch']
            else:
                _sub = ''

            self.ovl_type = _type

            try:
                _class = self.module_controller.get_class(_type)
            except InvalidModuleName:
                _class = self.module_controller.get_class('stub')

            _location = encode(_src)
            if _sub:
                self.branch = encode(_sub)
            else:
                self.branch = None

            return _class(parent=self,
                          config=self.config,
                          _location=_location,
                          ignore=ignore)

        self.sources = [create_json_overlay_source(e) for e in _sources]

        _owners = json['owner']
        self.owners = []

        for _owner in _owners:
            owner = {}
            if 'name' in _owner:
                owner['name'] = encode(_owner['name'])
            else:
                owner['name'] = None
            if 'email' in _owner:
                owner['email'] = encode(_owner['email'])
            else:
                owner['email'] = None
                msg = 'Overlay from_json(), "%(name)s" is missing an '\
                      '"owner.email" entry!' % {'name': self.name}
                if not ignore:
                    raise Exception(msg)
                elif ignore == 1:
                    self.output.warn(msg, 4)
            self.owners.append(owner)

        if 'description' in json:
            self.descriptions = []
            _descs = json['description']
            for d in _descs:
                d = WHITESPACE_REGEX.sub(' ', d)
                self.descriptions.append(encode(d))
        else:
            self.descriptions = ['']
            msg = 'Overlay from_json() "%(name)s" is missing description'\
                  'entry!' % {'name': self.name}
            if not ignore:
                raise Exception(msg)
            elif ignore == 1:
                self.output.warn(msg, 4)

        if '@status' in json:
            self.status = encode(json['@status'])
        else:
            self.status = None

        self.quality = 'experimental'
        if '@quality' in json:
            if json['@quality'] in set(QUALITY_LEVELS):
                self.quality = encode(json['@quality'])

        if '@priority' in json:
            self.priority = int(json['@priority'])
        else:
            self.priority = 50

        if '@license' in json:
            self.license = encode(json['@license'])
        else:
            self.license = None

        if 'homepage' in json:
            self.homepage = encode(json['homepage'])
        else:
            self.homepage = None

        if 'feed' in json:
            self.feeds = [encode(e) \
                for e in json['feed']]
        else:
            self.feeds = None

        if 'irc' in json:
            self.irc = encode(json['irc'])
        else:
            self.irc = None
コード例 #30
0
ファイル: overlay.py プロジェクト: dwfreed/layman
    def from_dict(self, overlay, ignore):
        """Process an overlay dictionary definition
        """
        self.output.debug("Overlay from_dict(); overlay" + str(overlay), 6)
        _name = overlay['name']
        if _name != None:
            self.name = encode(_name)
        else:
            raise Exception('Overlay from_dict(), "' + self.name +
                'is missing a "name" entry!')

        _sources = overlay['sources']

        if _sources == None:
            raise Exception('Overlay from_dict(), "' + self.name +
                '" is missing a "source" entry!')

        def create_dict_overlay_source(source_):
            _src, _type, _sub = source_
            try:
                _class = OVERLAY_TYPES[_type]
            except KeyError:
                raise Exception('Overlay from_dict(), "' + self.name +
                    'Unknown overlay type "%s"!' % _type)
            _location = encode(_src)
            if _sub:
                self.branch = encode(_sub)
            else:
                self.branch = None

            return _class(parent=self, config=self.config,
                _location=_location, ignore=ignore)

        self.sources = [create_dict_overlay_source(e) for e in _sources]

        if 'owner_name' in overlay:
            _owner = overlay['owner_name']
            self.owner_name = encode(_owner)
            _email = overlay['owner_email']
        else:
            self.owner_name = None

        if 'owner_email' in overlay:
            _email = overlay['owner_email']
            self.owner_email = encode(_email)
        else:
            self.owner_email = None
            if not ignore:
                raise Exception('Overlay from_dict(), "' + self.name +
                    '" is missing an "owner.email" entry!')
            elif ignore == 1:
                self.output.warn('Overlay from_dict(), "' + self.name +
                    '" is missing an "owner.email" entry!', 4)

        if 'description' in overlay:
            _desc = overlay['description']
            d = WHITESPACE_REGEX.sub(' ', _desc)
            self.description = encode(d)
            del d
        else:
            self.description = ''
            if not ignore:
                raise Exception('Overlay from_dict(), "' + self.name +
                    '" is missing a "description" entry!')
            elif ignore == 1:
                self.output.warn('Overlay from_dict(), "' + self.name +
                    '" is missing a "description" entry!', 4)

        if 'status' in overlay:
            self.status = encode(overlay['status'])
        else:
            self.status = None

        self.quality = 'experimental'
        if 'quality' in overlay:
            if overlay['quality'] in set(QUALITY_LEVELS):
                self.quality = encode(overlay['quality'])

        if 'priority' in overlay:
            self.priority = int(overlay['priority'])
        else:
            self.priority = 50

        if 'homepage' in overlay:
            self.homepage = encode(overlay['homepage'])
        else:
            self.homepage = None

        if 'feed' in overlay:
            self.feeds = [encode(e) \
                for e in overlay['feeds']]
        else:
            self.feeds = None

        if 'irc' in overlay:
            self.irc = encode(overlay['irc'])
        else:
            self.irc = None

        if 'branch' in overlay:
            self.branch = encode(overlay['branch'])
        else:
            self.branch = None
コード例 #31
0
    def from_dict(self, overlay, ignore):
        '''
        Process an overlay dictionary definition
        '''
        msg = 'Overlay from_dict(); overlay %(ovl)s' % {'ovl': str(overlay)}
        self.output.debug(msg, 6)

        _name = overlay['name']
        if _name != None:
            self.name = encode(_name)
        else:
            msg = 'Overlay from_dict(), "name" entry missing from dictionary!'
            raise Exception(msg)

        if 'source' in overlay:
            _sources = overlay['source']
        else:
            _sources = None

        if _sources == None:
            msg = 'Overlay from_dict(), "%(name)s" is missing a "source" '\
                  'entry!' % {'name': self.name}
            raise Exception(msg)

        def create_dict_overlay_source(source_):
            _src, _type, _sub = source_
            self.ovl_type = _type
            try:
                _class = self.module_controller.get_class(_type)
            except InvalidModuleName:
                _class = self.module_controller.get_class('stub')

            _location = encode(_src)
            if _sub:
                self.branch = encode(_sub)
            else:
                self.branch = None

            return _class(parent=self,
                          config=self.config,
                          _location=_location,
                          ignore=ignore)

        self.sources = [create_dict_overlay_source(e) for e in _sources]

        self.owners = []

        if 'owner' in overlay:
            for _owner in overlay['owner']:
                owner = {}
                if 'name' in _owner and _owner['name']:
                    owner['name'] = encode(_owner['name'])
                else:
                    owner['name'] = None

                if 'email' in _owner:
                    owner['email'] = encode(_owner['email'])
                else:
                    owner['email'] = None
                    msg = 'Overlay from_dict(), "%(name)s" is missing an '\
                          '"owner.email" entry!' % {'name': self.name}
                    if not ignore:
                        raise Exception(msg)
                    elif ignore == 1:
                        self.output.warn(msg, 4)

                self.owners.append(owner)

        if 'description' in overlay:
            self.descriptions = []
            _descs = overlay['description']
            for d in _descs:
                d = WHITESPACE_REGEX.sub(' ', d)
                self.descriptions.append(encode(d))
        else:
            self.descriptions = ['']
            if not ignore:
                raise Exception('Overlay from_dict(), "' + self.name +
                                '" is missing a "description" entry!')
            elif ignore == 1:
                self.output.warn(
                    'Overlay from_dict(), "' + self.name +
                    '" is missing a "description" entry!', 4)

        if 'status' in overlay:
            self.status = encode(overlay['status'])
        else:
            self.status = None

        self.quality = 'experimental'
        if 'quality' in overlay:
            if overlay['quality'] in set(QUALITY_LEVELS):
                self.quality = encode(overlay['quality'])

        if 'priority' in overlay:
            self.priority = int(overlay['priority'])
        else:
            self.priority = 50

        if 'license' in overlay:
            self.license = encode(overlay['license'])
        else:
            self.license = None

        if 'homepage' in overlay:
            self.homepage = encode(overlay['homepage'])
        else:
            self.homepage = None

        if 'feed' in overlay:
            self.feeds = [encode(e) \
                for e in overlay['feed']]
        else:
            self.feeds = None

        if 'irc' in overlay:
            self.irc = encode(overlay['irc'])
        else:
            self.irc = None
コード例 #32
0
ファイル: overlay.py プロジェクト: dewey/layman
    def from_json(self, json, ignore):
        '''
        Process a json overlay definition
        '''
        msg = 'Overlay from_json(); overlay %(ovl)s' % {'ovl': str(json)}
        self.output.debug(msg, 6)

        _name = json['name']
        if _name != None:
            self.name = encode(_name)
        else:
            msg = 'Overlay from_json(), "name" entry missing from json!'
            raise Exception(msg)

        if 'source' in json:
            _sources = json['source']
        else:
            _sources = None

        if _sources == None:
            msg = 'Overlay from_json(), "%(name)s" is missing a "source" '\
                  'entry!' % {'name': self.name}
            raise Exception(msg)

        def create_json_overlay_source(source_):
            _src = source_['#text']
            _type = source_['@type']
            if '@branch' in source_:
                _sub = source_['@branch']
            else:
                _sub = ''

            self.ovl_type = _type

            try:
                _class = self.module_controller.get_class(_type)
            except InvalidModuleName:
                _class = self.module_controller.get_class('stub')

            _location = encode(_src)
            if _sub:
                self.branch = encode(_sub)
            else:
                self.branch = None

            return _class(parent=self, config=self.config,
                _location=_location, ignore=ignore)

        self.sources = [create_json_overlay_source(e) for e in _sources]

        _owners = json['owner']
        self.owners = []

        for _owner in _owners:
            owner = {}
            if 'name' in _owner:
                owner['name'] = encode(_owner['name'])
            else:
                owner['name'] = None
            if 'email' in _owner:
                owner['email'] = encode(_owner['email'])
            else:
                owner['email'] = None
                msg = 'Overlay from_json(), "%(name)s" is missing an '\
                      '"owner.email" entry!' % {'name': self.name}
                if not ignore:
                    raise Exception(msg)
                elif ignore == 1:
                    self.output.warn(msg, 4)
            self.owners.append(owner)

        if 'description' in json:
            self.descriptions = []
            _descs = json['description']
            for d in _descs:
                d = WHITESPACE_REGEX.sub(' ', d)
                self.descriptions.append(encode(d))
        else:
            self.descriptions = ['']
            msg = 'Overlay from_json() "%(name)s" is missing description'\
                  'entry!' % {'name': self.name}
            if not ignore:
                raise Exception(msg)
            elif ignore == 1:
                self.output.warn(msg, 4)

        if '@status' in json:
            self.status = encode(json['@status'])
        else:
            self.status = None

        self.quality = 'experimental'
        if '@quality' in json:
            if json['@quality'] in set(QUALITY_LEVELS):
                self.quality = encode(json['@quality'])

        if '@priority' in json:
            self.priority = int(json['@priority'])
        else:
            self.priority = 50

        if '@license' in json:
            self.license = encode(json['@license'])
        else:
            self.license = None

        if 'homepage' in json:
            self.homepage = encode(json['homepage'])
        else:
            self.homepage = None

        if 'feed' in json:
            self.feeds = [encode(e) \
                for e in json['feed']]
        else:
            self.feeds = None

        if 'irc' in json:
            self.irc = encode(json['irc'])
        else:
            self.irc = None
コード例 #33
0
ファイル: overlay.py プロジェクト: dwfreed/layman
    def from_xml(self, xml, ignore):
        """Process an xml overlay definition
        """
        def strip_text(node):
            res = node.text
            if res is None:
                return ''
            return res.strip()

        _name = xml.find('name')
        if _name != None:
            self.name = encode(strip_text(_name))
        elif 'name' in xml.attrib:
            self.name = encode(xml.attrib['name'])
        else:
            raise Exception('Overlay from_xml(), "' + self.name + \
                'is missing a "name" entry!')

        _branch = xml.find('branch')
        if _branch != None and _branch.text:
            self.branch = encode(_branch.text.strip())
        elif 'branch' in xml.attrib:
            self.branch = encode(xml.attrib['branch'])
        else:
            self.branch = ''

        _sources = xml.findall('source')
        # new xml format
        if _sources != []:
            _sources = [e for e in _sources if 'type' in e.attrib]
        #old xml format
        elif ('src' in xml.attrib) and ('type' in xml.attrib):
            s = ET.Element('source', type=xml.attrib['type'])
            s.text = xml.attrib['src']
            _sources = [s]
            del s

        def create_overlay_source(source_elem):
            _branch = ''
            _type = source_elem.attrib['type']
            if 'branch' in source_elem.attrib:
                _branch = source_elem.attrib['branch']
                
            try:
                _class = OVERLAY_TYPES[_type]
            except KeyError:
                raise Exception('Overlay from_xml(), "' + self.name + \
                    'Unknown overlay type "%s"!' % _type)

            _location = encode(strip_text(source_elem))

            self.branch = _branch

            return _class(parent=self, config=self.config,
                _location=_location, ignore=ignore)

        if not len(_sources):
            raise Exception('Overlay from_xml(), "' + self.name + \
                '" is missing a "source" entry!')

        self.sources = [create_overlay_source(e) for e in _sources]

        _owner = xml.find('owner')
        if _owner == None:
            _email = None
        else:
            _email = _owner.find('email')
        if _owner != None and _email != None:
            self.owner_email = encode(strip_text(_email))
            _name = _owner.find('name')
            if _name != None:
                self.owner_name = encode(strip_text(_name))
            else:
                self.owner_name = None
        elif 'contact' in xml.attrib:
            self.owner_email = encode(xml.attrib['contact'])
            self.owner_name = None
        else:
            self.owner_email = ''
            self.owner_name = None
            if not ignore:
                raise Exception('Overlay  from_xml(), "' + self.name + \
                    '" is missing an "owner.email" entry!')
            elif ignore == 1:
                self.output.warn('Overlay "' + self.name + '" is missing a '
                         '"owner.email" entry!', 4)

        _desc = xml.find('description')
        if _desc != None:
            d = WHITESPACE_REGEX.sub(' ', strip_text(_desc))
            self.description = encode(d)
            del d
        else:
            self.description = ''
            if not ignore:
                raise Exception('Overlay  from_xml(), "' + self.name + \
                    '" is missing a description" entry!')
            elif ignore == 1:
                self.output.warn('Overlay "' + self.name + '" is missing a '
                         '"description" entry!', 4)

        if 'status' in xml.attrib:
            self.status = encode(xml.attrib['status'])
        else:
            self.status = None

        self.quality = 'experimental'
        if 'quality' in xml.attrib:
            if xml.attrib['quality'] in set(QUALITY_LEVELS):
                self.quality = encode(xml.attrib['quality'])

        if 'priority' in xml.attrib:
            self.priority = int(xml.attrib['priority'])
        else:
            self.priority = 50

        h = xml.find('homepage')
        l = xml.find('link')
        if h != None:
            self.homepage = encode(strip_text(h))
        elif l != None:
            self.homepage = encode(strip_text(l))
        else:
            self.homepage = None

        self.feeds = [encode(strip_text(e)) \
            for e in xml.findall('feed')]

        _irc = xml.find('irc')
        if _irc != None:
            self.irc = encode(strip_text(_irc))
        else:
            self.irc = None
コード例 #34
0
    def from_xml(self, xml, ignore):
        '''
        Process an xml overlay definition
        '''
        def strip_text(node):
            res = node.text
            if res is None:
                return ''
            return res.strip()

        _name = xml.find('name')

        if _name != None:
            self.name = encode(strip_text(_name))
        elif 'name' in xml.attrib:
            self.name = encode(xml.attrib['name'])
        else:
            msg = 'Overlay from_xml(), "name" entry missing from xml!'
            raise Exception(msg)

        _sources = xml.findall('source')

        # new xml format
        if _sources != []:
            _sources = [e for e in _sources if 'type' in e.attrib]
        #old xml format
        elif ('src' in xml.attrib) and ('type' in xml.attrib):
            s = ET.Element('source', type=xml.attrib['type'])
            s.text = xml.attrib['src']
            _sources = [s]
            del s

        def create_overlay_source(source_elem):
            _branch = ''
            _type = source_elem.attrib['type']
            self.ovl_type = _type

            if 'branch' in source_elem.attrib:
                _branch = source_elem.attrib['branch']

            try:
                _class = self.module_controller.get_class(_type)
            except InvalidModuleName:
                _class = self.module_controller.get_class('stub')

            _location = encode(strip_text(source_elem))
            self.branch = _branch

            return _class(parent=self,
                          config=self.config,
                          _location=_location,
                          ignore=ignore)

        if not len(_sources):
            msg = 'Overlay from_xml(), "%(name)" is missing a "source" entry!'\
                  % {'name': self.name}
            raise Exception(msg)

        self.sources = [create_overlay_source(e) for e in _sources]

        _owners = xml.findall('owner')
        self.owners = []

        # For backwards compatibility with older Overlay XML formats
        # default to this.
        if 'contact' in xml.attrib:
            owner = {'email': encode(xml.attrib['contact']), 'name': None}
            self.owners.append(owner)
        else:
            for _owner in _owners:
                owner = {}

                _email = _owner.find('email')
                _name = _owner.find('name')

                if _name != None:
                    owner['name'] = encode(strip_text(_name))
                else:
                    owner['name'] = None
                if _email != None:
                    owner['email'] = encode(strip_text(_email))
                else:
                    owner['email'] = None
                    msg = 'Overlay from_xml(), "%(name)s" is missing an '\
                          '"owner.email" entry!' % {'name': self.name}
                    if not ignore:
                        raise Exception(msg)
                    elif ignore == 1:
                        self.output.warn(msg, 4)

                self.owners.append(owner)

        _desc = xml.findall('description')
        if _desc != None:
            self.descriptions = []
            for d in _desc:
                d = WHITESPACE_REGEX.sub(' ', strip_text(d))
                self.descriptions.append(encode(d))
        else:
            self.descriptions = ['']
            msg = 'Overlay from_xml(), "%(name)s is missing a '\
                  '"description" entry!' % {'name': self.name}
            if not ignore:
                raise Exception(msg)
            elif ignore == 1:
                self.output.warn(msg, 4)

        if 'status' in xml.attrib:
            self.status = encode(xml.attrib['status'])
        else:
            self.status = None

        self.quality = 'experimental'
        if 'quality' in xml.attrib:
            if xml.attrib['quality'] in set(QUALITY_LEVELS):
                self.quality = encode(xml.attrib['quality'])

        if 'priority' in xml.attrib:
            self.priority = int(xml.attrib['priority'])
        else:
            self.priority = 50

        if 'license' in xml.attrib:
            self.license = encode(xml.attrib['license'])
        else:
            self.license = None

        h = xml.find('homepage')
        l = xml.find('link')

        if h != None:
            self.homepage = encode(strip_text(h))
        elif l != None:
            self.homepage = encode(strip_text(l))
        else:
            self.homepage = None

        self.feeds = [encode(strip_text(e)) for e in xml.findall('feed')]

        _irc = xml.find('irc')
        if _irc != None:
            self.irc = encode(strip_text(_irc))
        else:
            self.irc = None
コード例 #35
0
ファイル: overlay.py プロジェクト: dewey/layman
    def from_dict(self, overlay, ignore):
        '''
        Process an overlay dictionary definition
        '''
        msg = 'Overlay from_dict(); overlay %(ovl)s' % {'ovl': str(overlay)}
        self.output.debug(msg, 6)

        _name = overlay['name']
        if _name != None:
            self.name = encode(_name)
        else:
            msg = 'Overlay from_dict(), "name" entry missing from dictionary!'
            raise Exception(msg)

        if 'source' in overlay:
            _sources = overlay['source']
        else:
            _sources = None

        if _sources == None:
            msg = 'Overlay from_dict(), "%(name)s" is missing a "source" '\
                  'entry!' % {'name': self.name}
            raise Exception(msg)

        def create_dict_overlay_source(source_):
            _src, _type, _sub = source_
            self.ovl_type = _type
            try:
                _class = self.module_controller.get_class(_type)
            except InvalidModuleName:
                _class = self.module_controller.get_class('stub')

            _location = encode(_src)
            if _sub:
                self.branch = encode(_sub)
            else:
                self.branch = None

            return _class(parent=self, config=self.config,
                _location=_location, ignore=ignore)

        self.sources = [create_dict_overlay_source(e) for e in _sources]

        self.owners = []

        if 'owner' in overlay:
            for _owner in overlay['owner']:
                owner = {}
                if 'name' in _owner and _owner['name']:
                    owner['name'] = encode(_owner['name'])
                else:
                    owner['name'] = None

                if 'email' in _owner:
                    owner['email'] = encode(_owner['email'])
                else:
                    owner['email'] = None
                    msg = 'Overlay from_dict(), "%(name)s" is missing an '\
                          '"owner.email" entry!' % {'name': self.name}
                    if not ignore:
                        raise Exception(msg)
                    elif ignore == 1:
                        self.output.warn(msg, 4)

                self.owners.append(owner)

        if 'description' in overlay:
            self.descriptions = []
            _descs = overlay['description']
            for d in _descs:
                d = WHITESPACE_REGEX.sub(' ', d)
                self.descriptions.append(encode(d))
        else:
            self.descriptions = ['']
            if not ignore:
                raise Exception('Overlay from_dict(), "' + self.name +
                    '" is missing a "description" entry!')
            elif ignore == 1:
                self.output.warn('Overlay from_dict(), "' + self.name +
                    '" is missing a "description" entry!', 4)

        if 'status' in overlay:
            self.status = encode(overlay['status'])
        else:
            self.status = None

        self.quality = 'experimental'
        if 'quality' in overlay:
            if overlay['quality'] in set(QUALITY_LEVELS):
                self.quality = encode(overlay['quality'])

        if 'priority' in overlay:
            self.priority = int(overlay['priority'])
        else:
            self.priority = 50

        if 'license' in overlay:
            self.license = encode(overlay['license'])
        else:
            self.license = None

        if 'homepage' in overlay:
            self.homepage = encode(overlay['homepage'])
        else:
            self.homepage = None

        if 'feed' in overlay:
            self.feeds = [encode(e) \
                for e in overlay['feed']]
        else:
            self.feeds = None

        if 'irc' in overlay:
            self.irc = encode(overlay['irc'])
        else:
            self.irc = None
コード例 #36
0
ファイル: overlay.py プロジェクト: wking/layman
    def from_dict(self, overlay, ignore):
        """Process an overlay dictionary definition
        """
        self.output.debug("Overlay from_dict(); overlay" + str(overlay), 6)
        _name = overlay['name']
        if _name != None:
            self.name = encode(_name)
        else:
            raise Exception('Overlay from_dict(), "' + self.name +
                'is missing a "name" entry!')

        _sources = overlay['sources']

        if _sources == None:
            raise Exception('Overlay from_dict(), "' + self.name +
                '" is missing a "source" entry!')

        def create_dict_overlay_source(source_):
            _src, _type, _sub = source_
            self.ovl_type = _type
            try:
                _class = self.module_controller.get_class(_type)
            except InvalidModuleName:
                _class = self.module_controller.get_class('stub')

            _location = encode(_src)
            if _sub:
                self.branch = encode(_sub)
            else:
                self.branch = None

            return _class(parent=self, config=self.config,
                _location=_location, ignore=ignore)

        self.sources = [create_dict_overlay_source(e) for e in _sources]

        if 'owner_name' in overlay:
            _owner = overlay['owner_name']
            self.owner_name = encode(_owner)
        else:
            self.owner_name = None

        if 'owner_email' in overlay:
            _email = overlay['owner_email']
            self.owner_email = encode(_email)
        else:
            self.owner_email = None
            if not ignore:
                raise Exception('Overlay from_dict(), "' + self.name +
                    '" is missing an "owner.email" entry!')
            elif ignore == 1:
                self.output.warn('Overlay from_dict(), "' + self.name +
                    '" is missing an "owner.email" entry!', 4)

        if 'descriptions' in overlay:
            self.descriptions = []
            _descs = overlay['descriptions']
            for d in _descs:
                d = WHITESPACE_REGEX.sub(' ', d)
                self.descriptions.append(encode(d))
        else:
            self.descriptions = ['']
            if not ignore:
                raise Exception('Overlay from_dict(), "' + self.name +
                    '" is missing a "description" entry!')
            elif ignore == 1:
                self.output.warn('Overlay from_dict(), "' + self.name +
                    '" is missing a "description" entry!', 4)

        if 'status' in overlay:
            self.status = encode(overlay['status'])
        else:
            self.status = None

        self.quality = 'experimental'
        if 'quality' in overlay:
            if overlay['quality'] in set(QUALITY_LEVELS):
                self.quality = encode(overlay['quality'])

        if 'priority' in overlay:
            self.priority = int(overlay['priority'])
        else:
            self.priority = 50

        if 'homepage' in overlay:
            self.homepage = encode(overlay['homepage'])
        else:
            self.homepage = None

        if 'feeds' in overlay:
            self.feeds = [encode(e) \
                for e in overlay['feeds']]
        else:
            self.feeds = None

        if 'irc' in overlay:
            self.irc = encode(overlay['irc'])
        else:
            self.irc = None
コード例 #37
0
ファイル: overlay.py プロジェクト: dewey/layman
    def from_xml(self, xml, ignore):
        '''
        Process an xml overlay definition
        '''
        def strip_text(node):
            res = node.text
            if res is None:
                return ''
            return res.strip()

        _name = xml.find('name')

        if _name != None:
            self.name = encode(strip_text(_name))
        elif 'name' in xml.attrib:
            self.name = encode(xml.attrib['name'])
        else:
            msg = 'Overlay from_xml(), "name" entry missing from xml!'
            raise Exception(msg)

        _sources = xml.findall('source')

        # new xml format
        if _sources != []:
            _sources = [e for e in _sources if 'type' in e.attrib]
        #old xml format
        elif ('src' in xml.attrib) and ('type' in xml.attrib):
            s = ET.Element('source', type=xml.attrib['type'])
            s.text = xml.attrib['src']
            _sources = [s]
            del s

        def create_overlay_source(source_elem):
            _branch = ''
            _type = source_elem.attrib['type']
            self.ovl_type = _type

            if 'branch' in source_elem.attrib:
                _branch = source_elem.attrib['branch']

            try:
                _class = self.module_controller.get_class(_type)
            except InvalidModuleName:
                _class = self.module_controller.get_class('stub')

            _location = encode(strip_text(source_elem))
            self.branch = _branch

            return _class(parent=self, config=self.config,
                _location=_location, ignore=ignore)

        if not len(_sources):
            msg = 'Overlay from_xml(), "%(name)" is missing a "source" entry!'\
                  % {'name': self.name}
            raise Exception(msg)

        self.sources = [create_overlay_source(e) for e in _sources]

        _owners = xml.findall('owner')
        self.owners = []

        # For backwards compatibility with older Overlay XML formats
        # default to this.
        if 'contact' in xml.attrib:
            owner = {'email': encode(xml.attrib['contact']),
                     'name': None}
            self.owners.append(owner)
        else:
            for _owner in _owners:
                owner = {}

                _email = _owner.find('email')
                _name = _owner.find('name')

                if _name != None:
                    owner['name'] = encode(strip_text(_name))
                else:
                    owner['name'] = None
                if _email != None:
                    owner['email'] = encode(strip_text(_email))
                else:
                    owner['email'] = None
                    msg = 'Overlay from_xml(), "%(name)s" is missing an '\
                          '"owner.email" entry!' % {'name': self.name}
                    if not ignore:
                        raise Exception(msg)
                    elif ignore == 1:
                        self.output.warn(msg, 4)

                self.owners.append(owner)

        _desc = xml.findall('description')
        if _desc != None:
            self.descriptions = []
            for d in _desc:
                d = WHITESPACE_REGEX.sub(' ', strip_text(d))
                self.descriptions.append(encode(d))
        else:
            self.descriptions = ['']
            msg = 'Overlay from_xml(), "%(name)s is missing a '\
                  '"description" entry!' % {'name': self.name}
            if not ignore:
                raise Exception(msg)
            elif ignore == 1:
                self.output.warn(msg, 4)

        if 'status' in xml.attrib:
            self.status = encode(xml.attrib['status'])
        else:
            self.status = None

        self.quality = 'experimental'
        if 'quality' in xml.attrib:
            if xml.attrib['quality'] in set(QUALITY_LEVELS):
                self.quality = encode(xml.attrib['quality'])

        if 'priority' in xml.attrib:
            self.priority = int(xml.attrib['priority'])
        else:
            self.priority = 50

        if 'license' in xml.attrib:
            self.license = encode(xml.attrib['license'])
        else:
            self.license = None

        h = xml.find('homepage')
        l = xml.find('link')

        if h != None:
            self.homepage = encode(strip_text(h))
        elif l != None:
            self.homepage = encode(strip_text(l))
        else:
            self.homepage = None

        self.feeds = [encode(strip_text(e)) for e in xml.findall('feed')]

        _irc = xml.find('irc')
        if _irc != None:
            self.irc = encode(strip_text(_irc))
        else:
            self.irc = None