Example #1
0
    def __init__(self, source):
        super(IntermediateDataExporter, self).__init__()
        assert os.path.exists(
            source), "Source file '%s' does not exist" % source

        # Load intermediate data
        self.idata = IntermediateShortcutData()
        self.idata.load(source)

        # Get app prefs from intermediate data format
        self.app_name = self.idata.name
        self.app_version = self.idata.version
        self.default_context_name = self.idata.default_context

        # Windows and Mac app configs
        self.data_windows = None
        self.data_mac = None
        if OS_WINDOWS in self.idata.os:
            self.data_windows = ApplicationConfig(self.app_name,
                                                  self.app_version, OS_WINDOWS,
                                                  self.default_context_name)
        if OS_MAC in self.idata.os:
            self.data_mac = ApplicationConfig(self.app_name, self.app_version,
                                              OS_MAC,
                                              self.default_context_name)
Example #2
0
    def parse(self):
        if not os.path.exists(self.source_file):
            log.error("Source file '%s' does not exist", self.source_file)
            return

        # Windows and Mac appconfigs
        self.app_win = ApplicationConfig(self.app_name, self.app_version, 'windows', self.default_context_name)
        self.app_mac = ApplicationConfig(self.app_name, self.app_version, 'mac', self.default_context_name)

        # Load intermediate data
        idata = AdobeIntermediateData()
        idata.load(self.source_file)

        # WINDOWS: Iterate contexts and shortcuts
        log.info("Parsing intermediate data for Windows shortcuts")
        for context in idata.contexts:
            context_win = self.app_win.get_or_create_new_context(context.name)
            for shortcut in context.shortcuts:
                for s in self._parse_shortcut(shortcut.name, shortcut.win_keys):
                    context_win.add_shortcut(s)

        # MAC: Iterate contexts and shortcuts
        log.info("Parsing intermediate data for MacOS shortcuts")
        for context in idata.contexts:
            context_mac = self.app_mac.get_or_create_new_context(context.name)
            for shortcut in context.shortcuts:
                for s in self._parse_shortcut(shortcut.name, shortcut.mac_keys):
                    context_mac.add_shortcut(s)
Example #3
0
    def __init__(self, source, app_name, app_version, defualt_context_name):
        super(AdobeExporter, self).__init__()
        self.source_file = source
        self.app_name = app_name
        self.app_version = app_version
        self.default_context_name = defualt_context_name

        # Windows and Mac appconfigs
        self.app_win = ApplicationConfig(self.app_name, self.app_version, 'windows', self.default_context_name)
        self.app_mac = ApplicationConfig(self.app_name, self.app_version, 'mac', self.default_context_name)
