Exemplo n.º 1
0
    def __call__(self):
        print "tagged: ", self.namespace.tagged
        #for m_method_name, m_method_info in config.mendely_class.methods.iteritems():
        #    x = getattr(self.namespace, m_method_name)
        #    if x != '':
        #       print m_method_name, ": ", x

        mendeley_proxy.lazy_init_config()
        for method in self.namespace.tagged:
            try:
                func = getattr(mendeley_proxy.mendeley, method)
            except AttributeError:
                continue
            else:
                if not func:
                    print "client method not found %s." % method
                    continue
                param = getattr(self.namespace, method)
                print "FUNC %s, PARAM %s" % (func, param)

                response = func(mendeley_proxy.mendeley)
                print "RESPONE:"
                pprint.pprint(response, indent = 3, depth = 99)
    def __call__(self):
        print "accessing your mendeley account..."
        mendeley_proxy.lazy_init_config()

        fld = mendeley_proxy.folder(self.folder, ignore_case = True)

        if fld == None:
            print "folder '%s' not found, please select from your groups:" % self.folder
            CONTENT = "%10s|%s"
            print CONTENT % ("id", "group name")
            print "-" * 30
            flds = mendeley_proxy.folders()
            for fld in flds:
                print CONTENT % (fld.id, fld.name)
            sys.exit()

        # request content of mendeley-directory
        print "quering your mendeley papers (in directory '%s')..." % fld.name
        docs = fld.docs
        if not self.ima:
            def foo(doc):
                #print "DEBUG ", repr(doc), len(doc.abstract)
                return len(doc.abstract) <= 10

            res = filter(foo, docs)
            if len(res) > 0:
                print "some papers have no abstract:"
                for doc in res:
                    print "| %s\n|   (%s)" % (doc.title, doc.authorspp)
                sys.exit(-1)

        outdir = os.path.abspath(config.output_directory or os.path.curdir)
        util.trymkdir(outdir)

        texfilename = os.path.join(outdir, "%s.tex" % self.filename)
        pdffilename = os.path.join(outdir, "%s.pdf" % self.filename)
        print "generating files '%s'..." % pdffilename
        out = codecs.open(texfilename, "w+", "utf-8")

        out.write(stream_base_begin(
                foldername = "%s (id %s)" % (fld.name, fld.id),
                today = datetime.datetime.now().isoformat()))
        for doc in docs:
            out.write(stream_entry(
                title = doc.title,
                abstract = doc.abstract,
                authors = doc.authorspp,
                type = doc.type,
                published = doc.publisher,
                year = doc.year,
                keywords = u", ".join(doc.keywords)
            ))
        out.write(stream_base_end())

        if os.path.exists(pdffilename):
            os.unlink(pdffilename)
        cmd = "%s --output-directory %s -interaction batchmode %s" % (config.pdflatex, outdir, texfilename)
        try:
            util.exec_cmd(cmd)
            util.exec_cmd(cmd)
        except subprocess.CalledProcessError:
            pass
        assert os.access(pdffilename, os.R_OK)

        cmd = "%s %s" % (config.pdfopen, pdffilename)
        util.exec_cmd(cmd)