示例#1
0
    def create_new_store_object(self, path, storage_dir_name):

        STORE_CONFIG_DIR = TsConstants.DEFAULT_STORE_CONFIG_DIR
        STORE_CONFIG_FILE_NAME = TsConstants.DEFAULT_STORE_CONFIG_FILENAME
        STORE_TAGS_FILE_NAME = TsConstants.DEFAULT_STORE_TAGS_FILENAME
        STORE_VOCABULARY_FILE_NAME = TsConstants.DEFAULT_STORE_VOCABULARY_FILENAME

        STORE_STORAGE_DIRS = [storage_dir_name]
        #        STORE_DESCRIBING_NAV_DIRS = ["describing"]
        STORE_DESCRIBING_NAV_DIRS = []
        #        STORE_CATEGORIZING_NAV_DIRS = ["categorizing"]
        STORE_CATEGORIZING_NAV_DIRS = []
        STORE_EXPIRED_DIRS = []
        STORE_NAVIGATION_DIRS = []

        filesystem = FileSystemWrapper()

        if not filesystem.is_directory(path):
            filesystem.create_dir(path)

        ## create a new store just in the test dir
        store = Store(5, path, STORE_CONFIG_DIR + "/" + STORE_CONFIG_FILE_NAME,
                      STORE_CONFIG_DIR + "/" + STORE_TAGS_FILE_NAME,
                      STORE_CONFIG_DIR + "/" + STORE_VOCABULARY_FILE_NAME,
                      STORE_NAVIGATION_DIRS, STORE_STORAGE_DIRS,
                      STORE_DESCRIBING_NAV_DIRS, STORE_CATEGORIZING_NAV_DIRS,
                      STORE_EXPIRED_DIRS, "")
        store.init()
        return store
示例#2
0
    def remove_dir(self, store_path, store_id):

        filesystem = FileSystemWrapper()

        filesystem.delete_dir(store_path)

        config = ConfigWrapper("../tsresources/conf/tagstore.cfg")
        config.remove_store(store_id)

        assert (not filesystem.is_directory(store_path))
示例#3
0
    def move_store(self, store_path, store_id, new_store_path):
        store = self.create_new_store_object(store_path, "storage")

        store.move(new_store_path)
        ## rewrite the config with the new store dir
        config = ConfigWrapper("../tsresources/conf/tagstore.cfg")
        config.rename_store(store_id, new_store_path)

        filesystem = FileSystemWrapper()

        assert (filesystem.is_directory(new_store_path))
示例#4
0
    def test_remove_store(self):
        """
        create a store
        create an item with tags in the store
        place a "not allowed" item in the navigation hierarchy
        call the "remove" method of the store
        check if everything has been removed properly
        """

        STORE_PATH = "./test_store/"
        STORAGE_DIR = "storage"
        NEW_ITEM_NAME = "test_item"

        store = self.create_new_store_object(STORE_PATH, STORAGE_DIR)

        filesystem = FileSystemWrapper()

        ## place a new item in the store
        file_path = "%s%s/%s" % (STORE_PATH, STORAGE_DIR, NEW_ITEM_NAME)
        filesystem.create_file(file_path)
        config = ConfigWrapper("../tsresources/conf/tagstore.cfg")
        ## write the new store also to the config
        store_id = config.add_new_store(STORE_PATH)
        ## now tag it manually
        store.add_item_with_tags(NEW_ITEM_NAME, ["should", "not"],
                                 ["get", "this"])

        ## create a new file in a tag-dir to test if it is removed as well
        file_path = "%s%s/%s" % (STORE_PATH, "descriptions/should",
                                 "i_should_not_be_here.file")
        filesystem.create_file(file_path)

        ## now remove the store
        store.remove()
        ##check if this is done properly
        ##this one should not exist ...
        assert (not filesystem.path_exists(file_path))
        ## this path should still exist
        assert (filesystem.path_exists(STORE_PATH))

        self.remove_dir(STORE_PATH, store_id)
        assert (not filesystem.path_exists(STORE_PATH))

        config.remove_store(store_id)