Example #4
0
class IntermediateDataExporter(object):
    """Exports an intermediate .json file to the contents/generated directory in the correct file format."""
    def __init__(self, source):
        super(IntermediateDataExporter, self).__init__()
        assert os.path.exists(
            source), "Source file '%s' does not exist" % source

        # Load intermediate data
        self.idata = IntermediateShortcutData()
        self.idata.load(source)

        # Get app prefs from intermediate data format
        self.app_name = self.idata.name
        self.app_version = self.idata.version
        self.default_context_name = self.idata.default_context

        # Windows and Mac app configs
        self.data_windows = None
        self.data_mac = None
        if OS_WINDOWS in self.idata.os:
            self.data_windows = ApplicationConfig(self.app_name,
                                                  self.app_version, OS_WINDOWS,
                                                  self.default_context_name)
        if OS_MAC in self.idata.os:
            self.data_mac = ApplicationConfig(self.app_name, self.app_version,
                                              OS_MAC,
                                              self.default_context_name)

    def _parse_shortcut(self, name, keys):
        if len(keys) == 0:
            return []

        # All cases we need to handle:
        #  "A"
        #  "Shift + A"
        #  "Ctrl + 0 - 8"     this is a range of keys from 0 to 8
        #  "Shift + ] / Shift + ["
        #  ". (period) / , (comma)"
        #  "Spacebar or Z"
        #  "Up Arrow / Down Arrow or + / -"
        #  "Shift + Up Arrow / Shift + Down Arrow or Shift + + / Shift + -"

        # Cleanup the string and replace edge cases
        keys = re.sub("numpad \+", "NUMPAD_PLUS", keys, flags=re.IGNORECASE)
        keys = re.sub("numpad /", "NUMPAD_SLASH", keys, flags=re.IGNORECASE)
        keys = keys.replace(" or +", " or TEMP_PLUS")
        keys = keys.replace(" or /", " or TEMP_SLASH")
        keys = keys.replace(" + +", " + TEMP_PLUS")
        keys = keys.replace(" + /", " + TEMP_SLASH")
        keys = keys.strip(" ")
        if keys == '/':
            keys = "TEMP_SLASH"
        if keys == '+':
            keys = "TEMP_PLUS"

        # If we split by ' or ' and then ' / ' we can parse each combo separately
        combo_parts = []
        for parts1 in keys.split(' or '):
            for parts2 in parts1.split('/'):
                combo_parts.append(parts2)

        # Parse each combo
        shortcuts = []
        for combo in combo_parts:
            # TODO: skip mouse shortcuts for now
            if 'click' in combo.lower() or 'drag' in combo.lower():
                continue

            parts = combo.split("+")

            # Parse main key
            key = parts[-1]  # last element
            key = key.strip(' ')
            if key == 'TEMP_SLASH':
                key = '/'
            elif key == 'TEMP_PLUS':
                key = '+'

            # Has no key
            if len(key) == 0:
                continue

            # Parse modifiers
            mods = [m.strip(u' ') for m in parts[:-1]]  # all but last

            # Handle a range of keys (Example: "Ctrl + 0-9")
            #  which will result in multiple shortcuts with the same label
            if re.match("[0-9]*.-.[0-9]*", key):
                start = int(key[0])
                end = int(key[-1])
                for i in range(start, end + 1):
                    shortcut = Shortcut(name, str(i), mods)
                    shortcuts.append(shortcut)

            # Result is just one shortcut
            else:
                shortcut = Shortcut(name, key, mods)
                shortcuts.append(shortcut)

        return shortcuts

    def parse(self):
        # WINDOWS: Iterate contexts and shortcuts
        if self.data_windows:
            log.info("Parsing intermediate data for Windows shortcuts")
            for context in self.idata.contexts:
                context_win = self.data_windows.get_or_create_new_context(
                    context.name)
                for shortcut in context.shortcuts:
                    for s in self._parse_shortcut(shortcut.name,
                                                  shortcut.win_keys):
                        context_win.add_shortcut(s)
            log.info("...DONE\n")

        # MAC: Iterate contexts and shortcuts
        if self.data_mac:
            log.info("Parsing intermediate data for MacOS shortcuts")
            for context in self.idata.contexts:
                context_mac = self.data_mac.get_or_create_new_context(
                    context.name)
                for shortcut in context.shortcuts:
                    for s in self._parse_shortcut(shortcut.name,
                                                  shortcut.mac_keys):
                        context_mac.add_shortcut(s)
            log.info("...DONE\n")

    def export(self):
        if self.data_windows:
            self.data_windows.serialize(DIR_CONTENT_GENERATED)
        if self.data_mac:
            self.data_mac.serialize(DIR_CONTENT_GENERATED)
