Esempio n. 1
0
    def download_resource(self, resource, extra_params=None):
        """
        Downloads files of Google Documents type and puts them in the
        correct folders according to Docs collections.
        """
        current_folder = resource.InCollections()[0].title.encode('UTF-8')
        document_name = resource.title.text.encode('UTF-8')
        file_ext = '.txt'

        print '=' * 50
        print 'Document name: ' + document_name

        # if document is in the root collection, then it is
        # saved in the root
        if current_folder.lower() == self.docs_folder.lower():
            file_path = os.path.join(self.base_path, document_name + file_ext)
            if utilfunc.make_directory(file_path):
                self.docs_client.DownloadResource(resource, file_path,
                                                    extra_params)
            print 'Saved in the base folder ({0}{1}{0})\n'.format(os.sep,
                                                                current_folder)
        else:
            file_path = os.path.join(self.base_path, current_folder,
                                     document_name + file_ext)
            if utilfunc.make_directory(file_path):
                self.docs_client.DownloadResource(resource, file_path,
                                                    extra_params)
            print 'Saved in subfolder ({0}{1}{0})\n'.format(os.sep,
                                                            current_folder)

        utilfunc.remove_ext_txt(file_path)
Esempio n. 2
0
    def download_resource(self, resource, extra_params=None):
        """
        Downloads files of Google Documents type and puts them in the
        correct folders according to Docs collections.
        """
        current_folder = resource.InCollections()[0].title.encode('UTF-8')
        document_name = resource.title.text.encode('UTF-8')
        file_ext = '.txt'

        print '=' * 50
        print 'Document name: ' + document_name

        # if document is in the root collection, then it is
        # saved in the root
        if current_folder.lower() == self.docs_folder.lower():
            file_path = os.path.join(self.base_path, document_name + file_ext)
            if utilfunc.make_directory(file_path):
                self.docs_client.DownloadResource(resource, file_path,
                                                  extra_params)
            print 'Saved in the base folder ({0}{1}{0})\n'.format(
                os.sep, current_folder)
        else:
            file_path = os.path.join(self.base_path, current_folder,
                                     document_name + file_ext)
            if utilfunc.make_directory(file_path):
                self.docs_client.DownloadResource(resource, file_path,
                                                  extra_params)
            print 'Saved in subfolder ({0}{1}{0})\n'.format(
                os.sep, current_folder)

        utilfunc.remove_ext_txt(file_path)
Esempio n. 3
0
    def cleanup_latex(self):
        latex_temp_extensions = ('.aux', '.bbl', '.blg', '.log', '.toc',
                          '.lof', '.lot',)
        temp_folder_name = 'temp'

        for root, dirs, files in os.walk(self.base_path):
            for file in files:
                if file.endswith(latex_temp_extensions):
                    source = os.path.join(root, file)
                    destination = os.path.join(root, temp_folder_name, file)
                    # path has to exist before shutil.move
                    if not os.path.exists(destination):
                        utilfunc.make_directory(destination)
                    shutil.move(source, destination)