Esempio n. 1
0
    def initialize(self):
        """
        Dynamic modules can't be imported/loaded from a zipfile.
        So this routine will extract the appropriate
        library for the target OS and copy it to the 'alfcrypto' subdirectory of
        calibre's configuration directory. That 'alfcrypto' directory is then
        inserted into the syspath (as the very first entry) in the run function
        so the CDLL stuff will work in the alfcrypto.py script.

        The extraction only happens once per version of the plugin
        Also perform upgrade of preferences once per version
        """
        try:
            self.pluginsdir = os.path.join(config_dir,u"plugins")
            if not os.path.exists(self.pluginsdir):
                os.mkdir(self.pluginsdir)
            self.maindir = os.path.join(self.pluginsdir,u"DeDRM")
            if not os.path.exists(self.maindir):
                os.mkdir(self.maindir)
            self.helpdir = os.path.join(self.maindir,u"help")
            if not os.path.exists(self.helpdir):
                os.mkdir(self.helpdir)
            self.alfdir = os.path.join(self.maindir,u"libraryfiles")
            if not os.path.exists(self.alfdir):
                os.mkdir(self.alfdir)
            # only continue if we've never run this version of the plugin before
            self.verdir = os.path.join(self.maindir,PLUGIN_VERSION)
            if not os.path.exists(self.verdir):
                if iswindows:
                    names = [u"alfcrypto.dll",u"alfcrypto64.dll"]
                elif isosx:
                    names = [u"libalfcrypto.dylib"]
                else:
                    names = [u"libalfcrypto32.so",u"libalfcrypto64.so",u"kindlekey.py",u"adobekey.py",u"subasyncio.py"]
                lib_dict = self.load_resources(names)
                print u"{0} v{1}: Copying needed library files from plugin's zip".format(PLUGIN_NAME, PLUGIN_VERSION)

                for entry, data in lib_dict.items():
                    file_path = os.path.join(self.alfdir, entry)
                    try:
                        os.remove(file_path)
                    except:
                        pass

                    try:
                        open(file_path,'wb').write(data)
                    except:
                        print u"{0} v{1}: Exception when copying needed library files".format(PLUGIN_NAME, PLUGIN_VERSION)
                        traceback.print_exc()
                        pass

                # convert old preferences, if necessary.
                from calibre_plugins.dedrm.prefs import convertprefs
                convertprefs()

                # mark that this version has been initialized
                os.mkdir(self.verdir)
        except Exception, e:
            traceback.print_exc()
            raise
Esempio n. 2
0
    def initialize(self):
        """
        Dynamic modules can't be imported/loaded from a zipfile.
        So this routine will extract the appropriate
        library for the target OS and copy it to the 'alfcrypto' subdirectory of
        calibre's configuration directory. That 'alfcrypto' directory is then
        inserted into the syspath (as the very first entry) in the run function
        so the CDLL stuff will work in the alfcrypto.py script.

        The extraction only happens once per version of the plugin
        Also perform upgrade of preferences once per version
        """
        try:
            self.pluginsdir = os.path.join(config_dir,u"plugins")
            if not os.path.exists(self.pluginsdir):
                os.mkdir(self.pluginsdir)
            self.maindir = os.path.join(self.pluginsdir,u"DeDRM")
            if not os.path.exists(self.maindir):
                os.mkdir(self.maindir)
            self.helpdir = os.path.join(self.maindir,u"help")
            if not os.path.exists(self.helpdir):
                os.mkdir(self.helpdir)
            self.alfdir = os.path.join(self.maindir,u"libraryfiles")
            if not os.path.exists(self.alfdir):
                os.mkdir(self.alfdir)
            # only continue if we've never run this version of the plugin before
            self.verdir = os.path.join(self.maindir,PLUGIN_VERSION)
            if not os.path.exists(self.verdir):
                if iswindows:
                    names = [u"alfcrypto.dll",u"alfcrypto64.dll"]
                elif isosx:
                    names = [u"libalfcrypto.dylib"]
                else:
                    names = [u"libalfcrypto32.so",u"libalfcrypto64.so",u"kindlekey.py",u"adobekey.py",u"subasyncio.py"]
                lib_dict = self.load_resources(names)
                print u"{0} v{1}: Copying needed library files from plugin's zip".format(PLUGIN_NAME, PLUGIN_VERSION)

                for entry, data in lib_dict.items():
                    file_path = os.path.join(self.alfdir, entry)
                    try:
                        os.remove(file_path)
                    except:
                        pass

                    try:
                        open(file_path,'wb').write(data)
                    except:
                        print u"{0} v{1}: Exception when copying needed library files".format(PLUGIN_NAME, PLUGIN_VERSION)
                        traceback.print_exc()
                        pass

                # convert old preferences, if necessary.
                from calibre_plugins.dedrm.prefs import convertprefs
                convertprefs()

                # mark that this version has been initialized
                os.mkdir(self.verdir)
        except Exception, e:
            traceback.print_exc()
            raise
