Exemplo n.º 1
0
def _copy_by_force_way(path, options):
    """Copy By Force Way

    Function allow to delete file/dir... to bin by rename way if name
    collision exists.

    Arguments:
        path: path to source.
        options: list of optional parameters.

    """
    if os.path.exists(
        os.path.join(
            user_config_manager.get_property('bin_path'),
            os.path.basename(path)
        )
    ):
        bin_config_manager.history_del(os.path.basename(path))
        clean_path.delete(
            os.path.join(
                user_config_manager.get_property('bin_path'),
                os.path.basename(path)
            )
        )
    bin_config_manager.history_add(path)
    clean_path.copy(
        path,
        os.path.join(
            user_config_manager.get_property('bin_path'),
            os.path.basename(path)
        ),
        options
    )
Exemplo n.º 2
0
    def test_empty_bin(self):
        file_1 = os.path.join(self.test_folder_path, 'file_1')
        os.mknod(file_1)
        bin_config_manager.history_add(file_1)
        clean_path.move(file_1, user_config_manager.get_property('bin_path'))
        self.assertTrue(
            os.path.exists(
                os.path.join(user_config_manager.get_property('bin_path'),
                             'file_1')))

        self.assertFalse(os.path.exists(file_1), msg="File should be in bin.")
        self.assertEqual(bin_config_manager.history_get('file_1')['src_dir'],
                         os.path.dirname(file_1),
                         msg="Initial preparations fails.")
        self.assertEqual(bin_command.empty_bin(),
                         0,
                         msg='Bin command should return success code: 0.')
        self.assertTrue(os.path.isdir(
            user_config_manager.get_property('bin_path')),
                        msg="Binempty should not delete existing bin folder.")
        self.assertFalse(
            os.path.exists(
                os.path.join(user_config_manager.get_property('bin_path'),
                             'file_1')))
        self.assertEqual(len(bin_config_manager.get_property('history')), 0)
Exemplo n.º 3
0
 def test_history_delete(self):
     file_1 = os.path.join(self.test_bin_path, 'file_1')
     bin_config_manager.history_add(file_1)
     bin_config_manager.history_del(os.path.basename(file_1))
     self.assertEqual(len(bin_config_manager.get_property('history')),
                      0,
                      msg="History len should be 0 after removing element.")
Exemplo n.º 4
0
 def test_history_get_with_date(self):
     file_1 = os.path.join(self.test_bin_path, 'file_1')
     file_1_name = os.path.basename(file_1)
     cur_datetime = datetime.strptime(
         datetime.strftime(datetime.now(), HISTORY_DATETIME_FORMAT),
         HISTORY_DATETIME_FORMAT)
     bin_config_manager.history_add(file_1)
     self.assertEqual(
         bin_config_manager.history_get(file_1_name)['date'], cur_datetime)
Exemplo n.º 5
0
 def test_history_get(self):
     file_1 = os.path.join(self.test_bin_path, 'file_1')
     file_1_name = os.path.basename(file_1)
     bin_config_manager.history_add(file_1)
     self.assertEqual(
         bin_config_manager.history_get(file_1_name)['src_dir'],
         os.path.dirname(file_1))
     self.assertEqual(
         bin_config_manager.history_get(file_1_name)['bin_name'],
         os.path.basename(file_1))
Exemplo n.º 6
0
 def test_move_bin(self):
     file_1 = os.path.join(self.test_folder_path, 'file_1')
     bin_move_path = os.path.join(self.test_folder_path, 'bin_move_path')
     os.mknod(file_1)
     bin_config_manager.history_add(file_1)
     clean_path.move(file_1, user_config_manager.get_property('bin_path'))
     self.assertEqual(bin_command.move_bin(bin_move_path), 0)
     self.assertFalse(
         os.path.exists(os.path.join(self.test_bin_path, 'file_1')))
     self.assertTrue(os.path.exists(os.path.join(bin_move_path, 'file_1')))
     self.assertEqual(user_config_manager.get_property('bin_path'),
                      bin_move_path)
     self.assertEqual(len(bin_config_manager.get_property('history')), 1)
