示例#1
0
def test_individual_channel_convenience():
    """Accessing individual channel via om.read works"""
    data = om.read(path=persist, channel='testing')
    assert_false(data == {})

    # Non-existing channel returns dictionary
    assert_is_instance(om.read(persist, 'NON_EXISTANT'), dict)
示例#2
0
def test_individual_file_convenience():
    """Accessing individual file via om.read works"""
    data = om.read(path=persist, channel='testing', key='file1')
    assert_false(data == {})

    data = om.read(persist, 'testing', 'NON_EXISTANT')
    assert_equals(data, None)
示例#3
0
 def set_items(self):
     self.software_commands.clear()
     project_name = self.comboBox_project_list.currentText()
     self.manager = SoftwareManager(project_name)
     for app_ in self.manager.applications:
         icon_name = app_.icon
         app_.project_name = project_name
         if icon_name:
             image_path = self.icon(icon_name, True)
         else:
             image_path = self.icon("default_software_icon.png", True)
         if not os.path.isfile(image_path):
             image_path = self.icon("default_software_icon.png", True)
         image = QtGui.QIcon(image_path)
         layer_widget = SoftwareManagerItemGUI(app_, self)
         layer_widget.set_icon(image)
         profiles = self.get_profiles(app_.name, project_name)
         if profiles:
             layer_widget.set_list(profiles.keys())
             temp_name = om.read(self.local_profile_folder,
                                 '%s_%s' % (project_name, app_.name))
             if temp_name:
                 layer_widget.set_current_item(temp_name)
         else:
             layer_widget.set_list([app_.name])
         layer_item = QtWidgets.QListWidgetItem(self.software_commands)
         layer_item.setSizeHint(QtCore.QSize(layer_widget.width() - 10,
                                             layer_widget.height()))
         layer_item.path = app_.path
         layer_item.name = app_.name
         layer_item.profiles = profiles
         layer_item.setToolTip(u'%s' % app_.description)
         self.software_commands.setItemWidget(layer_item, layer_widget)
     self.save_current_project()
示例#4
0
def storing_collection_as_blobs():
    """
    Open Metadata can store any arbitrary data as blobs. Blobs are stored
    together with its parent; i.e. in the simples of situation, blobs are
    copied from their source into the Open Metadata hierarchy.

     __________________       ____________________________
    |                  |     |                            |
    | /root/source.bin |---->| /location/.meta/source.bin |
    |__________________|     |____________________________|

    """

    raise NotImplementedError

    path = '/project/asset'
    location = om.Location(path)
    myvalue = om.Entry('myvalue', parent=location)
    myvalue.value = '/path/to/myvalue.json'
    myvalue.isblob = True
    om.flush(myvalue)

    # Retreiving stored blob
    myvalue = om.read(path, 'myvalue')
    myvalue.path
    # --> '/project/asset/.meta/myvalue.json'

    assert myvalue.value == myvalue.path
示例#5
0
    def test_nested_wrongsuffix(self):
        """Suffixes are ignored

        Although you specify a suffix, if the name exists a correct suffix
        will be derived during lookup.

        """

        value = om.read(self.project_path, 'deep/subdeep.list/value.string')
        self.assertEquals(value, 'Value')
示例#6
0
    def test_existing_unknown_type(self):
        """unknown.abc contains nothing and isn't a recognised type.

        As a result, nothing will get successfully read from disk, and
        no default will be assigned, resultuing in None.

        """

        value = om.read(self.project_path, 'unknown.abc')
        self.assertEquals(value, None)
示例#7
0
    def test_integration(self):
        """Test a combination of features"""
        entry = om.Entry('test.string', value="Hello", parent=self.root)
        child = om.Entry('child.int', value=1, parent=entry)
        self.assertEquals(entry.type, 'dict')
        om.flush(entry)
        self.assertTrue(os.path.exists(entry.path.as_str))
        om.pull(entry)
        self.assertEquals(entry.type, 'dict')
        entry.value = "Hello"
        self.assertEquals(entry.type, 'string')
        self.assertEquals(entry.value, "Hello")
        om.flush(entry)
        om.pull(entry)
        self.assertFalse(os.path.exists(child.path.as_str))

        child = om.Entry('child.int', value=1, parent=entry)
        om.flush(entry)
        self.assertEquals(om.read(self.root_path, 'test/child'), 1)
        om.write(self.root_path, '/test/child', 2)
        self.assertEquals(om.read(self.root_path, 'test/child'), 2)
        om.write(self.root_path, '/root/test/another', 10)
        self.assertEquals(om.read(self.root_path, 'root/test/another'), 10)
