-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtopic.py
More file actions
156 lines (129 loc) · 4.45 KB
/
topic.py
File metadata and controls
156 lines (129 loc) · 4.45 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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
# -*- coding: utf-8 -*-
# This file is part of POS with TIBS.
#
# POS with TIBS is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# POS with TIBS is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with POS with TIBS. If not, see <http://www.gnu.org/licenses/>.
#
#
#
# Module Name:
#
# topic.py
#
# Abstract:
#
# Author:
#
# Project Manager : Feng-Pu Yabg
# Core Team Member: Bai-Small
#
# Project:
#
# OpenISDM
#
# -*-
#from posdata import PosData
import os
import json
class Topic:
def __init__(self, tname, acc_path, data_path):
self.name = tname
self.acc_path = acc_path
self.data_path = data_path
def get_publisher(self):
pass
def get_id(self):
return self.id
def btn(self):
pass
def process_acc(self):
return_val = {}
return_val['vaildable'] = True
return return_val
#print self.name
#next iteration
def get_name(self):
return self.name
def get_tags(self):
pass
def get_version(self):
return self.version
def add_data(self):
# 1. data description (from metadata)
# 2. data_id (from metadata)
# 3. data_name
# 4. accountability_name (from metadata)
# 5. accountability_description (from metadata)
#
# TODO: read metadata and write self.data_profile
for data in self.data_set:
metadata = self.read_metadata(self.root)
acc_folder = os.path.join(self.root, "acc")
acc = self.acc_build(metadata, acc_folder)
data_obj = PosData(metadata["data_name"], metadata["data_id"], metadata["data_desc"],acc)
if not data_obj in self.data_list:
self.data_list.append(data_obj)
def get_data(self):
# 1. check data accountability
# 2. delegate to accountability function (provided by publisher)
# 3. if success, return data and save accountability record
# else, return nothing and save accountability record
'''data = self.data_profile[data_id]
#data-level
data_acc_desc = data['accountability_description']
data_acc_name = data['accountability_name']
data_description = data['description']
#object-level
data_object_names = data['object_names']
data_object_descriptions = data['object_descriptions']'''
return self.data_list
def read_metadata(self, root):
''' This function read metadata content if it isn't missing
or is not mismatch.
:param root: string -- the metadata location
:returns: dictionary -- the metadata content.
'''
#TODO:
# Error checking:
# 1. no metadata
# 2. mismatch between t_data & scanned result
if self.__err_detector_metadata_data_mismatch():
self.__err_handler_metadata_data_mismatch()
if self.__err_detector_no_metadata():
self.__err_handler_no_metadata()
path = os.path.join(root, "data.metadata")
json_data = open(path)
metadata = json.load(json_data)
return metadata
#TODO: read metadata
# ...
def acc_build(self, metadata, acc_folder):
'''This function use a dictionary to store acc properties
like its name, description and path.
:param metadata: dictionary -- The data about topic data.
:param acc_folder: string -- The location of accountability folder.
:returns: dictionary -- the detail of accountability.
'''
acc = {}
acc["name"] = metadata["accountability_name"]
acc["desc"] = metadata["accountability_description"]
acc["path"] = os.path.join(acc_folder, acc["name"])
return acc
def __err_detector_metadata_data_mismatch(self):
pass
def __err_detector_no_metadata(self):
pass
def __err_handler_metadata_data_mismatch(self):
pass
def __err_handler_no_metadata(self):
pass