예제 #1
0
 def upload(self):
     #read#
     file = open(self.tfile_path, 'r')
     lines = file.readlines()
     file.close()
     #load#
     self.tpath = lines[0].replace('tpath: ', '')[0:-1]
     self.machine[0] = lines[1].replace('machine0: ', '')[0:-1]
     self.machine[1] = lines[2].replace('machine1: ', '')[0:-1]
     self.path[0] = lines[3].replace('path0: ', '')[0:-1]
     self.path[1] = lines[4].replace('path1: ', '')[0:-1]
     exclusions = lines[5].replace('exclusions: ', '')[0:-1]
     if exclusions != '':
         exclusions = exclusions.split('|')
     else:
         exclusions = []
     self.exclusions[0] = []
     self.exclusions[1] = []
     for exclusion in exclusions:
         self.exclusions[0].append(self.path[0] + exclusion)
         self.exclusions[1].append(self.path[1] + exclusion)
     self.mpath[0] = mapping.MappedPath(
         mpath_str=lines[6].replace('mpath0: ', '')[0:-1])
     self.mpath[1] = mapping.MappedPath(
         mpath_str=lines[7].replace('mpath1: ', '')[0:-1])
     self.changes[0] = changes.upload_changes(lines[8].replace(
         'changes0: ', '')[0:-1])
     self.changes[1] = changes.upload_changes(lines[9].replace(
         'changes1: ', '')[0:-1])
예제 #2
0
 def __init__(self, name, path, new=False):
     if path != '' and name != '':
         path = path
     self.tfile_path = path + '\\' + name
     self.tpath = 0
     self.machine = [0, 0]
     self.path = [0, 0]
     self.exclusions = [0, 0]
     self.mpath = [0, 0]
     self.changes = [0, 0]
     if new:
         self.tpath = path
         self.machine[0] = ''
         self.machine[1] = ''
         self.path[0] = ''
         self.path[1] = ''
         self.exclusions[0] = []
         self.exclusions[1] = []
         self.mpath[0] = mapping.MappedPath(mpath_str='a*a*0*0*False<>')
         self.mpath[1] = mapping.MappedPath(mpath_str='a*a*0*0*False<>')
         self.changes[0] = changes.empty_changes
         self.changes[1] = changes.empty_changes
예제 #3
0
 def make_ctime_unique(mpath, mpath_check):
     while True:
         if mpath.search_dup(mpath_check) != None:  # while duplicate exists
             #### get duplicate ####
             mpath_dup_pos = mpath.search_dup(mpath_check)
             mpath_dup = mpath.get_mpath_at(mpath_dup_pos)
             #### mod duplicate ####
             resources.mod_ctime(
                 mpath_dup.path)  # iterate duplicate ctime by a nanosecond
             mpath.update_mpath_at(mapping.MappedPath(mpath_dup.path),
                                   mpath_dup_pos)  # update mpath duplicate
             make_ctime_unique(mpath,
                               mpath_dup)  # check duplicate for duplicates
         else:
             break
예제 #4
0
    print('transfile testing\n')

    #switches#
    transfile_switch = True
    cleanup_switch = False

    #tests#
    if transfile_switch:
        disp_test_title('make new')
        tfile = TransFile('transfer.tf', '', new=True)
        tfile.tpath = 'D:\\Transfer'
        tfile.path[0] = 'testdir\\original'
        tfile.path[1] = 'testdir\\remix'
        tfile.exclusions[0].append('testdir\\original\\symb')
        tfile.exclusions[1].append('testdir\\remix\\symb')
        tfile.mpath[0] = mapping.MappedPath(tfile.path[0],
                                            exclusions=tfile.exclusions[0])
        tfile.mpath[1] = mapping.MappedPath(tfile.path[1],
                                            exclusions=tfile.exclusions[1])
        print('tpath: {}'.format(tfile.tpath))
        print('path0: {}'.format(tfile.path[0]))
        print('path1: {}'.format(tfile.path[1]))
        print('exclusions: {}'.format(tfile.exclusions))
        print('mpath0: {}'.format(tfile.mpath[0].get_mpath_str()))
        print('mpath1: {}'.format(tfile.mpath[1].get_mpath_str()))
        print('changes0: {}'.format(tfile.changes[0]))
        print('changes1: {}'.format(tfile.changes[1]))
        disp_test_output(tfile)

        disp_test_title('download')
        tfile.download()
        disp_test_output('check for \"transfer.tf\"')
