blob: 924ba3af24fd8af691bb33ceaf260583819c56fa [file] [log] [blame]
Weiweie5640c62015-07-31 01:43:01 -07001# -*- Mode:python; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
2#
3# Copyright (C) 2014-2015 Regents of the University of California.
4# Author: Weiwei Liu <summerwing10@gmail.com>
5#
6# This program is free software: you can redistribute it and/or modify
7# it under the terms of the GNU Lesser General Public License as published by
8# the Free Software Foundation, either version 3 of the License, or
9# (at your option) any later version.
10#
11# This program is distributed in the hope that it will be useful,
12# but WITHOUT ANY WARRANTY; without even the implied warranty of
13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14# GNU Lesser General Public License for more details.
15#
16# You should have received a copy of the GNU Lesser General Public License
17# along with this program. If not, see <http://www.gnu.org/licenses/>.
18# A copy of the GNU Lesser General Public License is in the file COPYING.
19
20import sys
21import os
22import sqlite3
23from device_user_access_storage import DeviceUserAccessStorage
24def showDefault(databaseFilePath = None):
25 if databaseFilePath == None or databaseFilePath == "":
26 if not "HOME" in os.environ:
27 home = '.'
28 else:
29 home = os.environ["HOME"]
30
31 dbDirectory = os.path.join(home, '.ndn')
32 if not os.path.exists(dbDirectory):
33 os.makedirs(dbDirectory)
34
35 databaseFilePath = os.path.join(dbDirectory, 'ndnhome-controller.db')
36
37 database = sqlite3.connect(databaseFilePath)
38 storage = DeviceUserAccessStorage(databaseFilePath)
39 cursor = database.cursor()
40 cursor.execute("SELECT id, prefix FROM Device")
41 print 'id: prefix: Commands: ServiceProfile:'
42 for row in cursor.fetchall():
43 commandResult = storage.getCommandsOfDevice(row[0])
44 commandStr =''
45 for command in commandResult:
46 commandStr += command[0] + ';'
47 profileResult = storage.getServiceProfilesOfDevice(row[0])
48 profileStr=''
49 for profile in profileResult:
50 profileStr = profile[0] +';'
51 print '%d %s %s %s' %(row[0], row[1], commandStr, profileStr )
52
53 cursor.close()
54
55
56
57if len(sys.argv) < 2:
58 showDefault()
59
60else:
61 raise RuntimeError("options is not implemented yet")
62
63