コード例 #1
0
ファイル: ConfigManip.py プロジェクト: JasonLai256/pyExpenses
 def delOption(cls, section, val):
     if section not in ['Type', 'Payment', 'Currency', 'Tag']:
         EH.valueError('section value is invalid.')
     if section == 'Type':
         _delTypeOpt(cls.obj, mtype=val[0], subtype=val[1])
     else:
         if val in cls.obj[section]['types']:
             cls.obj[section]['types'].remove(val)
     _exportObj(cls.obj, cls.objfile)
コード例 #2
0
ファイル: RecParser.py プロジェクト: JasonLai256/pyExpenses
 def append(self, parser):
     if parser.type == 'filter':
         self._ft_list.append(parser)
     elif parser.type == 'statistic':
         self._stat_list.append(parser)
     elif parser.type == 'analysis':
         self._analy_list.append(parser)
     else:
         EH.valueError("{0} is can't recognize.".format(parser.type))
コード例 #3
0
ファイル: RecParser.py プロジェクト: JasonLai256/pyExpenses
 def _test_and_correct(self, mthlist):
     for i in xrange(len(mthlist)):
         int(mthlist[i])
         
     for item in mthlist:
         if not 1 <= item <= 12:
             EH.valueError('{0} is not a correct number in months.' \
                               .format(item))
     return mthlist
コード例 #4
0
ファイル: RecParser.py プロジェクト: JasonLai256/pyExpenses
 def _test_and_correct(self, daylist):
     for i in xrange(len(daylist)):
         daylist[i] = int(daylist[i])
         
     for item in daylist:
         if not 1 <= item <= 31:
             EH.valueError(
                 '{0} is not a correct number in day of months.'.format(item)
             )
     return daylist
コード例 #5
0
ファイル: ConfigManip.py プロジェクト: JasonLai256/pyExpenses
 def setInfo(cls, option, value):
     """Set the given option to the specifit value for BaseInfo section.
     @note: there are not to check the value is valid or not, so need
            to ensure value is valid before invoke this method.
     """
     if not cls.obj['BaseInfo'].has_key(option):
         EH.attrError(
             'Expense info has not "{0}" option.'.format(option)
         )
     cls.obj['BaseInfo'][option] = value
     _exportObj(cls.obj, cls.objfile)
コード例 #6
0
ファイル: ConfigManip.py プロジェクト: JasonLai256/pyExpenses
 def getOptions(cls, section):
     if section not in ['Type', 'Payment', 'Currency', 'Tag']:
         EH.valueError('section value is invalid.')
     retval = []
     if section == 'Type':
         for t in cls.obj[section]['type_order']:
             retval.append(
                 (t, cls.obj['Type']['types'][t])
             )
     else:
         retval = cls.obj[section]['types']
     return retval
コード例 #7
0
ファイル: utils.py プロジェクト: JasonLai256/pyExpenses
def to_date(da):
    """假设da的格式为'yyyy-mm-dd'."""
    if isinstance(da, date):
        return da
    elif isinstance(da, (str, unicode)):
        if datecheck(da):
            y = int(da[:4])
            m = int(da[5:7])
            d = int(da[8:])
            return date(y, m, d)
    else:
        EH.valueError('date ({0}) format error.'.format(str(da)))
コード例 #8
0
ファイル: ConfigManip.py プロジェクト: JasonLai256/pyExpenses
 def addOption(cls, section, val):
     """If val is not exist then create a new one that suit to the
     situation of section. On the other hand, if val is already exist
     nothing will happends.
     """
     if section not in ['Type', 'Payment', 'Currency', 'Tag']:
         EH.valueError('section value is invalid.')
     if section == 'Type':
         _addTypeOpt(cls.obj, mtype=val[0], subtype=val[1])
     else:
         if val not in cls.obj[section]['types']:
             cls.obj[section]['types'].append(val)
     _exportObj(cls.obj, cls.objfile)
コード例 #9
0
ファイル: ConfigManip.py プロジェクト: JasonLai256/pyExpenses
    def __new__(cls, name, bases, dict):
        try:            
            dict['objfile'] = 'config.json'
            dict['buffile'] = 'databuf.json'
            dict['obj'] = _importObj(filename=dict['objfile'])
            # A storing object that contain the datas of project's buffer
            # and records buffer by json format.
            dict['bufobj'] = _importObj(filename=dict['buffile'])

            dict['obj']['BaseInfo']['path'] = abspath(dirname(__file__))
        except IOError:
            EH.ioError(
                "file not exist, can't initialise program."
            )
        return super(cls, ConfiMeta).__new__(cls, name, bases, dict)
コード例 #10
0
ファイル: RecParser.py プロジェクト: JasonLai256/pyExpenses
 def _test(self):
     if self.start < 0 or self.stop < 0 or \
     self.stop < self.start:
         EH.valueError("start number({0}) and stop number({1}) has" \
                           "value problem.".format(self.start, self.stop))