modify storage class name
Change-Id: I1727937514933e8ccf663897dca6725e3a162e9a
diff --git a/device_user_access_storage.py b/device_storage.py
similarity index 97%
rename from device_user_access_storage.py
rename to device_storage.py
index fb0fd9e..3de7c54 100644
--- a/device_user_access_storage.py
+++ b/device_storage.py
@@ -16,7 +16,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# A copy of the GNU General Public License is in the file COPYING.
"""
-DeviceUserAccessStorage implements a basic storage of devices, users and access
+DeviceStorage implements a basic storage of devices and corresponding commands
"""
import os
@@ -24,6 +24,7 @@
from pyndn import Name
from device_profile import DeviceProfile
from hmac_key import HMACKey
+
INIT_DEVICE_TABLE = ["""
CREATE TABLE IF NOT EXISTS
Device(
@@ -36,12 +37,12 @@
serial_number BLOB,
manufacturer BLOB,
seed_name BLOB NOT NULL,
- seed_sequence BLOB NOT NULL,
- seed_counter BLOB NOT NULL,
+ seed_sequence INTEGER NOT NULL,
+ seed_counter INTEGER NOT NULL,
seed BLOB NOT NULL,
configuration_token BLOB NOT NULL,
- configuration_token_sequence BLOB NOT NULL,
- configuration_token_counter BLOB NOT NULL,
+ configuration_token_sequence INTEGER NOT NULL,
+ configuration_token_counter INTEGER NOT NULL,
PRIMARY KEY (id)
);
@@ -54,8 +55,8 @@
device_id INTEGER NOT NULL,
name BLOB NOT NULL,
command_token_name BLOB NOT NULL,
- command_token_sequence BLOB NOT NULL,
- command_token_counter BLOB NOT NULL,
+ command_token_sequence INTEGER NOT NULL,
+ command_token_counter INTEGER NOT NULL,
command_token BLOB NOT NULL,
PRIMARY KEY(id)
@@ -75,7 +76,7 @@
);
"""]
-class DeviceUserAccessStorage(object):
+class DeviceStorage(object):
"""
Create a new DeviceUserStorage to work with an SQLite file.
:param str databaseFilePath: (optional) The path of the SQLite file. If ommitted, use the default path.
@@ -251,7 +252,7 @@
cursor.execute(operation, (prefix.toUri(),))
result = cursor.fetchone()
cursor.close()
- print result
+ #print result
if result == None:
return None
else:
@@ -277,7 +278,7 @@
cursor.execute(operation, (prefix.toUri(),))
result = cursor.fetchone()
cursor.close()
- print result
+ #print result
if result == None:
return None
else:
@@ -471,7 +472,7 @@
#return None
cursor.execute(operation, (deviceId,))
result = cursor.fetchall()
- print result
+ #print result
commandList = []
if result == None:
return commandList
diff --git a/device_user_access_manager.py b/device_user_access_manager.py
index fa989c9..1d14c73 100644
--- a/device_user_access_manager.py
+++ b/device_user_access_manager.py
@@ -25,14 +25,14 @@
import sys
from pyndn.name import Name
from device_profile import DeviceProfile
-from device_user_access_storage import DeviceUserAccessStorage
+from device_storage import DeviceStorage
class DeviceUserAccessManager(object):
"""
Create a new DeviceUserAccessManager
"""
def __init__(self, databaseFilePath = None):
- deviceUserAccessStorage = DeviceUserAccessStorage(databaseFilePath)
+ deviceUserAccessStorage = DeviceStorage(databaseFilePath)
self._deviceUserAccessStorage = deviceUserAccessStorage
def createDevice(self, deviceProfile, seed, configurationToken, commandList = None):
diff --git a/fill_database_for_test.py b/fill_database_for_test.py
index 6ffc096..9a021a3 100644
--- a/fill_database_for_test.py
+++ b/fill_database_for_test.py
@@ -20,7 +20,7 @@
import os.path
from pyndn import Name
-from device_user_access_storage import DeviceUserAccessStorage
+from device_storage import DeviceStorage
from device_profile import DeviceProfile
from hmac_key import HMACKey
@@ -42,7 +42,7 @@
if os.path.isfile(self.databaseFilePath):
os.remove(self.databaseFilePath)
- self.storage = DeviceUserAccessStorage()
+ self.storage = DeviceStorage()
def fillDatabase(self):
count = self.count
diff --git a/show_devices.py b/show_devices.py
index 924ba3a..7d34dca 100644
--- a/show_devices.py
+++ b/show_devices.py
@@ -20,7 +20,7 @@
import sys
import os
import sqlite3
-from device_user_access_storage import DeviceUserAccessStorage
+from device_storage import DeviceStorage
def showDefault(databaseFilePath = None):
if databaseFilePath == None or databaseFilePath == "":
if not "HOME" in os.environ:
@@ -35,7 +35,7 @@
databaseFilePath = os.path.join(dbDirectory, 'ndnhome-controller.db')
database = sqlite3.connect(databaseFilePath)
- storage = DeviceUserAccessStorage(databaseFilePath)
+ storage = DeviceStorage(databaseFilePath)
cursor = database.cursor()
cursor.execute("SELECT id, prefix FROM Device")
print 'id: prefix: Commands: ServiceProfile:'
@@ -43,11 +43,11 @@
commandResult = storage.getCommandsOfDevice(row[0])
commandStr =''
for command in commandResult:
- commandStr += command[0] + ';'
+ commandStr += command + ';'
profileResult = storage.getServiceProfilesOfDevice(row[0])
profileStr=''
for profile in profileResult:
- profileStr = profile[0] +';'
+ profileStr = profile +';'
print '%d %s %s %s' %(row[0], row[1], commandStr, profileStr )
cursor.close()
diff --git a/tests/test_storage.py b/tests/test_device_storage.py
similarity index 98%
rename from tests/test_storage.py
rename to tests/test_device_storage.py
index dbdce7f..d04449e 100644
--- a/tests/test_storage.py
+++ b/tests/test_device_storage.py
@@ -20,11 +20,11 @@
import unittest as ut
import os.path
from pyndn import Name
-from device_user_access_storage import DeviceUserAccessStorage
+from device_storage import DeviceStorage
from device_profile import DeviceProfile
from hmac_key import HMACKey
-class TestStorageMethods(ut.TestCase):
+class TestDeviceStorageMethods(ut.TestCase):
def setUp(self):
if not "HOME" in os.environ:
home = '.'
@@ -37,7 +37,7 @@
if os.path.isfile(self.databaseFilePath):
os.remove(self.databaseFilePath)
- self.storage = DeviceUserAccessStorage()
+ self.storage = DeviceStorage()
def tearDown(self):
pass
@@ -57,7 +57,7 @@
os.makedirs(dbdir)
filePath = os.path.join(dbdir, 'ndnhome-controller.db')
- storage2 = DeviceUserAccessStorage(filePath)
+ storage2 = DeviceStorage(filePath)
self.assertTrue(os.path.isfile(filePath), 'fail to create database file' )
os.remove(filePath)