cubicweb/server/sources/datafeed.py
changeset 12828 dadbd4148a44
parent 12567 26744ad37953
equal deleted inserted replaced
12827:5d1568572895 12828:dadbd4148a44
    40 class DataFeedSource(AbstractSource):
    40 class DataFeedSource(AbstractSource):
    41     use_cwuri_as_url = True
    41     use_cwuri_as_url = True
    42 
    42 
    43     options = (
    43     options = (
    44         ('synchronize',
    44         ('synchronize',
    45          {'type' : 'yn',
    45          {'type': 'yn',
    46           'default': True,
    46           'default': True,
    47           'help': ('Is the repository responsible to automatically import '
    47           'help': ('Is the repository responsible to automatically import '
    48                    'content from this source? '
    48                    'content from this source? '
    49                    'You should say yes unless you don\'t want this behaviour '
    49                    'You should say yes unless you don\'t want this behaviour '
    50                    'or if you use a multiple repositories setup, in which '
    50                    'or if you use a multiple repositories setup, in which '
    51                    'case you should say yes on one repository, no on others.'),
    51                    'case you should say yes on one repository, no on others.'),
    52           'group': 'datafeed-source', 'level': 2,
    52           'group': 'datafeed-source', 'level': 2,
    53           }),
    53           }),
    54         ('synchronization-interval',
    54         ('synchronization-interval',
    55          {'type' : 'time',
    55          {'type': 'time',
    56           'default': '5min',
    56           'default': '5min',
    57           'help': ('Interval in seconds between synchronization with the '
    57           'help': ('Interval in seconds between synchronization with the '
    58                    'external source (default to 5 minutes, must be >= 1 min).'),
    58                    'external source (default to 5 minutes, must be >= 1 min).'),
    59           'group': 'datafeed-source', 'level': 2,
    59           'group': 'datafeed-source', 'level': 2,
    60           }),
    60           }),
    61         ('max-lock-lifetime',
    61         ('max-lock-lifetime',
    62          {'type' : 'time',
    62          {'type': 'time',
    63           'default': '1h',
    63           'default': '1h',
    64           'help': ('Maximum time allowed for a synchronization to be run. '
    64           'help': ('Maximum time allowed for a synchronization to be run. '
    65                    'Exceeded that time, the synchronization will be considered '
    65                    'Exceeded that time, the synchronization will be considered '
    66                    'as having failed and not properly released the lock, hence '
    66                    'as having failed and not properly released the lock, hence '
    67                    'it won\'t be considered'),
    67                    'it won\'t be considered'),
    68           'group': 'datafeed-source', 'level': 2,
    68           'group': 'datafeed-source', 'level': 2,
    69           }),
    69           }),
    70         ('delete-entities',
    70         ('delete-entities',
    71          {'type' : 'yn',
    71          {'type': 'yn',
    72           'default': False,
    72           'default': False,
    73           'help': ('Should already imported entities not found anymore on the '
    73           'help': ('Should already imported entities not found anymore on the '
    74                    'external source be deleted? Handling of this parameter '
    74                    'external source be deleted? Handling of this parameter '
    75                    "will depend on source's parser."),
    75                    "will depend on source's parser."),
    76           'group': 'datafeed-source', 'level': 2,
    76           'group': 'datafeed-source', 'level': 2,
    87           'help': ('Timeout of HTTP GET requests, when synchronizing a source.'),
    87           'help': ('Timeout of HTTP GET requests, when synchronizing a source.'),
    88           'group': 'datafeed-source', 'level': 2,
    88           'group': 'datafeed-source', 'level': 2,
    89           }),
    89           }),
    90         ('use-cwuri-as-url',
    90         ('use-cwuri-as-url',
    91          {'type': 'yn',
    91          {'type': 'yn',
    92           'default': None, # explicitly unset
    92           'default': None,  # explicitly unset
    93           'help': ('Use cwuri (i.e. external URL) for link to the entity '
    93           'help': ('Use cwuri (i.e. external URL) for link to the entity '
    94                    'instead of its local URL.'),
    94                    'instead of its local URL.'),
    95           'group': 'datafeed-source', 'level': 1,
    95           'group': 'datafeed-source', 'level': 1,
    96           }),
    96           }),
    97         )
    97         )
   351         # check modification date and compare attribute values to only update
   351         # check modification date and compare attribute values to only update
   352         # what's actually needed
   352         # what's actually needed
   353         self.notify_checked(entity)
   353         self.notify_checked(entity)
   354         mdate = attrs.get('modification_date')
   354         mdate = attrs.get('modification_date')
   355         if not mdate or mdate > entity.modification_date:
   355         if not mdate or mdate > entity.modification_date:
   356             attrs = dict( (k, v) for k, v in attrs.items()
   356             attrs = dict((k, v) for k, v in attrs.items()
   357                           if v != getattr(entity, k))
   357                          if v != getattr(entity, k))
   358             if attrs:
   358             if attrs:
   359                 entity.cw_set(**attrs)
   359                 entity.cw_set(**attrs)
   360                 self.notify_updated(entity)
   360                 self.notify_updated(entity)
   361 
   361 
   362 
   362 
   422 # use a cookie enabled opener to use session cookie if any
   422 # use a cookie enabled opener to use session cookie if any
   423 _OPENER = build_opener()
   423 _OPENER = build_opener()
   424 try:
   424 try:
   425     from logilab.common import urllib2ext
   425     from logilab.common import urllib2ext
   426     _OPENER.add_handler(urllib2ext.HTTPGssapiAuthHandler())
   426     _OPENER.add_handler(urllib2ext.HTTPGssapiAuthHandler())
   427 except ImportError: # python-kerberos not available
   427 except ImportError:  # python-kerberos not available
   428     pass
   428     pass
   429 _OPENER.add_handler(HTTPCookieProcessor(CookieJar()))
   429 _OPENER.add_handler(HTTPCookieProcessor(CookieJar()))