示例#5
0
    def test_create_store_move_and_delete_dir(self):
        """
        1. create a new store
        2. store a new item in the store - manually
        3. move the store to a new location
        4. delete the whole directory
        """

        filesystem = FileSystemWrapper()

        NEW_ITEM_NAME = "test_item"

        STORE_PATH = "./test_store/"
        STORAGE_DIR = "storage"

        store = self.create_new_store_object(STORE_PATH, STORAGE_DIR)

        ## place a new item in the store
        file_path = "%s%s/%s" % (STORE_PATH, STORAGE_DIR, NEW_ITEM_NAME)
        filesystem.create_file(file_path)
        config = ConfigWrapper("../tsresources/conf/tagstore.cfg")
        ## write the new store also to the config
        store_id = config.add_new_store(STORE_PATH)

        ## now tag it manually
        store.add_item_with_tags(NEW_ITEM_NAME, ["should", "not"],
                                 ["get", "this"])

        ## now the tag "should" must be a folde in the describing dir
        #        path_to_check = "%sdescribing/should" % STORE_PATH
        path_to_check = "%sdescriptions/should" % STORE_PATH
        print path_to_check
        assert (filesystem.is_directory(path_to_check))

        self.move_store("./test_store/", store_id, "./new_test_store/")
        self.remove_dir("./new_test_store/", store_id)