示例#8
0
    def test_corrupt(self):
        """corrupt.string conatins a value that isn't JSON formatted.

        Reading it will result in an exception being raised within lib.Resource
        which will in turn set its value to None.

        When querying the value of the entry, the .value property will
        encounter None and assume no value has been set or attempted to be
        set. As a result, it will assign a default value, which in the case of
        string is an empty string.

        """

        value = om.read(self.project_path, 'corrupt.string')
        self.assertEquals(value, '')
示例#9
0
def read(ctx, path, root):
    """Read metadata.

    \b
    Usage:
        $ openmetadata read my_variable
        Hello World
        $ openmetadata read another_var
        5

    """

    root = os.path.abspath(root) or os.getcwd()

    sys.stdout.write(openmetadata.read(path=root,
                                       metapath=path))
示例#10
0
    def search_software(self):
        result = []
        self.software_commands.clear()
        soft_name = self.search_text.text()
        regularly = '.*?'.join(soft_name.lower())
        regex = re.compile(regularly)
        project_name = self.comboBox_project_list.currentText()

        for app_ in self.manager.applications:
            match = regex.search(app_.name.lower())
            if match:
                result.append((len(match.group()), match.start(), app_))
        if result:
            sorted_result = [x for _, _, x in sorted(result)]
            for app_ in sorted_result:
                icon_name = app_.icon
                app_.project_name = project_name
                if icon_name:
                    image_path = self.icon(icon_name, True)
                else:
                    image_path = self.icon("default_software_icon.png", True)

                if not os.path.isfile(image_path):
                    image_path = self.icon("default_software_icon.png")
                image = QtGui.QIcon(image_path)
                layer_widget = SoftwareManagerItemGUI(app_, self)
                layer_widget.set_icon(image)
                profiles = self.get_profiles(app_.name, project_name)
                if profiles:
                    layer_widget.set_list(profiles.keys())
                    temp_value = om.read(self.local_profile_folder,
                                         '%s_%s' % (project_name, app_.name))
                    if temp_value:
                        layer_widget.set_current_item(temp_value)
                else:
                    layer_widget.set_list([app_.name])
                layer_item = QtWidgets.QListWidgetItem(self.software_commands)
                layer_item.setSizeHint(QtCore.QSize(layer_widget.width() - 10,
                                                    layer_widget.height()))
                layer_item.path = app_.path
                layer_item.name = app_.name
                layer_item.profiles = profiles
                layer_item.setToolTip(u'%s' % app_.description)
                self.software_commands.setItemWidget(layer_item, layer_widget)
示例#11
0
def storing_collection_as_open_metadata():
    """
    While blobs facilitate storage of any arbitrary data, Open Metadata also
    has the notion of Open Metadata-types.

    Open Metadata-types offer extended features for plain-data, such as text,
    numbers, dates and matrices in that they may be added, subtracted, version-
    controlled and eventually end up in user interfaces as views and editors
    relevant to their specific type.

     _______________________       ___________________________________________
    |                       |     |                                           |
    | ['entry1', 'entry2' ] |---->| /location/.meta/myvalue.list/0.string     |
    |_______________________| |   |___________________________________________|
                              |
                              |    ___________________________________________
                              |   |                                           |
                              \-->| /location/.meta/myvalue.list/1.string     |
                                  |___________________________________________|

    The advantage of each ultimately depends on your use-case, but in short:

    - If control > performance, use Open Metadata-types
    - If control < performance, use Blobs

    """
    raise NotImplementedError

    location = om.Location(path)
    myvalue = om.Entry('myvalue', parent=location)
    myvalue.value = ['entry1', 'entry2']
    om.flush(myvalue)

    # Retreiving stored blob
    myvalue = om.read(path, 'myvalue')
    myvalue == ['entry1', 'entry2']

    assert myvalue.value != myvalue.path