Example #5
0
class AdobeExporter(object):
    """Exports an intermediate .json file to the gh-pages appdata dir in the correct file format."""

    def __init__(self, source, app_name, app_version, defualt_context_name):
        super(AdobeExporter, self).__init__()
        self.source_file = source
        self.app_name = app_name
        self.app_version = app_version
        self.default_context_name = defualt_context_name

        # Windows and Mac appconfigs
        self.app_win = ApplicationConfig(self.app_name, self.app_version, 'windows', self.default_context_name)
        self.app_mac = ApplicationConfig(self.app_name, self.app_version, 'mac', self.default_context_name)

    def _parse_shortcut(self, name, keys):
        if len(keys) == 0:
            return []

        # All cases we need to handle:
        #  "A"
        #  "Shift + A"
        #  "Ctrl + 0 - 8"     this is a range of keys from 0 to 8
        #  "Shift + ] / Shift + ["
        #  ". (period) / , (comma)"
        #  "Spacebar or Z"
        #  "Up Arrow / Down Arrow or + / -"
        #  "Shift + Up Arrow / Shift + Down Arrow or Shift + + / Shift + -"

        # Cleanup the string and replace edge cases
        keys = keys.replace(" or +", " or TEMP_PLUS")
        keys = keys.replace(" or /", " or TEMP_SLASH")
        keys = keys.replace(" + +", " + TEMP_PLUS")
        keys = keys.replace(" + /", " + TEMP_SLASH")
        keys = keys.strip(" ")
        if keys == '/':
            keys = "TEMP_SLASH"
        if keys == '+':
            keys = "TEMP_PLUS"

        # If we split by ' or ' and then ' / ' we can parse each combo separately
        combo_parts = []
        for parts1 in keys.split(' or '):
            for parts2 in parts1.split('/'):
                combo_parts.append(parts2)

        # Parse each combo
        shortcuts = []
        for combo in combo_parts:
            # TODO: skip mouse shortcuts for now
            if 'click' in combo.lower() or 'drag' in combo.lower():
                continue

            parts = combo.split("+")

            # Parse main key
            key = parts[-1] #last element
            key = key.strip(' ')
            if key == 'TEMP_SLASH':
                key = '/'
            elif key == 'TEMP_PLUS':
                key = '+'

            # Has no key
            if len(key) == 0:
                continue

            # Parse modifiers
            mods = [m.strip(u' ') for m in parts[:-1]] #all but last

            # For numerical key shortcuts, the adobe documentation specifies a "range of keys"
            #  which will result in multiple shortcuts with the same label
            if re.match("[0-9]*.-.[0-9]*", key):
                start = int(key[0])
                end = int(key[-1])
                for i in range(start, end+1):
                    shortcut = Shortcut(name, str(i), mods)
                    shortcuts.append(shortcut)

            # Result is just one shortcut
            else:
                shortcut = Shortcut(name, key, mods)
                shortcuts.append(shortcut)


        return shortcuts

    def parse(self):
        if not os.path.exists(self.source_file):
            log.error("Source file '%s' does not exist", self.source_file)
            return

        # Windows and Mac appconfigs
        self.app_win = ApplicationConfig(self.app_name, self.app_version, 'windows', self.default_context_name)
        self.app_mac = ApplicationConfig(self.app_name, self.app_version, 'mac', self.default_context_name)

        # Load intermediate data
        idata = AdobeIntermediateData()
        idata.load(self.source_file)

        # WINDOWS: Iterate contexts and shortcuts
        log.info("Parsing intermediate data for Windows shortcuts")
        for context in idata.contexts:
            context_win = self.app_win.get_or_create_new_context(context.name)
            for shortcut in context.shortcuts:
                for s in self._parse_shortcut(shortcut.name, shortcut.win_keys):
                    context_win.add_shortcut(s)

        # MAC: Iterate contexts and shortcuts
        log.info("Parsing intermediate data for MacOS shortcuts")
        for context in idata.contexts:
            context_mac = self.app_mac.get_or_create_new_context(context.name)
            for shortcut in context.shortcuts:
                for s in self._parse_shortcut(shortcut.name, shortcut.mac_keys):
                    context_mac.add_shortcut(s)


    def export(self):
        self.app_win.serialize(DIR_PAGES_APPDATA)
        self.app_mac.serialize(DIR_PAGES_APPDATA)