~ubuntu-branches/ubuntu/trusty/aptoncd/trusty

« back to all changes in this revision

Viewing changes to parsegz.py

  • Committer: Bazaar Package Importer
  • Author(s): Fabrice Coutadeur
  • Date: 2009-08-19 21:41:06 UTC
  • mfrom: (3 sid) (1.2.1 upstream)
  • mto: This revision was merged to the branch mainline in revision 4.
  • Revision ID: james.westby@ubuntu.com-20090819214106-7g72fpzgvl722w6k
* New maintainer (Closes: #542459, #484637, #542501)
* New upstream release
  - Fix the executable flag on non executable files. This fix last lintian
    warnings
* debian/rules: prepared for python2.6 (include of python.mk and use of 
  $(py_setup_install_args) )

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/usr/bin/env python
2
 
# -*- coding: utf-8 -*-
3
 
######################################################
4
 
##
5
 
#  This program is free software; you can redistribute it and/or modify
6
 
#  it under the terms of the GNU General Public License as published
7
 
#  by the Free Software Foundation; version 2 only.
8
 
#
9
 
#  This program is distributed in the hope that it will be useful,
10
 
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 
#  GNU General Public License for more details.
13
 
##
14
 
######################################################
15
 
## 
16
 
#  Project: AptOnCd
17
 
#  File: parsegz.py
18
 
#  Author: Laudeci Oliveira <laudeci@gmail.com>
19
 
#  Creation: 16/11/2006
20
 
#  Changed: 
21
 
#  Purpose: Class that will control repositoy downloads
22
 
##
23
 
######################################################
24
 
import gzip
25
 
import re
26
 
(PACKAGE, VERSION, FILENAME, SIZE, DEBFILENAME,REMOTEFILEPATH,SECTION) = range(7)
27
 
class ParseFile:
28
 
    def __init__(self,strParse):
29
 
        self.ParseString = strParse.split('\n')
30
 
        self.Lines = []
31
 
 
32
 
    def Parse(self):
33
 
        LineNumber = -1
34
 
        # this procedure will return a list in the following format
35
 
        # [Package, Version, Filename, Size]
36
 
        Package  = re.compile(r'(Package:\s)(.*)',re.IGNORECASE| re.MULTILINE| re.DOTALL)
37
 
        Version  = re.compile(r'(Version:\s)(.*)',re.IGNORECASE| re.MULTILINE| re.DOTALL)
38
 
        Filename = re.compile(r'(Filename:\s)(.*)',re.IGNORECASE| re.MULTILINE| re.DOTALL)
39
 
        Section = re.compile(r'(Section::\s)(.*)',re.IGNORECASE| re.MULTILINE| re.DOTALL)
40
 
        Size =re.compile(r'(Size:\s)(.*)',re.IGNORECASE| re.MULTILINE| re.DOTALL)
41
 
        
42
 
        if len(self.ParseString) <=0:
43
 
            return []
44
 
    
45
 
        for line in self.ParseString:
46
 
            #get package name
47
 
            match = Package.search(line)
48
 
            if match:
49
 
                #(PACKAGE, VERSION, FILENAME, SIZE, DEBFILENAME,REMOTEFILEPATH,ARCHITECTURE) = range(7)
50
 
                self.Lines.append([match.group(2),'','','','','',''])
51
 
                LineNumber +=1
52
 
    
53
 
            #get package version
54
 
            matchv = Version.search(line)
55
 
            if matchv:
56
 
                self.Lines[LineNumber][1] = matchv.group(2)
57
 
            
58
 
            matcha = Section.search(line)
59
 
            if matcha:
60
 
                self.Lines[LineNumber][6] = matcha.group(2)
61
 
                
62
 
            #get package file
63
 
            matchn = Filename.search(line)
64
 
            if matchn:
65
 
                fullFilePath = matchn.group(2)
66
 
                filename = fullFilePath.split('/')[-1] #filename without path
67
 
                filePath = fullFilePath.replace(filename,'')#PATH without filename
68
 
                
69
 
                self.Lines[LineNumber][2] = fullFilePath
70
 
                self.Lines[LineNumber][4] = filename 
71
 
                self.Lines[LineNumber][5] = filePath 
72
 
            
73
 
            #get package size
74
 
            matchs = Size.search(line)
75
 
            if matchs:
76
 
                self.Lines[LineNumber][3] = matchs.group(2)
77
 
 
78
 
        return self.Lines
79
 
    
80
 
def openGZ(obj):
81
 
    inF = gzip.GzipFile(obj, 'rb')
82
 
    s=inF.read()
83
 
    inF.close()
84
 
    return s