-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcommons.py
47 lines (40 loc) · 1.54 KB
/
commons.py
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
import luigi
import os
import sys
import re
sys.path.append("..")
import cfg
import csv
class commons(luigi.Config):
is_remote = luigi.BoolParameter(default=False)
SSH_HOST = luigi.Parameter(default='134.96.225.222')
SSH_PORT = luigi.Parameter(default='2222')
# remote_path = luigi.Parameter(default='/home/kuznetsov/imd/static_analysis/data')
remote_root = luigi.Parameter()
local_root = cfg.evo_data_folder
permission_mapping = luigi.Parameter() # TODO refactor
hostname = luigi.Parameter()
@staticmethod
def get_apk_data(file_path):
basename = commons().strip_file_name(file_path)
pattern = re.compile(r"(?P<pkg>.+)_(?P<ver>[0-9]+)(_(?P<date>[0-9\-]+))?$") # date can be empty
match = pattern.match(basename)
if match is None:
raise ValueError("Problem with file name: {fn}".format(fn=file_path))
pkg = match.group("pkg")
vercode = match.group("ver")
date = match.group("date")
return pkg, vercode, date
@staticmethod
def get_apk_name(pkg, vercode, date):
return "{pkg}_{vercode}_{date}".format(pkg=pkg, vercode=vercode, date=date)
@staticmethod
def strip_file_name(file_path):
bn = os.path.basename(file_path)
return re.sub('\.(xml|json|apk|txt)$', '', bn)
@staticmethod
def csv_file_to_dict(filename):
with open(filename, 'r') as infile:
reader = csv.reader(infile, delimiter=';')
dictionary = {rows[0]: rows[1] for rows in reader}
return dictionary