Example #1
0
def embed(tcop, files):
    # embed the specified claim in each file
    for filename in files:
        try:
            metadata(filename).setClaim(tcop)
        except:
            traceback.print_exc()
            sys.exit(2)
Example #2
0
def lookup(filename, displayOnly=False):

    # retrieve the license claim
    mdata = metadata(filename)
    claim = mdata.getClaim()

    # check if it actually exists
    if claim is None:
        # no license; bail out
        print "%s does not contain a copyright/license claim." % filename
        return None
    else:
        print "%s contains the following claim:" % filename
        print claim

        if displayOnly:
            # only displaying; bail out
            return None

    # verify the file
    try:
        if cctag.lookup.lookup(filename):
            print "Verified."
        else:
            print "Unable to verify claim."
    except:
        # an error occured while trying to verify the claim...
        # print a traceback to stderr and return the appropriate exit code
        pprint.pprint(sys.exc_info(), sys.stderr)
        sys.exit(3)
Example #3
0
 def _checkFile(self, filename):
     """Extracts license info from the specified file and
     returns true if it matches the set dummy info.
     """
     return (metadata(filename).getClaim() ==
             "%s %s. Licensed to the public under %s verify at %s" %
             (self.YEAR, self.HOLDER, self.LICENSE, self.VERIFY)
             )
Example #4
0
def verify(filename):
    """Extracts license claim information from a file and verifies it.
    Returns the following status codes:
    1     Verified
    0     No RDF
    -1    Work information not found (possible SHA1 mismatch)
    -2    Verification license does not match claim.
    """

    status = 0
    
    claim = metadata(filename).getClaim()
    if claim is None:
        raise cctag.exceptions.NotLicensedException
    
    fileinfo = parseClaim(claim)
    fileinfo['sha'] = 'urn:sha1:%s' % cctag.rdf.fileHash(filename)

    verifyRdf = rdfextract.RdfExtractor().extractRdfText(
        rdfextract.retrieveUrl(fileinfo['verify at'])
        )

    # check if we found any RDF at all, and update the status code
    if len(verifyRdf) > 0:
        status = -1

    # check each block of RDF
    #  (a verification page may also have it's own license RDF embedded)
    for block in verifyRdf:
        # parse/validate the RDF
        verifyCc = ccrdf.ccRdf()
        verifyCc.parse(block)

        # for each work in the RDF block...
        for work in verifyCc.works():
            
            # if the subject matches...
            if work.subject == fileinfo['sha']:
                # we found the work information;
                # only one reason left to not verify
                status = -2
                
                # we found the work, now make sure the license matches
                for license in work.licenses():
                    if license == fileinfo['license']:
                        return 1

    # either the file wasn't found, or the license didn't match
    return status
Example #5
0
    def onEmbed(self, event):
        # make sure we have all the information we need
        if not(self._readyToEmbed(event)):
            return

        # get form values
        license = XRCCTRL(self, "TXT_LICENSE").GetValue()
        verify_url = XRCCTRL(self, "TXT_VERIFICATION").GetValue()
        year = XRCCTRL(self, "TXT_YEAR").GetValue()
        holder = XRCCTRL(self, "TXT_HOLDER").GetValue()

        for filename in self._files:
            metadata(filename).embed(license, verify_url, year, holder)

        # make sure we have the license RDF for this license
        if license not in LICENSE_URLS or \
               (license in LICENSE_URLS and LICENSE_URLS[license] is None):
            LICENSE_URLS[license] = rdf.getLicense(license)
        
        # generate the verification RDF
        verification = rdf.generate(self._files, verify_url, 
                                    license, year, holder,
                                    license_rdf=LICENSE_URLS[license])
        XRCCTRL(self, "TXT_RDF").SetValue(verification)
Example #6
0
    def selectFiles(self, files):
        self._files = files
        if len(self._files) == 0: return
        
        # set the value of copyright holder (artist) and copyright year
        file_info = metadata(self._files[0])

        try:
           XRCCTRL(self, "TXT_HOLDER").SetValue(str(file_info.getArtist()))
           XRCCTRL(self, "TXT_YEAR").SetValue(str(file_info.getYear()))
        except NotImplementedError:
           # not a supported file type; show an error message
           wx.MessageBox("Unknown file type; unable to embed license.",
                         caption="ccTag: Error.",
                         style=wx.OK|wx.ICON_ERROR, parent=self)
           return
        
        # should we check for an existing claim here and parse if available?
        
        # set the value of the filenames control
        XRCCTRL(self, "TXT_FILENAME").SetValue(", ".join(self._files))

        # clear the verification RDF
        XRCCTRL(self, "TXT_VERIFICATION").SetValue("")
Example #7
0
 def _embedFile(self, filename):
     """Embeds the specified file with dummy license info for validation.
     """
     metadata(filename).embed(self.LICENSE, self.VERIFY,
                              self.YEAR, self.HOLDER)