Changeset 2974 for branch


Ignore:
Timestamp:
Aug 8, 2017 4:50:04 PM (6 years ago)
Author:
odonnell
Message:

remove prints in LoadDictFromProjFile?, SaveDictToProjFile?, add dump args

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branch/2frame/GSASIIscriptable.py

    r2968 r2974  
    8686        ]
    8787    '''
    88     if not ospath.exists(ProjFile):
    89         print ('\n*** Error attempt to open project file that does not exist:\n   '+
    90             str(ProjFile))
    91         return
     88    # Let IOError be thrown if file does not exist
     89    # if not ospath.exists(ProjFile):
     90    #     print ('\n*** Error attempt to open project file that does not exist:\n   '+
     91    #         str(ProjFile))
     92    #     return
    9293    file = open(ProjFile,'rb')
    93     print('loading from file: {}'.format(ProjFile))
     94    # print('loading from file: {}'.format(ProjFile))
    9495    Project = {}
    9596    nameList = []
     
    107108                nameList[-1].append(datus[0])
    108109        file.close()
    109         print('project load successful')
     110        # print('project load successful')
    110111    except:
    111         print("Error reading file "+str(ProjFile)+". This is not a GSAS-II .gpx file")
    112         return None
     112        raise IOError("Error reading file "+str(ProjFile)+". This is not a GSAS-II .gpx file")
     113    finally:
     114        file.close()
    113115    return Project,nameList
    114116
     
    122124    '''
    123125    file = open(ProjFile,'wb')
    124     print('save to file: {}'.format(ProjFile))
    125     for name in nameList:
    126         data = []
    127         item = Project[name[0]]
    128         data.append([name[0],item['data']])
    129         for item2 in name[1:]:
    130             data.append([item2,item[item2]])
    131         cPickle.dump(data,file,1)
    132     file.close()
    133     print('project save successful')
     126    # print('save to file: {}'.format(ProjFile))
     127    try:
     128        for name in nameList:
     129            data = []
     130            item = Project[name[0]]
     131            data.append([name[0],item['data']])
     132            for item2 in name[1:]:
     133                data.append([item2,item[item2]])
     134            cPickle.dump(data,file,1)
     135    finally:
     136        file.close()
     137    # print('project save successful')
    134138
    135139def ImportPowder(reader,filename):
     
    880884        phases = self.data['Phases']
    881885        if phasename in phases:
    882             return G2Phase(phases[phasename], self)
     886            return G2Phase(phases[phasename], phasename, self)
    883887
    884888    def phases(self):
     
    12951299    Author: Jackson O'Donnell jacksonhodonnell@gmail.com
    12961300    """
    1297     def __init__(self, data, proj):
     1301    def __init__(self, data, name, proj):
    12981302        self.data = data
     1303        self.name = name
    12991304        self.proj = proj
    13001305
     
    14411446def dump(*args):
    14421447    """The dump subcommand"""
    1443     import IPython.lib.pretty as pretty
    1444     proj, nameList = LoadDictFromProjFile(args[0])
    1445     print("names:", nameList)
    1446     for key, val in proj.items():
    1447         print(key, ":", sep='')
    1448         pretty.pprint(val)
     1448    raw = True
     1449    histograms = False
     1450    phases = False
     1451    filenames = []
     1452    for arg in args:
     1453        if arg in ['-h', '--histograms']:
     1454            histograms = True
     1455            raw = False
     1456        elif arg in ['-p', '--phases']:
     1457            phases = True
     1458            raw = False
     1459        elif arg in ['-r', '--raw']:
     1460            raw = True
     1461        else:
     1462            filenames.append(arg)
     1463    if raw:
     1464        import IPython.lib.pretty as pretty
     1465    for fname in filenames:
     1466        if raw:
     1467            proj, nameList = LoadDictFromProjFile(fname)
     1468            print("file:", fname)
     1469            print("names:", nameList)
     1470            for key, val in proj.items():
     1471                print(key, ":")
     1472                pretty.pprint(val)
     1473        else:
     1474            proj = G2Project(fname)
     1475            if histograms:
     1476                hists = proj.histograms()
     1477                for h in hists:
     1478                    print(fname, h.name)
     1479            if phases:
     1480                phases = proj.phases()
     1481                for p in phases:
     1482                    print(fname, p.name)
    14491483
    14501484
     
    14611495
    14621496def export(*args):
     1497    """The export subcommand"""
     1498    # Export CIF or Structure or ...
    14631499    pass
    14641500
Note: See TracChangeset for help on using the changeset viewer.