Subversion Repositories basico

Rev

Rev 370 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 370 Rev 400
Line 35... Line 35...
35
        Generate new attachment id (same as for annotations)
35
        Generate new attachment id (same as for annotations)
36
        '''
36
        '''
37
        return "%s@T%s" % (sid, str(uuid.uuid4()))
37
        return "%s@T%s" % (sid, str(uuid.uuid4()))
38
38
39
39
40
    def create(self, path, aid):
-
 
-
 
40
    def create(self, path, aid):
41
        sid = self.get_sid(aid)
41
        sid = self.get_sid(aid)
42
        tid = self.gen_tid(sid)
42
        tid = self.gen_tid(sid)
43
        metadata = self.srvutl.get_file_metadata(path)
43
        metadata = self.srvutl.get_file_metadata(path)
44
        metadata['AID'] = aid
44
        metadata['AID'] = aid
45
        metadata['TID'] = tid
45
        metadata['TID'] = tid
Line 47... Line 47...
47
        metadata['Created'] = self.srvutl.timestamp()
47
        metadata['Created'] = self.srvutl.timestamp()
48
        self.log.debug("\tAID: %s", aid)
48
        self.log.debug("\tAID: %s", aid)
49
        self.log.debug("\tTID: %s", tid)
49
        self.log.debug("\tTID: %s", tid)
50
        self.log.debug("\tPath: %s", path)
50
        self.log.debug("\tPath: %s", path)
51
        self.log.debug("\tCreated: %s", metadata['Created'])
51
        self.log.debug("\tCreated: %s", metadata['Created'])
52
        ATTACHMENT_FILE_METADATA = LPATH['ATTACHMENTS'] + tid + '.json'
-
 
-
 
52
        ATTACHMENT_FILE_METADATA = LPATH['ATTACHMENTS'] + tid + '.json'
53
        ATTACHMENT_FILE_CONTENT = LPATH['ATTACHMENTS'] + tid # No extension needed
53
        ATTACHMENT_FILE_CONTENT = LPATH['ATTACHMENTS'] + tid # No extension needed
54
       
-
 
-
 
54
55
        # copy attachment file to attachemnts database
55
        # copy attachment file to attachemnts database
56
        shutil.copy(path, ATTACHMENT_FILE_CONTENT)
56
        shutil.copy(path, ATTACHMENT_FILE_CONTENT)
57
57
58
        # Write attachment metadata
58
        # Write attachment metadata
59
        with open(ATTACHMENT_FILE_METADATA, 'w') as fa:
59
        with open(ATTACHMENT_FILE_METADATA, 'w') as fa:
60
            json.dump(metadata, fa)
60
            json.dump(metadata, fa)
61
61
62
        self.log.info("Attachment '%s' (%s) created" % (metadata['Title'], metadata['TID']))
62
        self.log.info("Attachment '%s' (%s) created" % (metadata['Title'], metadata['TID']))
63
63
64
        return tid
64
        return tid
65
       
-
 
-
 
65
66
66
67
    def delete(self, aid):
67
    def delete(self, aid):
68
        sid = self.get_sid(aid)
68
        sid = self.get_sid(aid)
69
        ATTACHMENT_FILE_METADATA = LPATH['ATTACHMENTS'] + aid + '.json'
69
        ATTACHMENT_FILE_METADATA = LPATH['ATTACHMENTS'] + aid + '.json'
70
        ATTACHMENT_FILE_CONTENT = LPATH['ATTACHMENTS'] + aid
70
        ATTACHMENT_FILE_CONTENT = LPATH['ATTACHMENTS'] + aid
Line 80... Line 80...
80
80
81
81
82
    def get_by_sid(self, sid):
82
    def get_by_sid(self, sid):
83
        matches = set()
83
        matches = set()
84
        ATTACHMENT_FILES = LPATH['ATTACHMENTS'] + '*.json'
84
        ATTACHMENT_FILES = LPATH['ATTACHMENTS'] + '*.json'
85
        attachments = glob.glob(ATTACHMENT_FILES)        
-
 
-
 
85
        attachments = glob.glob(ATTACHMENT_FILES)
86
        for attachment in attachments:
86
        for attachment in attachments:
87
            if sid in attachment:
87
            if sid in attachment:
88
                matches.add(attachment)
88
                matches.add(attachment)
89
        # ~ self.log.debug("Attachments for SAP Note %s: %s", sid, matches)
89
        # ~ self.log.debug("Attachments for SAP Note %s: %s", sid, matches)
90
        return matches
90
        return matches
Line 126... Line 126...
126
126
127
127
128
    def get_metadata_value(self, tid, key):
128
    def get_metadata_value(self, tid, key):
129
        metadata = self.get_metadata_from_tid(tid)
129
        metadata = self.get_metadata_from_tid(tid)
130
        return metadata[key]
130
        return metadata[key]
-
 
131
131
132
132
    def is_valid(self, aid):
133
    def is_valid(self, aid):
133
        ATTACHMENT_FILE_METADATA = LPATH['ATTACHMENTS'] + aid + '.json'
134
        ATTACHMENT_FILE_METADATA = LPATH['ATTACHMENTS'] + aid + '.json'
134
        ATTACHMENT_FILE_CONTENT = LPATH['ATTACHMENTS'] + aid
135
        ATTACHMENT_FILE_CONTENT = LPATH['ATTACHMENTS'] + aid
135
        ATTACHMENT_FILE = LPATH['ATTACHMENTS'] + aid + '.json'
136
        ATTACHMENT_FILE = LPATH['ATTACHMENTS'] + aid + '.json'