Exemplo n.º 1
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)
Exemplo n.º 2
0
def gen(basepath, destpath, profile=None):
    basepath = Path(basepath)
    destpath = Path(destpath)
    configpath = basepath + 'conf.yaml'
    confall = yaml.load(io.open(configpath, 'rt', encoding='utf-8'))
    conf = confall['base']
    if profile and profile in confall:
        conf.update(confall[profile])
    tixurl = conf['tixurl']
    changelogdata = read_changelog_file(str(basepath + conf['changelog']))
    changelog = render_changelog(changelogdata, tixurl)
    if 'env' in conf:
        envpath = basepath + conf['env']
        env = yaml.load(io.open(envpath, 'rt', encoding='utf-8'))
    else:
        env = {}
    env['changelog'] = changelog
    pagespath = basepath + conf['pages']
    if 'basepages' in conf:
        fallbackpath = basepath + conf['basepages']
    else:
        fallbackpath = None
    pagedatas = yaml.load(io.open(pagespath, 'rt', encoding='utf-8'))
    pages = [MainPage(pagedata, pagespath=pagespath[:-1], fallbackpath=fallbackpath) for pagedata in pagedatas]
    skelpath = basepath + Path(conf['skeleton'])
    if not io.exists(destpath):
        print("Copying skeleton")
        io.copytree(skelpath, destpath)
    pages[0].meta = conf.get('firstpage_meta', '')
    for i, page in enumerate(pages):
        print("Rendering {0}".format(page.name))
        page.render(destpath, pages, env)
Exemplo n.º 3
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()
Exemplo n.º 4
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))
Exemplo n.º 5
0
def gen(basepath, destpath, profile=None):
    basepath = Path(basepath)
    destpath = Path(destpath)
    configpath = basepath + 'conf.yaml'
    confall = yaml.load(io.open(configpath, 'rt', encoding='utf-8'))
    conf = confall['base']
    if profile and profile in confall:
        conf.update(confall[profile])
    tixurl = conf['tixurl']
    changelogdata = read_changelog_file(str(basepath + conf['changelog']))
    changelog = render_changelog(changelogdata, tixurl)
    if 'env' in conf:
        envpath = basepath + conf['env']
        env = yaml.load(io.open(envpath, 'rt', encoding='utf-8'))
    else:
        env = {}
    env['changelog'] = changelog
    pagespath = basepath + conf['pages']
    if 'basepages' in conf:
        fallbackpath = basepath + conf['basepages']
    else:
        fallbackpath = None
    pagedatas = yaml.load(io.open(pagespath, 'rt', encoding='utf-8'))
    pages = [
        MainPage(pagedata, pagespath=pagespath[:-1], fallbackpath=fallbackpath)
        for pagedata in pagedatas
    ]
    skelpath = basepath + Path(conf['skeleton'])
    if not io.exists(destpath):
        print("Copying skeleton")
        io.copytree(skelpath, destpath)
    pages[0].meta = conf.get('firstpage_meta', '')
    for i, page in enumerate(pages):
        print("Rendering {0}".format(page.name))
        page.render(destpath, pages, env)
Exemplo n.º 6
0
 def __init__(self, pagedata, pagespath, fallbackpath):
     self.name = pagedata['name']
     self.basename = Path(self.name)[-1]
     self.basepath = Path(self.name)[:-1]
     self.path = pagespath + self.basepath + '{}.md'.format(self.basename)
     if not io.exists(self.path):
         self.path = fallbackpath + self.basepath + '{}.md'.format(self.basename)
     self.title = pagedata['title']
     self.relpath = '../' * len(self.basepath)
     self.meta = ''
Exemplo n.º 7
0
 def __init__(self, pagedata, pagespath, fallbackpath):
     self.name = pagedata['name']
     self.basename = Path(self.name)[-1]
     self.basepath = Path(self.name)[:-1]
     self.path = pagespath + self.basepath + '{}.md'.format(self.basename)
     if not io.exists(self.path):
         self.path = fallbackpath + self.basepath + '{}.md'.format(
             self.basename)
     self.title = pagedata['title']
     self.relpath = '../' * len(self.basepath)
     self.meta = ''