示例#12
0
 def test_nested(self):
     value = om.read(self.project_path, 'deep/subdeep/value')
     self.assertEquals(value, 'Value')
示例#13
0
"""Wrap Open Metadata"""

import logging
import openmetadata

log = logging.getLogger('openmetadata')
log.setLevel(logging.CRITICAL)


write = lambda path, key, value: openmetadata.write(path, key, value)
read = lambda path, key: openmetadata.read(path, key)
示例#14
0
 def test_nested_absolute(self):
     """Specifying suffixes make no difference"""
     value = om.read(self.project_path, 'deep.dict/subdeep/value.string')
     self.assertEquals(value, 'Value')
示例#15
0
l2 = om.Entry('item2.bool', value=True, parent=olist)
l3 = om.Entry('item3.int', value=5, parent=olist)

# ..and a dictionary..
odict = om.Entry('mydict.dict', parent=olist)

# ..with two keys
key1 = om.Entry('key1.string', value='value', parent=odict)

# One of which, we neglect to specify a value-type.
# The value-type will be determined via the Python value-type <str>
key2 = om.Entry('key2', value='value', parent=odict)

# Finally, write it to disk.
om.flush(location)

# ----------- Read it back in


assert om.read(path) == ['mylist', 'simple_data']

assert om.read(path, 'mylist') == ['item2', 'item3', 'item1', 'mydict']

assert om.read(path, 'mylist/item2') is True


# ------------ Remove additions


om.clear(path)
示例#16
0
 def set_current_project(self):
     project_name = om.read(self.local_profile_folder, 'project')
     if project_name:
         self.comboBox_project_list.setCurrentIndex(
             self.comboBox_project_list.findText(project_name.lower()))
