5 valid_control_fields
= ["Package", "Version", "Depends", "Provides",\
6 "Replaces", "Conflicts", "Suggests", "Recommends",\
7 "Section", "Architecture", "Maintainer", "MD5Sum",\
8 "Size", "InstalledSize", "Filename", "Source",\
9 "Description", "OE", "Homepage", "Priority",\
12 def __init__(self
, **control
):
13 for k
in control
.keys():
14 if k
not in self
.valid_control_fields
:
15 raise Exception("Invalid control field: "
17 self
.control
= control
19 def write(self
, tar_not_ar
=False, data_files
=None):
20 filename
= "{Package}_{Version}_{Architecture}.opk"\
21 .format(**self
.control
)
22 if os
.path
.exists(filename
):
24 if os
.path
.exists("control"):
26 if os
.path
.exists("control.tar.gz"):
27 os
.unlink("control.tar.gz")
28 if os
.path
.exists("data.tar.gz"):
29 os
.unlink("data.tar.gz")
31 f
= open("control", "w")
32 for k
in self
.control
.keys():
33 f
.write("{}: {}\n".format(k
, self
.control
[k
]))
36 tar
= tarfile
.open("control.tar.gz", "w:gz")
40 tar
= tarfile
.open("data.tar.gz", "w:gz")
48 tar
= tarfile
.open(filename
, "w:gz")
49 tar
.add("control.tar.gz")
50 tar
.add("data.tar.gz")
53 os
.system("ar q {} control.tar.gz data.tar.gz \
54 2>/dev/null".format(filename
))
57 os
.unlink("control.tar.gz")
58 os
.unlink("data.tar.gz")
64 def add(self
, **control
):
65 self
.opk_list
.append(Opk(**control
))
67 def write_opk(self
, tar_not_ar
=False):
68 for o
in self
.opk_list
:
71 def write_list(self
, filename
="Packages"):
72 f
= open(filename
, "w")
73 for opk
in self
.opk_list
:
74 for k
in opk
.control
.keys():
75 f
.write("{}: {}\n".format(k
, opk
.control
[k
]))
76 f
.write("Filename: {Package}_{Version}_{Architecture}"
77 ".opk\n".format(**opk
.control
))
84 Initialisation and sanity checking.
87 if not os
.access(cfg
.opkgcl
, os
.X_OK
):
88 print("Cannot exec {}".format(cfg
.opkgcl
))
93 os
.system("rm -fr {}".format(cfg
.offline_root
))
95 os
.makedirs("{}/usr/lib/opkg".format(cfg
.offline_root
))
96 os
.makedirs("{}/etc/opkg".format(cfg
.offline_root
))
98 f
= open("{}/etc/opkg/opkg.conf".format(cfg
.offline_root
), "w")
99 f
.write("arch all 1\n")
100 f
.write("src test file:{}\n".format(cfg
.opkdir
))