示例#1
0
 def _open_db(self):
     # If there's no CC db in moneyGuru's appdata folder, copy a model from CC's appdata.
     if not self.has_db():
         if not io.exists(self._mgccdbpath[:-1]):
             io.makedirs(self._mgccdbpath[:-1])
         io.copy(self._ccdbpath, self._mgccdbpath)
     self._db = CashculatorDB(str(self._mgccdbpath))
示例#2
0
 def __init__(self, view, date_format='dd/MM/yyyy', decimal_sep='.', grouping_sep='', 
     default_currency=USD, cache_path=None, appdata_path=None, plugin_model_path=None):
     Broadcaster.__init__(self)
     self.view = view
     self.cache_path = cache_path
     # cache_path is required, but for tests, we don't want to bother specifying it. When 
     # cache_path is kept as None, the path of the currency db will be ':memory:'
     if cache_path:
         if not io.exists(cache_path):
             io.makedirs(cache_path)
         db_path = op.join(cache_path, 'currency.db')
     else:
         db_path = ':memory:'
     self.appdata_path = appdata_path
     currency.initialize_db(db_path)
     self.is_first_run = not self.get_default(PreferenceNames.HadFirstLaunch, False)
     if self.is_first_run:
         self.set_default(PreferenceNames.HadFirstLaunch, True)
     self._default_currency = default_currency
     self._date_format = date_format
     self._decimal_sep = decimal_sep
     self._grouping_sep = grouping_sep
     self._autosave_timer = None
     self._autosave_interval = self.get_default(PreferenceNames.AutoSaveInterval, 10)
     self._auto_decimal_place = self.get_default(PreferenceNames.AutoDecimalPlace, False)
     self._show_schedule_scope_dialog = self.get_default(PreferenceNames.ShowScheduleScopeDialog, True)
     self.saved_custom_ranges = [None] * 3
     self._load_custom_ranges()
     self._load_plugins(plugin_model_path)
     self._hook_currency_plugins()
     self._update_autosave_timer()
示例#3
0
 def __ProcessNormalList(self, name_list, copy=False, job=nulljob):
     name_list = [
         paths for paths in name_list
         if (paths[0] != paths[1]) and io.exists(paths[0])
     ]
     conflicts = []
     tmpdir = None
     job.start_job(len(name_list))
     for source, dest in name_list:
         try:
             if io.exists(dest):
                 if not tmpdir:
                     tmpdir = Path(tempfile.mkdtemp())
                 newdest = tmpdir + dest[self.destination:]
                 conflicts.append((newdest, dest, source))
                 dest = newdest
             if not io.exists(dest[:-1]):
                 io.makedirs(dest[:-1])
             if copy:
                 io.copy(source, dest)
             else:
                 io.move(source, dest)
         except (OSError, IOError) as e:
             print("Warning: Error %r occured while processing %r to %r."\
                 % (e, str(source), str(dest)))
         job.add_progress()
     for source, dest, old_source in conflicts:
         if not io.exists(dest):
             io.rename(source, dest)
         elif not io.exists(old_source):
             io.rename(source, old_source)
示例#4
0
 def render(self, destpath, menu, env):
     dest = destpath + self.basepath + '{0}.htm'.format(self.basename)
     if not io.exists(dest[:-1]):
         io.makedirs(dest[:-1])
     mdcontents = io.open(self.path, 'rt', encoding='utf-8').read()
     mdcontents = mdcontents.format(**env)
     main_contents = markdown.markdown(mdcontents)
     rendered = MAIN_CONTENTS.format(meta=self.meta, title=self.title, relpath=self.relpath,
         menu=menu, contents=main_contents)
     fp = io.open(dest, 'wt', encoding='utf-8')
     fp.write(rendered)
     fp.close()
示例#5
0
 def render(self, destpath, menu, env):
     dest = destpath + self.basepath + '{0}.htm'.format(self.basename)
     if not io.exists(dest[:-1]):
         io.makedirs(dest[:-1])
     mdcontents = io.open(self.path, 'rt', encoding='utf-8').read()
     mdcontents = mdcontents.format(**env)
     main_contents = markdown.markdown(mdcontents)
     rendered = MAIN_CONTENTS.format(meta=self.meta,
                                     title=self.title,
                                     relpath=self.relpath,
                                     menu=menu,
                                     contents=main_contents)
     fp = io.open(dest, 'wt', encoding='utf-8')
     fp.write(rendered)
     fp.close()
示例#6
0
 def __ProcessCDList(self, name_list, cd_path, cd_location, job=nulljob):
     job.start_job(len(name_list))
     for source, dest in name_list:
         if not io.exists(dest[:-1]):
             io.makedirs(dest[:-1])
         if not io.exists(dest):
             processed = False
             while cd_path and (not processed):
                 try:
                     io.copy((cd_path + source), dest)
                     processed = True
                 except (OSError, IOError):
                     if io.exists(cd_path + source):
                         processed = True
                         #This is a very special case. It happens when the path on the
                         #CD is too long to be copied. It very seldom happens. Just skip the file.
                     else:
                         cd_path = self.OnNeedCD(cd_location)
                         if cd_path:
                             cd_path = Path(cd_path)
                         else:
                             return False
         job.add_progress()
     return True