Exemplo n.º 7
0
 def test_history_add(self):
     file_1 = os.path.join(self.test_bin_path, 'file_1')
     bin_config_manager.history_add(file_1)
     self.assertEqual(len(bin_config_manager.get_property('history')),
                      1,
                      msg="History len should be 1 after adding element.")
     self.assertEqual(
         bin_config_manager.get_property('history')[0]['bin_name'],
         os.path.basename(file_1),
         msg="Wrong history item name.")
     self.assertEqual(
         bin_config_manager.get_property('history')[0]['src_dir'],
         os.path.dirname(file_1),
         msg="Wrong history item src_dir.")
Exemplo n.º 8
0
 def test_create_bin(self):
     file_1 = os.path.join(self.test_folder_path, 'file_1')
     os.mknod(file_1)
     clean_path.move(file_1, user_config_manager.get_property('bin_path'))
     bin_config_manager.history_add(file_1)
     new_bin_location = os.path.join(self.test_folder_path,
                                     'new_bin_location')
     self.assertEqual(bin_command.create_bin(new_bin_location),
                      0,
                      msg='Bin command should return success code: 0.')
     self.assertEqual(len(bin_config_manager.get_property('history')),
                      0,
                      msg="New bin should be empty.")
     self.assertEqual(user_config_manager.get_property('bin_path'),
                      new_bin_location,
                      msg="New path should be writen to user config file")
Exemplo n.º 9
0
 def test_copy_bin(self):
     file_1 = os.path.join(self.test_folder_path, 'file_1')
     bin_copy_path = os.path.join(self.test_folder_path, 'bin_copy_path')
     os.mknod(file_1)
     bin_config_manager.history_add(file_1)
     clean_path.move(file_1, user_config_manager.get_property('bin_path'))
     self.assertEqual(bin_command.copy_bin(bin_copy_path),
                      0,
                      msg="Should return success code: 0.")
     self.assertEqual(
         len(bin_config_manager.get_property('history')),
         1,
     )
     self.assertTrue(os.path.exists(os.path.join(bin_copy_path, 'file_1')),
                     msg="Should copy innear files too")
     self.assertEqual(user_config_manager.get_property('bin_path'),
                      self.test_bin_path)
Exemplo n.º 10
0
    def test_history_empty(self):
        files = [
            os.path.join(self.test_bin_path, str(idx)) for idx in range(5)
        ]
        for file in files:
            bin_config_manager.history_add(file)

        self.assertEqual(
            len(bin_config_manager.get_property('history')),
            5,
            msg=
            "History should be equal to 5 after adding 5 different elements to it."
        )
        history = bin_config_manager.get_property('history')
        [
            self.assertEqual(
                os.path.join(history[i]['src_dir'], history[i]['bin_name']),
                files[i]) for i in range(5)
        ]
        bin_config_manager.history_empty()
        self.assertEqual(len(bin_config_manager.get_property('history')),
                         0,
                         msg="History should be len 0 after history_empty.")
Exemplo n.º 11
0
def _copy_by_rename_way(path, options):
    """Copy By Renam Way
    
    Function allow to delete file/dir... to bin by rename way if name
    collision exists.
    
    Arguments:
        path: path to source.
        options: list of optional parameters.
    
    """
    src_name = os.path.basename(path)
    src_dir = os.path.dirname(path)
    bin_name = os.path.basename(path)
    if bin_config_manager.history_get(bin_name, options):

        count = 0
        while True:

            tmp_bin_name = HISTORY_COPY_NAME_FORMAT.format(bin_name, count)
            if not bin_config_manager.history_get(tmp_bin_name, options):
                break
            count += 1
        bin_name = tmp_bin_name

    clean_path.copy(
        path, os.path.join(user_config_manager.get_property('bin_path'), bin_name),
        options
    )
    bin_config_manager.history_add(
        {
            'src_name': src_name,
            'src_dir': src_dir,
            'bin_name': bin_name
        },
        options
    )