-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathCFDataTypes.py
More file actions
101 lines (81 loc) · 2.87 KB
/
CFDataTypes.py
File metadata and controls
101 lines (81 loc) · 2.87 KB
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# -*- coding: utf-8 -*-
"""
Copyright (c) 2010 Brookhaven National Laboratory
All rights reserved. Use is subject to license terms and conditions.
Created on Feb 11, 2011
@author: shroffk
"""
def cmp(a, b):
return (a > b) - (a < b)
class Channel(object):
# TODO
# updated the properties data structure by splitting it into 2 dict
# All the attributes are private and read only in an attempt to make the channel object immutable
Name = property(lambda self: self.__Name)
Owner = property(lambda self: self.__Owner)
def __init__(self, name, owner, properties=None, tags=None):
"""
Channel object constructor.
A Channel object consists of a unique name, an owner and an optional list
of Tags and Properties
:param name: channel name
:param owner: channel owner
:param properties: list of properties of type Property
:param tags: list of tags of type Tag
"""
self.__Name = str(name).strip()
self.__Owner = str(owner).strip()
self.Properties = properties
self.Tags = tags
## TODO don't recreate the dictionary with every get
def getProperties(self):
"""
Get all properties associated with calling channel.
It returns a dictionary with format:
{"property name": "property value",
...
}
:return: dictionary of properties, or None if property is empty
"""
propDictionary = {}
if self.Properties is None:
return None
for prop in self.Properties:
propDictionary[prop.Name] = prop.Value
return propDictionary
def getTags(self):
"""
Get all tags associated with calling channel.
All names in the results are unique, and duplicated name are removed.
It returns a list of tag names with format ['tag 1', 'tag 2', ...]
:return: list of tags, or None if tag is empty
"""
if self.Tags is None:
return None
else:
return set([tag.Name for tag in self.Tags])
class Property(object):
def __init__(self, name, owner, value=None):
"""
Property consists of a name, an owner and a value
"""
self.Name = str(name).strip()
self.Owner = str(owner).strip()
self.Value = value
if self.Value:
str(value).strip()
def __cmp__(self, *arg, **kwargs):
if arg[0] is None:
return 1
return cmp((self.Name, self.Value), (arg[0].Name, arg[0].Value))
class Tag(object):
def __init__(self, name, owner):
"""
Tag object consists on a name and an owner
"""
self.Name = str(name).strip()
self.Owner = str(owner).strip()
def __cmp__(self, *arg, **kwargs):
if arg[0] is None:
return 1
return cmp(self.Name, arg[0].Name)