示例#17
0
    def __init__(self, ui_file):
        super(SoftwareManagerGUI, self).__init__()
        # parent custom widget
        RenderAwesomeUI(ui_file=ui_file, parent_widget=self, css_file=CSS_FILE)
        # init attribute
        self.offset = None
        self.app_launchers = htk.get_launchers()
        self.resources = HZResources()
        self.user_name = env.USERNAME.string
        self.local_profile_folder = get_local_profile_dir()
        self.drag_file = ''
        self.wrappers_dir = WRAPPERS
        self.app_dir = APP_DIR
        self.icon_combo_box = QtWidgets.QComboBox()
        self.user_image = htk.pathjoin(self.local_profile_folder, "user.png")
        self.delete = False
        self.gui_show = True
        self.drag_pos = QtCore.QPoint(0, 0)
        self.right_button = False
        self.background_image = None
        _image = om.read(self.local_profile_folder, 'skin')

        # init windows
        self.setAttribute(QtCore.Qt.WA_DeleteOnClose)
        self.setWindowFlags(QtCore.Qt.FramelessWindowHint |
                            QtCore.Qt.Window |
                            QtCore.Qt.WindowStaysOnTopHint |
                            QtCore.Qt.WindowSoftkeysRespondHint)
        self.comboBox_project_list.addItems(self.get_project_list())

        self.set_current_project()

        self.icon_combo_box.addItem(self.icon("default_software_icon.png"),
                                    "Dmyz")
        self.quit_action = QtWidgets.QAction("exit", self,
                                             triggered=QtWidgets.QApplication.quit)
        open_log_action = QtWidgets.QAction("Explore Log Folder ",
                                            self,
                                            triggered=self.go_to_log_folder)

        self.open_local_folder = QtWidgets.QAction(
            "Open Local Settings Folder",
            self,
            triggered=self.explore_local_settings_folder)
        project_manager_action = QtWidgets.QAction("project manager",
                                                   self,
                                                   triggered=self.go_to_log_folder)

        self.tray_icon_menu = QtWidgets.QMenu(self)
        if _image:
            self.background_image = _image.encode("utf-8").replace("\\", "/")

        self.skin_action = QtWidgets.QAction('Skin Store', self,
                                             triggered=self.show_skin_widget)

        self.change_css = QtWidgets.QMenu('Change CSS', self.tray_icon_menu)

        default = QtWidgets.QAction("default", self.change_css,
                                    triggered=self.change_css_default)

        self.change_css.addAction(default)

        self.tray_icon_menu.addAction(self.skin_action)

        self.tray_icon_menu.addAction(self.open_local_folder)

        self.tray_icon_menu.addAction(project_manager_action)

        self.tray_icon_menu.addAction(open_log_action)

        random_skin_aciton = self._action("random_skin", self._skin_timer)
        random_skin_aciton.setCheckable(True)
        status = om.read(self.local_profile_folder, "random_skin")
        if status:
            random_skin_aciton.setChecked(status)

        self.tray_icon_menu.addAction(random_skin_aciton)

        self.tray_icon_menu.addMenu(self.change_css)
        self.tray_icon_menu.addAction(self.quit_action)
        gif_file = HZResources.get_icon_resources("default_software_icon.gif")
        self.tray_icon = AnimatedSystemTrayIcon(QtGui.QMovie(gif_file),
                                                self)
        self.tray_icon.setContextMenu(self.tray_icon_menu)
        self.icon_combo_box.currentIndexChanged.connect(self.set_icon)
        self.setWindowIcon(self.icon("default_software_icon.png"))
        self.icon_combo_box.setCurrentIndex(1)
        self.tray_icon.show()
        self.tray_icon.setToolTip('HZ')
        self.tray_icon.activated.connect(self.icon_activated)
        self.setAcceptDrops(True)
        self.set_transparency(True)

        if os.path.isfile(self.user_image):
            self.user_button.setIcon(
                self.create_round_thumbnail(self.user_image))
        else:
            self.user_button.setIcon(self.create_round_thumbnail(
                self.icon("default_user_thumb.png", True)))

        self.pushButton_bottom_icon.setIcon(self.icon("software_name.png"))
        self.pushButton_top_icon.setIcon(self.icon("hz_label.png"))
        self.pushButton_hide.setIcon(self.icon("software_manager_hide.png"))
        self.pushButton_close.setIcon(self.icon("software_manager_close.png"))
        self.pushButton_hide.clicked.connect(self.close)
        self.pushButton_close.clicked.connect(QtWidgets.QApplication.quit)
        self.tool_box = QtWidgets.QToolBox()
        self.software_commands = QtWidgets.QListWidget(self)
        self.software_commands.itemDoubleClicked.connect(self.launch)
        self.software_commands.setContextMenuPolicy(
            QtCore.Qt.ActionsContextMenu)
        self.verticalLayout_3.addWidget(self.software_commands)
        self.search_text.textChanged.connect(self.search_software)
        self.pushButton_bottom_icon.clicked.connect(self.popup_web)

        self.user_menu = QtWidgets.QMenu(self)

        self.user_menu.addSeparator()

        user_action = QtWidgets.QAction("change user image", self,
                                        triggered=self.set_user_image)

        self.user_menu.addAction(user_action)

        self.user_button.setMenu(self.user_menu)

        self.desktop = QtWidgets.QDesktopWidget()

        self.move(self.desktop.availableGeometry().width() - self.width(),
                  self.desktop.availableGeometry().height() - self.height())

        self.save_current_project()
        self.set_items()
        self.comboBox_project_list.activated.connect(self.set_items)
        self.update_info_file = htk.pathjoin(self.resources.resources_root,
                                             'update.txt')
        self.file_watcher = QtCore.QFileSystemWatcher([self.update_info_file])
        self.file_watcher.fileChanged.connect(self.on_file_changed)
        self.timer = QtCore.QTimer(self)
        self.timer.timeout.connect(self.time_task)
        self.timer.start(1000)
        if self.background_image:
            self.set_background_image_css(
                self.background_image.decode("utf-8"))
        else:
            self.set_background_image_css(self.get_skin())
        self.skin_timer = QtCore.QTimer(self)
        self.skin_timer.timeout.connect(self.random_skin)
        if status:
            self.skin_timer.start(20000)