Esempio n. 3
0
 def initialize(self):
     # convert old preferences, if necessary.
     try:
         from calibre_plugins.dedrm.prefs import convertprefs
         convertprefs()
     except:
         traceback.print_exc()
     """
     Dynamic modules can't be imported/loaded from a zipfile... so this routine
     runs whenever the plugin gets initialized. This will extract the appropriate
     library for the target OS and copy it to the 'alfcrypto' subdirectory of
     calibre's configuration directory. That 'alfcrypto' directory is then
     inserted into the syspath (as the very first entry) in the run function
     so the CDLL stuff will work in the alfcrypto.py script.
     """
     try:
         if iswindows:
             names = [u"alfcrypto.dll", u"alfcrypto64.dll"]
         elif isosx:
             names = [u"libalfcrypto.dylib"]
         else:
             names = [
                 u"libalfcrypto32.so", u"libalfcrypto64.so",
                 u"kindlekey.py", u"adobekey.py", u"subasyncio.py"
             ]
         lib_dict = self.load_resources(names)
         self.pluginsdir = os.path.join(config_dir, u"plugins")
         if not os.path.exists(self.pluginsdir):
             os.mkdir(self.pluginsdir)
         self.maindir = os.path.join(self.pluginsdir, u"DeDRM")
         if not os.path.exists(self.maindir):
             os.mkdir(self.maindir)
         self.helpdir = os.path.join(self.maindir, u"help")
         if not os.path.exists(self.helpdir):
             os.mkdir(self.helpdir)
         self.alfdir = os.path.join(self.maindir, u"libraryfiles")
         if not os.path.exists(self.alfdir):
             os.mkdir(self.alfdir)
         for entry, data in lib_dict.items():
             file_path = os.path.join(self.alfdir, entry)
             open(file_path, 'wb').write(data)
     except Exception, e:
         traceback.print_exc()
         raise
Esempio n. 4
0
    def initialize(self):
        # convert old preferences, if necessary.
        try:
            from calibre_plugins.dedrm.prefs import convertprefs

            convertprefs()
        except:
            traceback.print_exc()

        """
        Dynamic modules can't be imported/loaded from a zipfile... so this routine
        runs whenever the plugin gets initialized. This will extract the appropriate
        library for the target OS and copy it to the 'alfcrypto' subdirectory of
        calibre's configuration directory. That 'alfcrypto' directory is then
        inserted into the syspath (as the very first entry) in the run function
        so the CDLL stuff will work in the alfcrypto.py script.
        """
        try:
            if iswindows:
                names = [u"alfcrypto.dll", u"alfcrypto64.dll"]
            elif isosx:
                names = [u"libalfcrypto.dylib"]
            else:
                names = [u"libalfcrypto32.so", u"libalfcrypto64.so", u"kindlekey.py", u"adobekey.py", u"subasyncio.py"]
            lib_dict = self.load_resources(names)
            self.pluginsdir = os.path.join(config_dir, u"plugins")
            if not os.path.exists(self.pluginsdir):
                os.mkdir(self.pluginsdir)
            self.maindir = os.path.join(self.pluginsdir, u"DeDRM")
            if not os.path.exists(self.maindir):
                os.mkdir(self.maindir)
            self.helpdir = os.path.join(self.maindir, u"help")
            if not os.path.exists(self.helpdir):
                os.mkdir(self.helpdir)
            self.alfdir = os.path.join(self.maindir, u"libraryfiles")
            if not os.path.exists(self.alfdir):
                os.mkdir(self.alfdir)
            for entry, data in lib_dict.items():
                file_path = os.path.join(self.alfdir, entry)
                open(file_path, "wb").write(data)
        except Exception, e:
            traceback.print_exc()
            raise