示例#6
0
class TsConstants(object):
    """
    class for providing internal used constants
    just do provide a single-point of access
    """
    
    CONFIG_DIR = "./tsresources/conf/"
    CONFIG_PATH = "./tsresources/conf/tagstore.cfg"
    
    LOGGER_NAME = "TagStoreLogger"
    LOG_FILENAME = "tagstore.log"
    LOG_BACKUP_COUNT = 3
    LOG_FILESIZE = 524288

    STORE_LOGGER_NAME = "StoreLogger"
    STORE_LOG_FILENAME = "store.log"
    
    ##overwrite settings path for windows, if the config exists in the AppData directory
    file_system = FileSystemWrapper()
    if file_system.get_os() == EOS.Windows:
        dir = file_system.get_user_profile_path()
        if file_system.path_exists(dir):
            CONFIG_DIR = dir + "/AppData/Local/tagstore"
            CONFIG_PATH = CONFIG_DIR + "/tagstore.cfg"
            LOG_FILENAME = dir + "/AppData/Local/tagstore/" + "tagstore.log"
    
    STORE_CONFIG_TEMPLATE_PATH = "./tsresources/conf/store.cfg.template"
    STORE_TAGFILE_TEMPLATE_PATH = "./tsresources/conf/store.tgs.template"

    #STORE_STORAGE_DIR_EN = "storage"#,Ablage"
    #STORE_DESCRIBING_NAVIGATION_DIR_EN = "navigation"#,Navigation"
    #STORE_CATEGORIZING_NAVIGATION_DIR_EN = "categorization"#,Kategorisierung"
    #STORE_EXPIRED_DIR_EN = "expired_items"#abgelaufene_Daten"
    
    SETTING_SUPPORTED_LANGUAGES = "supported_languages"
    SETTING_TAG_SEPARATOR = "tag_separator"
    SETTING_FACET_SEPARATOR = "facet_separator"
    
    SETTING_DATESTAMP_FORMAT = "datestamp_format"
    SETTING_DATESTAMP_HIDDEN = "datestamp_hidden"
    #SETTING_AUTO_DATESTAMP = "automatic_datestamp"
    
    #SETTING_CATEGORY_MANDATORY = "category_mandatory"
    SETTING_SHOW_CATEGORY_LINE = "show_category_line"
    SETTING_CATEGORY_MANDATORY = "category_mandatory"
    
    SETTING_VOCABULARY_CONFIGURABLE = "vocabulary_configurable"
    
    ## these constants are NOT used at the config file - it is a "gui setting name"
    SETTING_CATEGORY_VOCABULARY = "category_vocabulary"
    SETTING_ITEMS = "store_items"
    
    SETTING_DESC_TAGS = "describing_tags"
    SETTING_CAT_TAGS = "categorizing_tags"
    SETTING_FIRST_START = "first_start"
    SETTING_SHOW_WIZARD = "show_wizard"
    SETTING_CURRENT_LANGUAGE = "current_language"
    SETTING_SYNC_TAG = "sync_tag"
    SETTING_ANDROID_STORE ="android_store"
    SETTING_ANDROID_STORE_PATH="android_store_path"
    
    SETTING_ADDITIONAL_IGNORED_EXTENSIONS = "additional_ignored_extensions"
    
    SETTING_EXPIRY_PREFIX = "expiry_prefix"
    
    SETTING_SHOW_TAG_HELP = "show_tag_help"
    SETTING_SHOW_MY_TAGS_HELP = "show_my_tags_help"
    SETTING_SHOW_DATESTAMPS_HELP = "show_datestamps_help"
    SETTING_SHOW_EXPIRY_DATE_HELP = "show_expiry_date_help"
    SETTING_SHOW_RETAGING_HELP = "show_retagging_help"
    SETTING_SHOW_RENAME_TAGS_HELP = "show_rename_tags_help"
    SETTING_SHOW_STORE_MANAGEMENT_HELP = "show_store_management_help"
    SETTING_SHOW_SYNC_SETTINGS_HELP = "show_sync_settings_help"
    
    DATESTAMP_FORMAT_DAY = "%Y-%m-%d"
    DATESTAMP_FORMAT_MONTH = "%Y-%m"
    
    DEFAULT_EXPIRY_PREFIX = "exp_"
    DEFAULT_STORE_CONFIG_DIR = ".tagstore"
    DEFAULT_STORE_CONFIG_FILENAME = "store.cfg"
    DEFAULT_STORE_TAGS_FILENAME = "store.tgs"
    DEFAULT_STORE_SYNC_TAGS_FILENAME = "sync.tgs"
    DEFAULT_STORE_VOCABULARY_FILENAME = "vocabulary.txt"
    
    ## this file is created during a synchronization process
    DEFAULT_SYNCHRONIZATION_LOCKFILE_NAME = "tagstore.synchronization.lock"
    
    DEFAULT_RECENT_TAGS = 5
    DEFAULT_POPULAR_TAGS = 5
    DEFAULT_MAX_TAGS = 3
    DEFAULT_TAG_SEPARATOR = ","
    DEFAULT_FACET_SEPARATOR = "="
    DEFAULT_SUPPORTED_LANGUAGES = ["en", "de"]
    DEFAULT_ENCODING = "UTF-8"
    DEFAULT_FIRST_START = "true"
    DEFAULT_SHOW_WIZARD = "true"
    DEFAULT_VOCABULARY_CONFIGURABLE = "false"
    DEFAULT_SHOW_CATEGORY_LINE = 1
    DEFAULT_DATESTAMP_FORMAT = 1
    DEFAULT_DATESTAMP_HIDDEN = "false"
    DEFAULT_ADDITIONAL_IGNORED_EXTENSIONS = ""
    DEFAULT_SYNC_TAG = "android"
    
    DEFAULT_SHOW_TAG_HELP = "true"
    DEFAULT_SHOW_MY_TAGS_HELP = "true"
    DEFAULT_SHOW_DATESTAMPS_HELP ="true"
    DEFAULT_SHOW_EXPIRY_DATE_HELP ="true"
    DEFAULT_SHOW_RETAGING_HELP ="true"
    DEFAULT_SHOW_RENAME_TAGS_HELP ="true"
    DEFAULT_SHOW_STORE_MANAGEMENT_HELP ="true"
    DEFAULT_SHOW_SYNC_SETTINGS_HELP ="true"
    
    DEFAULT_MAX_CLOUD_TAGS = 20
    
    def __init__(self):
        pass