bbarchivist.bbconstants.Datafile.__init__()   A
last analyzed

Complexity

Conditions 1

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 6
nop 4
dl 0
loc 9
ccs 6
cts 6
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
#!/usr/bin/env python3
2 5
"""This module is used to define constants for the program."""
3
4 5
import os.path  # for producing cap location constant
5 5
import sys
6
7 5
from ._version import get_versions
8
9 5
__author__ = "Thurask"
10 5
__license__ = "WTFPL v2"
11 5
__copyright__ = "2015-2019 Thurask"
12
13
14 5
class Datafile(object):
15
    """
16
    Structure for information about a data file included with this app.
17
    """
18
19 5
    def __init__(self, version, datatype, size):
20
        """
21
        Populate variables.
22
        """
23 5
        self.version = version
24 5
        self.name = datatype
25 5
        self.filename = "{0}-{1}.dat".format(datatype, version)
26 5
        self.location = os.path.join(DIRECTORY, "datfiles", self.filename)
27 5
        self.size = size
28
29
30 5
def frozen_versions():
31
    """
32
    Version grabbing when frozen with cx_Freeze.
33
    """
34 5
    with open("longversion.txt", "r") as longv:
35 5
        data = longv.read().split("\n")
36 5
        ver = data[0].split("-")
37
    #: App version.
38 5
    version = ver[0]
39
    #: If we're in a development build.
40 5
    dirty = "+devel" if data[0] != version else ""
41
    #: Git commit hash.
42 5
    commithash = ver[1]
43
    #: App version, tag + commits.
44 5
    longversion = "-".join(ver)
45
    #: Git commit timestamp.
46 5
    commitdate = data[1]
47 5
    return version, dirty, commithash, longversion, commitdate
48
49
50 5
if not getattr(sys, 'frozen', False):  # regular
51
    #: App version.
52 5
    VERSION = get_versions()["version"].split("-")[0]
53
    #: If we're in a development build.
54 5
    DIRTY = "+devel" if get_versions()["version"] != VERSION else ""
55
    #: Git commit hash.
56 5
    COMMITHASH = "g{0}".format(get_versions()["full-revisionid"][0:7])
57
    #: App version, tag + commits.
58 5
    LONGVERSION = "-".join((VERSION + DIRTY, COMMITHASH))
59
    #: Git commit timestamp.
60 5
    COMMITDATE = get_versions()["date"]
61
else:  # pyinstaller support
62
    VERSION, DIRTY, COMMITHASH, LONGVERSION, COMMITDATE = frozen_versions()
63
#: File location.
64 5
LOCATION = os.path.abspath(__file__)
65
#: File folder.
66 5
DIRECTORY = os.path.dirname(LOCATION)
67
#: CAP
68 5
CAP = Datafile("3.11.0.27", "cap", 9252412)
69
#: CFP
70 5
CFP = Datafile("3.10.0.57", "cfp", 16361984)
71
#: flashall.bat.dat
72 5
FLASHBAT = Datafile("5", "flashall.bat", 2930)
73
#: flashall.sh.dat
74 5
FLASHSH = Datafile("5", "flashall.sh", 2932)
75
#: flashallbbf.bat.dat
76 5
FLASHBATBBF = Datafile("5", "flashallbbf.bat", 3689)
77
#: flashallbbf.sh.dat
78 5
FLASHSHBBF = Datafile("5", "flashallbbf.sh", 3526)
79
#: JSON storage directory.
80 5
JSONDIR = os.path.join(DIRECTORY, "json")
81
#: Lookup server list.
82 5
SERVERS = {
83
    "p": "https://cs.sl.blackberry.com/cse/srVersionLookup/2.0.0/",
84
    "b1": "https://beta.sl.eval.blackberry.com/slscse/srVersionLookup/2.0.0/",
85
    "b2": "https://beta2.sl.eval.blackberry.com/slscse/srVersionLookup/2.0.0/",
86
    "a1": "https://alpha.sl.eval.blackberry.com/slscse/srVersionLookup/2.0.0/",
87
    "a2": "https://alpha2.sl.eval.blackberry.com/slscse/srVersionLookup/2.0.0/"
88
}
89
#: Archive files.
90 5
ARCS = (".7z", ".tar.xz", ".tar.bz2", ".tar.gz", ".tar", ".zip", ".txz", ".tbz", ".tgz", ".bar")
91
#: Archive files plus executables.
92 5
ARCSPLUS = (".7z", ".tar.xz", ".tar.bz2", ".tar.gz", ".zip", ".tar", ".exe")
93
#: Compression methods.
94 5
METHODS = ("7z", "tbz", "tgz", "zip", "txz", "tar")
95
#: Autoloader/archive filename beginnings.
96 5
PREFIXES = ("Q10", "Z10", "Z30", "Z3", "Passport")
97
#: Support files.
98 5
SUPPS = (".asc", ".cksum")
99
#: Devices.
100 5
DEVICES = (
101
    "STL100-1",
102
    "STL100-2/3/P9982",
103
    "STL100-4",
104
    "Q10/Q5/P9983",
105
    "Z30/CLASSIC/LEAP",
106
    "Z3",
107
    "PASSPORT")
108
#: Master servers.
109 5
TCLMASTERS = (
110
    "g2master-us-east.tctmobile.com",
111
    "g2master-us-west.tctmobile.com",
112
    "g2master-eu-west.tctmobile.com",
113
    "g2master-ap-south.tctmobile.com",
114
    "g2master-ap-north.tctmobile.com",
115
    "g2master-sa-east.tctmobile.com")
116