blob: a12b420ea121a4d815914ddfcf2b4eeb89bcf809 [file] [log] [blame]
susmit shannigrahi7c5de012015-03-30 16:18:01 -06001#!/usr/bin/env python3
2
3# -*- Mode:python; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
4#
5# Copyright (c) 2015, Colorado State University.
6#
7# This file is part of ndn-atmos.
8#
9# ndn-atmos is free software: you can redistribute it and/or modify it under the
10# terms of the GNU Lesser General Public License as published by the Free Software
11# Foundation, either version 3 of the License, or (at your option) any later version.
12#
13# ndn-atmos is distributed in the hope that it will be useful, but WITHOUT ANY
14# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
15# PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
16#
17# You should have received copies of the GNU General Public License and GNU Lesser
18# General Public License along with ndn-atmos, e.g., in COPYING.md file. If not, see
19# <http://www.gnu.org/licenses/>.
20#
21# See AUTHORS.md for complete list of ndn-atmos authors and contributors.
22
23'''Translates a netcdf filename to a NDN name'''
24
Susmit Shannigrahicad29ca2015-06-17 10:10:01 -060025from ndn_cmmap_translators.atmos2ndn_parser import conf_file_parser, cmd_arg_parser
26from ndn_cmmap_translators.atmos2ndn_translators import translate
susmit shannigrahi7c5de012015-03-30 16:18:01 -060027
28def argsForTranslation(dataFilepath, configPath):
29 '''this module does the actual translation calls'''
30 if __debug__:
31 print("config file '%s', data path '%s'" %(configPath, dataFilepath))
32
33 #pass the config file to parser module, which will return and object
34 #with all the mappings. The mappings tell us which name component
35 #comes from where and what should be the order of the components
susmit shannigrahi851e88b2015-06-08 15:33:29 -060036
37 #library would throw exceptions, if any
susmit shannigrahi7c5de012015-03-30 16:18:01 -060038 parsedConfig = conf_file_parser.ParseConf(configPath)
susmit shannigrahi851e88b2015-06-08 15:33:29 -060039
susmit shannigrahi7c5de012015-03-30 16:18:01 -060040
41 #do the translation
susmit shannigrahi851e88b2015-06-08 15:33:29 -060042 ndnNames = translate.translate(parsedConfig, dataFilepath)
susmit shannigrahi7c5de012015-03-30 16:18:01 -060043 if __debug__:
susmit shannigrahi851e88b2015-06-08 15:33:29 -060044 print("NDN names in atmos_translate module: %s" %(ndnNames))
45 return ndnNames
46
susmit shannigrahi7c5de012015-03-30 16:18:01 -060047
48def main():
susmit shannigrahi851e88b2015-06-08 15:33:29 -060049
50 '''This main is for debug only, run with the debug flag on.
51 Otherwise call argsForTranslation from a wrapper function'''
susmit shannigrahi7c5de012015-03-30 16:18:01 -060052
53 userArgs = cmd_arg_parser.InputParser()
54 userArgs.parse()
55 configFile = userArgs.confFilepath
susmit shannigrahi7c5de012015-03-30 16:18:01 -060056 if __debug__:
57 print("config file '%s', data path '%s'" %(configFile, userArgs.dataFilepath))
58
59 #call the translator module
susmit shannigrahi851e88b2015-06-08 15:33:29 -060060 ndnNames = argsForTranslation(userArgs.dataFilepath, configFile)
61
susmit shannigrahi7c5de012015-03-30 16:18:01 -060062
63if __name__ == '__main__':
64 main()