blob: 7d34dca938195ef751367928242ee8854809e3e9 [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
Weiweif3132ed2015-08-05 11:20:49 -070023from device_storage import DeviceStorage
Weiweie5640c62015-07-31 01:43:01 -070024def 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)
Weiweif3132ed2015-08-05 11:20:49 -070038 storage = DeviceStorage(databaseFilePath)
Weiweie5640c62015-07-31 01:43:01 -070039 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:
Weiweif3132ed2015-08-05 11:20:49 -070046 commandStr += command + ';'
Weiweie5640c62015-07-31 01:43:01 -070047 profileResult = storage.getServiceProfilesOfDevice(row[0])
48 profileStr=''
49 for profile in profileResult:
Weiweif3132ed2015-08-05 11:20:49 -070050 profileStr = profile +';'
Weiweie5640c62015-07-31 01:43:01 -070051 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