Beispiel #1
0
def imp_user(conn, imp_path, imp_dir=None,
             folder=None):
    '''import htm urls into current user's places file.'''
    links = []
    valid = None

    imp_dir = set_default(imp_dir, _path.downloads_or_home(), None)

    if imp_path is None:
        print "please supply a file path."
    else:
        #validate the path and handle mistakes with
        #being too forward or not forward enough
        imp_path_ = _path.abs_pth(imp_path)
        #valid = valid_path(imp_path, imp_dir)
        valid = valid_path(imp_path_, imp_dir)
        dmsg("full path:" + str(valid))
        dmsg("is_file:" + str(_path.is_file(valid)))
        if valid is not None:
            dmsg("imp_path: " + valid)
            _htm_io.find_links(valid, links)
            imp_urls(conn, links,
                     check_exists=True,
                     folder=folder)
        else:
            print "file doesn't exist."

    dmsg("<imp_user>")
Beispiel #2
0
def last_xpo_path(base, xpo_dir=None, numbered=True,
                  timestamp=True, date_format="%d_%m_%Y"):
    '''return path of most current backup.'''
    dmsg("<last_xpo_path>")
    ext = ".htm"

    xpo_dir = _path.downloads_or_home(xpo_dir)

    #check the directory for a file that already exist with same
    #name
    files = _path.search_dir(xpo_dir, base+"*"+ext)
    listz = []
    dictz = {}
    listz = names_to_nat(base=base+".",
                         names=files, index=dictz,
                         date_format=date_format)

    #find the start and stop index of all the dated files
    if timestamp:
        index_start, index_stop = date_indices(listz, not_None=True)
    elif not timestamp:
        index_start, index_stop = date_indices(listz, not_None=False)

    #print "listz:"+str(listz)
    #print "index_start:"+str(index_start)
    #print "index_stop:"+str(index_stop)
    if index_start is not None and index_stop is None:
        fyl = dictz[listz[index_start]]
    elif index_stop is not None:
        fyl = dictz[listz[index_stop]]
    else:
        fyl = None
    dmsg("</last_xpo_path>")
    return fyl
Beispiel #3
0
def reload_user(conn, base, imp_dir=None,
                indx=0, numbered=True, timestamp=True,
                date_format="%d_%m_%Y", folder=None):
    '''
    import last backup.
    0 being current and 1 being previous.
    '''
    full_path = None
    dmsg("<reload_user>")
    imp_dir = _path.downloads_or_home(imp_dir)
    #if imp_dir is None:
    #    imp_dir = _path.get_downloads_dir()
        #print "imp dir: "+str(imp_dir)
    #imp_user(results.i_val, results.v_val)
    #print "reloading..."
    #print timestamp
    fyl = last_xpo_path(base, xpo_dir=imp_dir, numbered=numbered,
                        timestamp=timestamp, date_format=date_format)
    dmsg("last fyl:" + str(fyl))
    if fyl is not None and imp_dir is not None:
        full_path = imp_dir + "/" + fyl
        #print full_path
        #reset_tables(conn)
        imp_user(conn, full_path, folder=folder)
    dmsg("</reload_user>")
    return fyl
Beispiel #4
0
def next_xpo_path(base, xpo_dir=None, numbered=True,
                  timestamp=True, date_format="%d_%m_%Y"):
    '''return path of future backup.'''
    dmsg("<next_xpo_path>")
    ext = ".htm"
    now = time.strftime(date_format)

    xpo_dir = _path.downloads_or_home(xpo_dir)
    vmsg(xpo_dir)

    fyl = file_stamp(base, timestamp, date_format)

    if numbered:

        files = _path.search_dir(xpo_dir, base+"*.htm")
        first_export = False

        if len(files) > 0:
            last_fyl = last_xpo_path(base=base, xpo_dir=xpo_dir,
                                     numbered=numbered, timestamp=timestamp,
                                     date_format=date_format)
            index = path_index(last_fyl)
            via_date = path_date(last_fyl)
            if via_date is None and index is None:
                index = 0
                via_date = now
                first_export = True
            if via_date is None and index is not None:
                first_export = False
            elif via_date != now:
                index = 0
                via_date = now
                first_export = True
            else:
                first_export = False

        elif len(files) == 0:
            index = 0
            via_date = now
            first_export = True

        #print "path_date: " + via_date
        #print "now:" + now
        #print "index:" + str(index)

        if timestamp:
            if via_date == now and not first_export:
                fyl += idx(index+1)
            else:
                fyl += idx(0)
        else:
            if not first_export:
                fyl += idx(index+1)
            else:
                fyl += idx(0)
    dmsg("</next_xpo_path>")
    return fyl + ext
Beispiel #5
0
def xpo_user(conn, file_name=None, xpo_dir=None,
             head_title="", verbose=True, numbered=True,
             timestamp=False, date_f="%d_%m_%Y",
             user_path=None):
    '''unless otherwise specified backup current user.'''
    vmsg("exporting...", verbose)

    xpo_dir = _path.downloads_or_home()

    vmsg("xpo dir:" + xpo_dir, verbose)
    xpo_places(conn, xpo_path=xpo_dir, file_name=file_name,
               head_title=head_title, numbered=numbered,
               timestamp=timestamp, date_f=date_f)
Beispiel #6
0
def xpo_htm(file_name=None, xpo_dir=None,
            head_title="", numbered=True,
            timestamp=False, date_f="%d_%m_%Y",
            user_path=None):
    '''create an empty backup.'''
    verbose = False

    xpo_dir = _path.downloads_or_home()
    vmsg("xpo dir:" + xpo_dir, verbose)
    xpo_urls(xpo_dir, file_name,
             links=None,
             head_title=head_title,
             numbered=numbered,
             timestamp=timestamp,
             date_f=date_f)
Beispiel #7
0
def db_con_home():
    '''connect to last profile in user's home directory.'''
    conn = None
    bk_dir = _path.downloads_or_home()
    #raw_input(str(bk_dir))

    dmsg("bk dir:" + bk_dir)
    home_path = _path.get_home()
    paths = _path.get_moz(home_path)
    for path in paths:
        places_path = path + "/"+'places.sqlite'
        is_file = str(_path.is_file(places_path))
        dmsg(path)
        dmsg(places_path)
        dmsg("places is_file:" + is_file)

        if is_file:
            conn = db_con(places_path)


    if conn is not None:
        return conn
    else:
        raise ValueError('could not connect to data store')