Changeset 5125 for nappy/trunk


Ignore:
Timestamp:
20/03/09 15:07:16 (11 years ago)
Author:
astephen
Message:

Added some fixes after command-line testing.

Location:
nappy/trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • nappy/trunk/bin/nc2na.py

    r3394 r5125  
    4141 
    4242# Import from nappy package 
    43 import nappy.nc_convertor.nc_to_na 
     43import nappy 
    4444import nappy.utils.common_utils 
    4545 
     
    8585            a["exclude_vars"] = value.split(",") 
    8686        elif arg == "--overwrite-metadata": 
    87             a["na_items_to_override"] = nappy.utils.makeDictFromCommaSepString(value) 
     87            a["na_items_to_override"] = makeDictFromCommaSepString(value) 
    8888        elif arg == "--names-only": 
    8989            a["only_return_file_names"] = True 
  • nappy/trunk/nappy/nappy_api.py

    r4693 r5125  
    197197        del arg_dict[arg_out] 
    198198 
    199     convertor = apply(nappy.nc_convertor.na_to_nc.NAToNC, [], arg_dict) 
     199    import nappy.nc_interface.na_to_nc 
     200    convertor = apply(nappy.nc_interface.na_to_nc.NAToNC, [], arg_dict) 
    200201    convertor.convert() 
    201202    if nc_file == None: 
     
    269270        na_file =  nappy.utils.getFileNameWithNewExtension(nc_file, "na") 
    270271 
    271     convertor = apply(nappy.nc_convertor.nc_to_na.NCToNA, [], arg_dict) 
     272    import nappy.nc_interface.nc_to_na 
     273    convertor = apply(nappy.nc_interface.nc_to_na.NCToNA, [], arg_dict) 
    272274    convertor.convert() 
    273275 
  • nappy/trunk/nappy/nc_interface/na_to_cdms.py

    r4693 r5125  
    224224                self.cdms_variables.append(self._convertNAToCdmsVariable(var_number)) 
    225225        else: 
    226             if type(self.variables[0]) == type(1): # They are integers = indices 
     226            if type(self.variables[0]) == type(1) or re.match("\d+", str(self.variables[0])): # They are integers = indices 
    227227                for var_number in self.variables: 
    228                     self.cdms_variables.append(self._convertNAToCdmsVariable(var_number))    
     228                    vn = int(var_number) 
     229                    self.cdms_variables.append(self._convertNAToCdmsVariable(vn))    
    229230            elif type(self.variables[0]) == type("string"):  # Vars are strings 
    230231                for var_name in self.variables: 
  • nappy/trunk/nappy/utils/common_utils.py

    r3999 r5125  
    146146 
    147147    d = {} 
    148     items = value.split(",") 
     148    items = s.split(",") 
    149149    while len(items) > 0: 
    150150        d[items[0]] = items[1] 
    151151        items = items[2:]  
    152152    return d 
     153 
     154 
     155def makeListFromCommaSepString(s): 
     156    """ 
     157    Reads in comma-separated list and converts to list of successive 
     158    keyword,value pairs. 
     159    """ 
     160    if s.count(",") % 2 == 0: 
     161        raise Exception("Must provide even number of items in argument of commas-separated pairs of values: " + s) 
     162 
     163    l = [] 
     164    items = s.split(",") 
     165    while len(items) > 0: 
     166        l.append((items[0], items[1])) 
     167        items = items[2:] 
     168    return l 
    153169 
    154170 
Note: See TracChangeset for help on using the changeset viewer.