susmit shannigrahi | 7c5de01 | 2015-03-30 16:18:01 -0600 | [diff] [blame] | 1 | #!/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 Shannigrahi | cad29ca | 2015-06-17 10:10:01 -0600 | [diff] [blame] | 25 | from ndn_cmmap_translators.atmos2ndn_parser import conf_file_parser, cmd_arg_parser |
| 26 | from ndn_cmmap_translators.atmos2ndn_translators import translate |
susmit shannigrahi | 7c5de01 | 2015-03-30 16:18:01 -0600 | [diff] [blame] | 27 | |
| 28 | def 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 shannigrahi | 851e88b | 2015-06-08 15:33:29 -0600 | [diff] [blame] | 36 | |
| 37 | #library would throw exceptions, if any |
susmit shannigrahi | 7c5de01 | 2015-03-30 16:18:01 -0600 | [diff] [blame] | 38 | parsedConfig = conf_file_parser.ParseConf(configPath) |
susmit shannigrahi | 851e88b | 2015-06-08 15:33:29 -0600 | [diff] [blame] | 39 | |
susmit shannigrahi | 7c5de01 | 2015-03-30 16:18:01 -0600 | [diff] [blame] | 40 | |
| 41 | #do the translation |
susmit shannigrahi | 851e88b | 2015-06-08 15:33:29 -0600 | [diff] [blame] | 42 | ndnNames = translate.translate(parsedConfig, dataFilepath) |
susmit shannigrahi | 7c5de01 | 2015-03-30 16:18:01 -0600 | [diff] [blame] | 43 | if __debug__: |
susmit shannigrahi | 851e88b | 2015-06-08 15:33:29 -0600 | [diff] [blame] | 44 | print("NDN names in atmos_translate module: %s" %(ndnNames)) |
| 45 | return ndnNames |
| 46 | |
susmit shannigrahi | 7c5de01 | 2015-03-30 16:18:01 -0600 | [diff] [blame] | 47 | |
| 48 | def main(): |
susmit shannigrahi | 851e88b | 2015-06-08 15:33:29 -0600 | [diff] [blame] | 49 | |
| 50 | '''This main is for debug only, run with the debug flag on. |
| 51 | Otherwise call argsForTranslation from a wrapper function''' |
susmit shannigrahi | 7c5de01 | 2015-03-30 16:18:01 -0600 | [diff] [blame] | 52 | |
| 53 | userArgs = cmd_arg_parser.InputParser() |
| 54 | userArgs.parse() |
| 55 | configFile = userArgs.confFilepath |
susmit shannigrahi | 7c5de01 | 2015-03-30 16:18:01 -0600 | [diff] [blame] | 56 | if __debug__: |
| 57 | print("config file '%s', data path '%s'" %(configFile, userArgs.dataFilepath)) |
| 58 | |
| 59 | #call the translator module |
susmit shannigrahi | 851e88b | 2015-06-08 15:33:29 -0600 | [diff] [blame] | 60 | ndnNames = argsForTranslation(userArgs.dataFilepath, configFile) |
| 61 | |
susmit shannigrahi | 7c5de01 | 2015-03-30 16:18:01 -0600 | [diff] [blame] | 62 | |
| 63 | if __name__ == '__main__': |
| 64 | main() |