Prepare argparse & pickle.
(self)
| 128 | """ |
| 129 | |
| 130 | def __init__(self): |
| 131 | """ |
| 132 | Prepare argparse & pickle. |
| 133 | """ |
| 134 | |
| 135 | # create the parser |
| 136 | parser = argparse.ArgumentParser( |
| 137 | description=self.__class__.__doc__, |
| 138 | argument_default=argparse.SUPPRESS) |
| 139 | |
| 140 | # add the arguments |
| 141 | parser.add_argument('--add', '-a', type=int, dest='add', action=Operate, |
| 142 | help='add some free days', default=0) |
| 143 | parser.add_argument('--remove', '-rm', type=int, dest='remove', action=Operate, |
| 144 | help='remove some free days', default=0) |
| 145 | parser.add_argument('--reset', type=int, dest='reset', |
| 146 | action=Operate, |
| 147 | help='reset holiday base', default=26) |
| 148 | parser.add_argument('--show', action=Operate, nargs='?', |
| 149 | help='show holiday changelog') |
| 150 | parser.add_argument('--clear', action=Operate, nargs='?', |
| 151 | help='clear all logs') |
| 152 | |
| 153 | # create file | use the existing one |
| 154 | try: |
| 155 | Log.history = pickle.load(open('history.p', 'rb')) |
| 156 | except IOError: |
| 157 | output = open(STATIC_P, 'wb') |
| 158 | Log.history = [('*' + \ |
| 159 | str(int(raw_input('Your holiday base (int): '))), |
| 160 | time.strftime(STATIC_T, time.gmtime()))] |
| 161 | pickle.dump( Log.history, output, protocol=PROTOCOL ) |
| 162 | output.close() |
| 163 | finally: |
| 164 | parser.parse_args() |
| 165 | |
| 166 | if __name__ == '__main__': |
| 167 | LEAVE = Leave() |