mirror of
https://gitlab.com/fdroid/fdroidserver.git
synced 2024-09-11 23:23:27 +02:00
Add documentation to new App class
This commit is contained in:
parent
ab614ab442
commit
6e87a8c45a
@ -53,6 +53,8 @@ class MetaDataException(Exception):
|
|||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.value
|
return self.value
|
||||||
|
|
||||||
|
# To filter which ones should be written to the metadata files if
|
||||||
|
# present
|
||||||
app_fields = set([
|
app_fields = set([
|
||||||
'Disabled',
|
'Disabled',
|
||||||
'AntiFeatures',
|
'AntiFeatures',
|
||||||
@ -135,10 +137,14 @@ class App():
|
|||||||
self.added = None
|
self.added = None
|
||||||
self.lastupdated = None
|
self.lastupdated = None
|
||||||
|
|
||||||
|
# Translates human-readable field names to attribute names, e.g.
|
||||||
|
# 'Auto Name' to 'AutoName'
|
||||||
@classmethod
|
@classmethod
|
||||||
def field_to_attr(cls, f):
|
def field_to_attr(cls, f):
|
||||||
return f.replace(' ', '')
|
return f.replace(' ', '')
|
||||||
|
|
||||||
|
# Translates attribute names to human-readable field names, e.g.
|
||||||
|
# 'AutoName' to 'Auto Name'
|
||||||
@classmethod
|
@classmethod
|
||||||
def attr_to_field(cls, k):
|
def attr_to_field(cls, k):
|
||||||
if k in app_fields:
|
if k in app_fields:
|
||||||
@ -146,21 +152,26 @@ class App():
|
|||||||
f = re.sub(r'([a-z])([A-Z])', r'\1 \2', k)
|
f = re.sub(r'([a-z])([A-Z])', r'\1 \2', k)
|
||||||
return f
|
return f
|
||||||
|
|
||||||
|
# Constructs an old-fashioned dict with the human-readable field
|
||||||
|
# names. Should only be used for tests.
|
||||||
def field_dict(self):
|
def field_dict(self):
|
||||||
return {App.attr_to_field(k): v for k, v in self.__dict__.iteritems()}
|
return {App.attr_to_field(k): v for k, v in self.__dict__.iteritems()}
|
||||||
|
|
||||||
|
# Gets the value associated to a field name, e.g. 'Auto Name'
|
||||||
def get_field(self, f):
|
def get_field(self, f):
|
||||||
if f not in app_fields:
|
if f not in app_fields:
|
||||||
raise MetaDataException('Unrecognised app field: ' + f)
|
raise MetaDataException('Unrecognised app field: ' + f)
|
||||||
k = App.field_to_attr(f)
|
k = App.field_to_attr(f)
|
||||||
return getattr(self, k)
|
return getattr(self, k)
|
||||||
|
|
||||||
|
# Sets the value associated to a field name, e.g. 'Auto Name'
|
||||||
def set_field(self, f, v):
|
def set_field(self, f, v):
|
||||||
if f not in app_fields:
|
if f not in app_fields:
|
||||||
raise MetaDataException('Unrecognised app field: ' + f)
|
raise MetaDataException('Unrecognised app field: ' + f)
|
||||||
k = App.field_to_attr(f)
|
k = App.field_to_attr(f)
|
||||||
self.__dict__[k] = v
|
self.__dict__[k] = v
|
||||||
|
|
||||||
|
# Appends to the value associated to a field name, e.g. 'Auto Name'
|
||||||
def append_field(self, f, v):
|
def append_field(self, f, v):
|
||||||
if f not in app_fields:
|
if f not in app_fields:
|
||||||
raise MetaDataException('Unrecognised app field: ' + f)
|
raise MetaDataException('Unrecognised app field: ' + f)
|
||||||
@ -170,6 +181,7 @@ class App():
|
|||||||
else:
|
else:
|
||||||
self.__dict__[k].append(v)
|
self.__dict__[k].append(v)
|
||||||
|
|
||||||
|
# Like dict.update(), but using human-readable field names
|
||||||
def update_fields(self, d):
|
def update_fields(self, d):
|
||||||
for f, v in d.iteritems():
|
for f, v in d.iteritems():
|
||||||
self.set_field(f, v)
|
self.set_field(f, v)
|
||||||
|
Loading…
Reference in New Issue
Block a user