示例#18
0
    # ..and a dictionary..
    odict = om.Entry('mydict.dict', parent=olist)

    # ..with two keys
    key1 = om.Entry('key1.string', value='value', parent=odict)

    # One of which, we neglect to specify a value-type.
    # The value-type will be determined via the Python value-type <str>
    key2 = om.Entry('key2', value='value', parent=odict)

    # Finally, write it to disk.
    om.flush(location)

    # ----------- Read it back in

    assert om.read(root) == ['mylist', 'simple_data']

    assert om.read(root, 'mylist') == ['item2',
                                       'item3',
                                       'item1',
                                       'mydict',
                                       'item4']

    assert om.read(root, 'mylist/item2') is True

    # ------------ Remove additions

finally:
    shutil.rmtree(root)
示例#19
0
 def test_existing(self):
     """Read from existing metadata"""
     value = om.read(self.project_path, 'height')
     self.assertEquals(value, 10)
示例#20
0
 def test_write_invalidgroup(self):
     om.write(self.root_path, '/deep/data.string/key', 'value')
     self.assertEquals(om.read(self.root_path, '/deep/data/key'), 'value')
raise NotImplementedError

import os
import time
import openmetadata as om
om.setup_log()

# Starting-point
path = os.path.expanduser(r'~/om')

# Add and modify data, with 1.2 seconds inbetween changes.
# *note: History is stored in seconds. Any changes occuring within
# 1 second will be overwritten. Not what you want? Let us know.
# https://groups.google.com/forum/#!forum/open-metadata

om.write(path, 'girlfriend', 'Lucy Lui')
print "Sleeping for 1.2 seconds.."
time.sleep(1.2)
om.write(path, 'girlfriend', 'Sandra Bullock')

assert om.read(path, 'girlfriend') == 'Sandra Bullock'

# To get the history, we must first get an
# instance of the Dataset 'girlfriend'
dataset = om.read(path, 'girlfriend', convert=False)
imprint = next(om.history(dataset))
om.restore(imprint, removehistory=False)

assert om.read(path, 'girlfriend') == 'Lucy Lui'
示例#22
0
    om.write(root, 'age', 27)

    data = {
        'firstname': 'Marcus',
        'lastname': 'Ottosson',
        'email': '[email protected]'
    }

    for key, value in data.iteritems():
        om.write(root, key, value)

    # Write deeply nested data
    om.write(root, '/root/group/amazing', True)

    # Successfully wrote: c:\users\marcus\om_temp\.meta\status.bool
    # Successfully wrote: c:\users\marcus\om_temp\.meta\story.string
    # Successfully wrote: c:\users\marcus\om_temp\.meta\age.int
    # Successfully wrote: c:\users\marcus\om_temp\.meta\lastname.string
    # Successfully wrote: c:\users\marcus\om_temp\.meta\email.string
    # Successfully wrote: c:\users\marcus\om_temp\.meta\firstname.string
    # Successfully wrote: c:\users\marcus\om_temp\.meta\root.dict\group.dict\amazing.bool

    # --------- Read it back in

    assert om.read(root, '/age') == 27
    assert om.read(root, '/status') is True
    assert om.read(root, '/root/group/amazing') is True

finally:
    shutil.rmtree(root)
raise NotImplementedError

import os
import openmetadata as om

# Starting-point
path = os.path.expanduser(r'~/om')

location = om.Location(path)

# Add a regular string
password = om.Dataset('password.string', parent=location)
password.data = 'abcdef'

# Write first occurence of dataset
om.flush(password)

# Save version and update dataset
om.save(password)
password.data = 'Sandra Bullock'
om.flush(password)

assert om.read(path, 'password') == 'Sandra Bullock'

# Restore previous value from history
# *note: om.history() returns a Python generator.
imprint = om.history(password).next()
om.restore(imprint)

assert om.read(path, 'password') == 'Lucy Lui'
示例#24
0
 def test_existing_known_type(self):
     value = om.read(self.project_path, 'height.int')
     self.assertEquals(value, 10)
示例#25
0
 def test_write_simple(self):
     om.write(self.root_path, 'simple', 'value')
     self.assertEquals(om.read(self.root_path, 'simple'), 'value')
示例#26
0
 def test_write_deep(self):
     om.write(self.root_path, '/deep/data/key', 'value')
     self.assertEquals(om.read(self.root_path, '/deep/data/key'), 'value')