summaryrefslogtreecommitdiffstats
path: root/external/meta-spdxscanner/recipes-devtools/python/python3-dosocs2/0001-Fix-bugs-because-python-from-2.x-to-3.x.patch
blob: f648d5018755ddd19a1dc4ef368ab5f2e85f9a50 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
From dbea8f1cf03b986ce98d50faa39f8721048b280e Mon Sep 17 00:00:00 2001
From: Lei Maohui <leimaohui@cn.fujitsu.com>
Date: Thu, 26 Oct 2017 16:08:39 +0900
Subject: [PATCH] Fix bugs because python from 2.x to 3.x.

Signed-off-by: Lei Maohui <leimaohui@cn.fujitsu.com>
---
 dosocs2/render.py      |  4 ++--
 dosocs2/scannerbase.py |  6 +++---
 dosocs2/spdxdb.py      |  2 +-
 dosocs2/util.py        | 30 +++++++++++++++---------------
 4 files changed, 21 insertions(+), 21 deletions(-)

diff --git a/dosocs2/render.py b/dosocs2/render.py
index 7118e3d..434bb5b 100644
--- a/dosocs2/render.py
+++ b/dosocs2/render.py
@@ -54,7 +54,7 @@ def get_row(conn, query):
 
 
 def get_rows(conn, query):
-    return list(sorted(dict(**row) for row in conn.execute(query)))
+    return list(dict(**row) for row in conn.execute(query))
 
 
 def render_template(templatefile, context):
@@ -77,7 +77,7 @@ def render_document(conn, docid, template_file):
     query = queries.relationships(document['document_namespace_id'], package['id_string'])
     package['relationships'] = get_rows(conn, query)
     package['files'] = get_rows(conn, queries.documents_files(docid, package['package_id']))
-    for file in sorted(package['files']):
+    for file in package['files']:
         file['license_info'] = get_rows(conn, queries.files_licenses(file['file_id']))
         file['contributors'] = get_rows(conn, queries.file_contributors(file['file_id']))
         file['annotations'] = get_rows(conn, queries.annotations(docid, file['id_string']))
diff --git a/dosocs2/scannerbase.py b/dosocs2/scannerbase.py
index d7a38b6..a54dce7 100644
--- a/dosocs2/scannerbase.py
+++ b/dosocs2/scannerbase.py
@@ -274,8 +274,8 @@ class FileLicenseScanner(Scanner):
 
         Return the new or existing license object in any case.
         '''
-        transtable = string.maketrans('()[]<>', '------')
-        short_name = string.translate(short_name, transtable)
+        transtable = str.maketrans('()[]<>', '------')
+        short_name = str.translate(short_name, transtable)
         existing_license = FileLicenseScanner.lookup_license(conn, short_name)
         if existing_license is not None:
             return existing_license
@@ -311,7 +311,7 @@ class FileLicenseScanner(Scanner):
 
     def store_results(self, processed_files):
         licenses_to_add = []
-        for (file, licenses_extracted) in processed_files.iteritems():
+        for (file, licenses_extracted) in processed_files.items():
             licenses = []
             for license_name in licenses_extracted:
                 license_kwargs = {
diff --git a/dosocs2/spdxdb.py b/dosocs2/spdxdb.py
index a8d3fd6..b8aef5f 100644
--- a/dosocs2/spdxdb.py
+++ b/dosocs2/spdxdb.py
@@ -135,7 +135,7 @@ def register_package(conn, package_root, name=None, version=None, comment=None,
     package['package_id'] = insert(conn, db.packages, package)
     # Create packages_files rows
     row_params = []
-    for (file_path, file_sha256) in hashes.iteritems():
+    for (file_path, file_sha256) in hashes.items():
         fileobj = register_file(conn, file_path, known_sha256=file_sha256)
         package_file_params = {
             'package_id': package['package_id'],
diff --git a/dosocs2/util.py b/dosocs2/util.py
index 5670f67..aba864c 100644
--- a/dosocs2/util.py
+++ b/dosocs2/util.py
@@ -43,23 +43,23 @@ def bool_from_str(s):
 
 def is_source(magic_string):
     return (
-        ' source' in magic_string and ' text' in magic_string or
-        ' script' in magic_string and ' text' in magic_string or
-        ' program' in magic_string and ' text' in magic_string or
-        ' shell script' in magic_string or
-        ' text executable' in magic_string or
-        'HTML' in magic_string and 'text' in magic_string or
-        'XML' in magic_string and 'text' in magic_string
+        b' source' in magic_string and b' text' in magic_string or
+        b' script' in magic_string and b' text' in magic_string or
+        b' program' in magic_string and b' text' in magic_string or
+        b' shell script' in magic_string or
+        b' text executable' in magic_string or
+        b'HTML' in magic_string and b'text' in magic_string or
+        b'XML' in magic_string and b'text' in magic_string
         )
 
 
 def is_binary(magic_string):
     return (
-        ' executable' in magic_string or
-        ' relocatable' in magic_string or
-        ' shared object' in magic_string or
-        ' dynamically linked' in magic_string or
-        ' ar archive' in magic_string
+        b' executable' in magic_string or
+        b' relocatable' in magic_string or
+        b' shared object' in magic_string or
+        b' dynamically linked' in magic_string or
+        b' ar archive' in magic_string
         )
 
 
@@ -70,7 +70,7 @@ def spdx_filetype(filename):
         return 'SOURCE'
     if is_binary(magic_string):
         return 'BINARY'
-    if 'archive' in magic_string:
+    if b'archive' in magic_string:
         return 'ARCHIVE'
     return 'OTHER'
 
@@ -158,7 +158,7 @@ def gen_ver_code(hashes, excluded_hashes=None):
         excluded_hashes = set()
     hashes_less_excluded = (h for h in hashes if h not in excluded_hashes)
     hashblob = ''.join(sorted(hashes_less_excluded))
-    return hashlib.sha256(hashblob).hexdigest()
+    return hashlib.sha256((hashblob).encode('utf-8')).hexdigest()
 
 
 def get_dir_hashes(path, excluded_hashes=None):
@@ -184,7 +184,7 @@ def get_dir_hashes(path, excluded_hashes=None):
         and hashes.get(abspath) not in excluded_hashes
         )
     rel_listing_hashes = (
-        hashlib.sha256(relpath).hexdigest()
+        hashlib.sha256((relpath).encode('utf-8')).hexdigest()
         for relpath in sorted(relative_listing)
         )
     return (gen_ver_code(hashes.values(), excluded_hashes),
-- 
2.7.4