예제 #5
0
    def transfer(name, path):
        tfile = load.TransFile(name, path)
        tfile.upload()
        local_m = -1
        exterior_m = -1
        #get host computer#
        if os.environ['COMPUTERNAME'] == tfile.machine[0]:
            local_m = 0
            exterior_m = 1
        elif os.environ['COMPUTERNAME'] == tfile.machine[1]:
            local_m = 1
            exterior_m = 0

        #CHECK# - get any changes on the local machine
        #var#
        old_mpath = tfile.mpath[local_m]
        new_mpath = mapping.MappedPath(
            tfile.path[local_m], exclusions=tfile.path[local_m]
        )  # get new new_mpath to compare to the old one
        old_changes = tfile.changes(local_m)
        new_changes = changes.empty_changes
        merged_changes = changes.empty_changes

        #check#
        binding.make_ctimes_unique(
            new_mpath)  # make sure any new files have unique ctimes
        new_changes = changes.get_changes(
            tfile.mpath[local_m], new_mpath)  # compare old_mpath to new_mpath
        tfile.mpath[local_m] = new_mpath

        if not changes.is_empty(old_changes):  # if there are old changes
            merged_changes = changes.hard_merge_changes(
                tfile.changes[local_m],
                new_changes)  # merge old_changes with new_changes
            tfile.changes[local_m] = merged_changes  # add merged changes
            changes.make_trans_changes(
                tfile.changes[local_m], tfile.tpath, tfile.mpath[local_m]
            )  # make transitional changes so changes can be made
        elif not changes.is_empty(
                new_changes
        ):  # if there are no old changes but there are new ones
            tfile.changes[local_m] = new_changes  # add changes
            changes.make_trans_changes(
                tfile.changes[local_m], tfile.tpath, tfile.mpath[local_m]
            )  # make transitional changes so changes can be made

        #display#
        print('CHECK')
        print('old new_mpath: ' + new_mpath.get_mpath_str())
        print('new new_mpath: ' + old_mpath.get_mpath_str())
        print('')
        print('old changes(local):')
        for change in old_changes:
            change.display()
        print('')
        print('new changes(local):')
        for change in new_changes:
            change.display()
        print('')
        if not changes.is_empty(old_changes):  # if there are old changes
            print('merged changes(local):')
            for change in new_changes:
                change.display()
            print('')

        #APPLY# - merge any changes on the local machine with changes on the exterior machine and apply merged exterior changes(staged changes)
        #var#
        local_changes = tfile.changes(local_m)
        exterior_changes = tfile.changes(exterior_m)
        merged_local_changes = changes.empty_changes
        staged_changes = changes.empty_changes

        #apply#
        if (not changes.is_empty(local_changes)) and (
                not changes.is_empty(exterior_changes)
        ):  # if there are changes on the local and exterior machine
            merged_local_changes, staged_changes = changes.soft_merge_changes(
                local_changes,
                exterior_changes)  # merge local and exterior changes
            tfile.changes[local_m] = merged_local_changes
            changes.make_changes(staged_changes, tfile.tpath,
                                 tfile.mpath[local_m])  # apply staged changes
            tfile.changes[
                exterior_m] = changes.empty_changes  # clear exterior changes (applied)

        #display#
        print('APPLY')
        print('local changes:')
        for change in local_changes:
            change.display()
        print('')
        print('exterior changes:')
        for change in exterior_changes:
            change.display()
        print('')
        if (not changes.is_empty(local_changes)) and (
                not changes.is_empty(exterior_changes)
        ):  # if there are changes on the local and exterior machine
            print('merged local changes:')
            for change in merged_local_changes:
                change.display()
            print('')
            print('staged changes:')
            for change in staged_changes:
                change.display()
            print('')
            print('staged changes applied')
        else:
            print('no staged changes')

        #DOWNLOAD#
        tfile.download()
예제 #6
0
    test_dir0 = 'C:\\Users\\JackPaul\\PycharmProjects\\Transpher\\testdir\\original'
    test_dir1 = 'C:\\Users\\JackPaul\\PycharmProjects\\Transpher\\testdir\\remix'

    #title#
    print('changes testing\n')

    #switches#
    get_changes_switch = False
    merge_changes_switch = False
    make_changes_switch = False
    output_switch = True

    #tests#
    if get_changes_switch:
        #init#
        mpath0 = mapping.MappedPath(test_dir0)
        binding.make_ctimes_unique(mpath0)
        resources.delete_file(test_dir1)
        resources.copy_file(test_dir0, test_dir1)
        binding.bind_paths(test_dir0, test_dir1)
        resources.make_file('C:\\Users\\JackPaul\\PycharmProjects\\Transpher\\testdir\\remix\\symb\\$.txt') # add
        resources.rename_file('/testdir/remix/numb/positive/a.txt',
                  'C:\\Users\\JackPaul\\PycharmProjects\\Transpher\\testdir\\remix\\numb\\positive\\a.txt') # move
        resources.write_file('C:\\Users\\JackPaul\\PycharmProjects\\Transpher\\testdir\\remix\\symb\\!.txt', 'no') # update
        resources.delete_file('C:\\Users\\JackPaul\\PycharmProjects\\Transpher\\testdir\\remix\\alpha\\d.txt') # del
        mpath1 = mapping.MappedPath(test_dir1)

        #tests#
        disp_test_title('get changes')
        changes = get_changes(mpath0, mpath1)
        print('output: ')