Exemplo n.º 8
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()
Exemplo n.º 9
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
Exemplo n.º 10
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()
Exemplo n.º 11
0
 def export_db(self):
     self._ensure_paths()
     if self._ccdbpath is None or not io.exists(self._ccdbpath):
         self.mainwindow.show_message(MSG_NO_BASE_DB)
         return
     # Determine date ranges for which we compute amounts
     dr = MonthRange(date.today())
     dateranges = [dr]
     for _ in range(MONTHS_TO_FILL-1):
         dr = dr.prev()
         dateranges.append(dr)
     # Update CC db with actual data from moneyGuru.
     self.document.oven.continue_cooking(until_date=date.today())
     currency = self.document.default_currency
     db = self.get_db()
     accounts = [row.account for row in self.atable]
     categories = self.get_categories()
     for account in accounts:
         if account.name not in categories:
             cat = db.new_category()
             cat.name = account.name
         else:
             cat = categories[account.name]
         cat.is_recurring = self.atable.is_recurring(account.name)
         cat.is_income = account.type == AccountType.Income
         cat.save_data()
         for dr in dateranges:
             cash_flow = account.entries.normal_cash_flow(dr, currency=currency)
             if not cash_flow:
                 continue
             cell = cat.get_cell(dr.start)
             cell.amount = int(cash_flow.value*100)
             cell.save_data()
     db.fix_category_order()
     # Now set starting balances
     accounts = {a for a in self.document.accounts if a.is_balance_sheet_account()}
     accounts -= self.document.excluded_accounts
     for dr in dateranges:
         baldate = dr.start - ONE_DAY
         nw =  sum(a.entries.balance(date=baldate, currency=currency) for a in accounts)
         if nw:
             nw = int(nw.value*100)
         db.set_balance(dr.start, nw)
     self._categories = None
Exemplo n.º 12
0
def get_iphoto_or_aperture_pictures(plistpath, photo_class):
    # The structure of iPhoto and Aperture libraries for the base photo list are excactly the same.
    if not io.exists(plistpath):
        return []
    s = io.open(plistpath, "rt", encoding="utf-8").read()
    # There was a case where a guy had 0x10 chars in his plist, causing expat errors on loading
    s = remove_invalid_xml(s, replace_with="")
    # It seems that iPhoto sometimes doesn't properly escape & chars. The regexp below is to find
    # any & char that is not a &-based entity (&, ", etc.). based on TextMate's XML
    # bundle's regexp
    s, count = re.subn(r"&(?![a-zA-Z0-9_-]+|#[0-9]+|#x[0-9a-fA-F]+;)", "", s)
    if count:
        logging.warning("%d invalid XML entities replacement made", count)
    plist = plistlib.readPlistFromBytes(s.encode("utf-8"))
    result = []
    for key, photo_data in plist["Master Image List"].items():
        if photo_data["MediaType"] != "Image":
            continue
        photo_path = Path(photo_data["ImagePath"])
        photo = photo_class(photo_path, key)
        result.append(photo)
    return result
Exemplo n.º 13
0
def get_iphoto_or_aperture_pictures(plistpath, photo_class):
    # The structure of iPhoto and Aperture libraries for the base photo list are excactly the same.
    if not io.exists(plistpath):
        return []
    s = io.open(plistpath, 'rt', encoding='utf-8').read()
    # There was a case where a guy had 0x10 chars in his plist, causing expat errors on loading
    s = remove_invalid_xml(s, replace_with='')
    # It seems that iPhoto sometimes doesn't properly escape & chars. The regexp below is to find
    # any & char that is not a &-based entity (&, ", etc.). based on TextMate's XML
    # bundle's regexp
    s, count = re.subn(r'&(?![a-zA-Z0-9_-]+|#[0-9]+|#x[0-9a-fA-F]+;)', '', s)
    if count:
        logging.warning("%d invalid XML entities replacement made", count)
    plist = plistlib.readPlistFromBytes(s.encode('utf-8'))
    result = []
    for key, photo_data in plist['Master Image List'].items():
        if photo_data['MediaType'] != 'Image':
            continue
        photo_path = Path(photo_data['ImagePath'])
        photo = photo_class(photo_path, key)
        result.append(photo)
    return result
Exemplo n.º 14
0
 def is_available(self):
     return io.exists(self.physical_path)
Exemplo n.º 15
0
 def has_db(self):
     self._ensure_paths()
     return (self._mgccdbpath is not None) and io.exists(self._mgccdbpath)
Exemplo n.º 16
0
def test_cache_path_is_auto_created(fake_server, tmpdir):
    # the cache_path directory is automatically created.
    cache_path = str(tmpdir.join('foo/bar'))
    app = Application(ApplicationGUI(), cache_path=cache_path)
    assert io.exists(cache_path)
Exemplo n.º 17
0
 def is_available(self):
     return io.exists(self.physical_path)