Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Functions | Variables
zip Namespace Reference

Functions

 _zip_dir (path, zip_file, prefix)
 
 add_symlink (zip_file, source, target)
 
 main (args)
 

Variables

 parser = argparse.ArgumentParser(description='This script creates zip files.')
 
 dest
 
 action
 
 help
 
 nargs
 

Function Documentation

◆ _zip_dir()

zip._zip_dir (   path,
  zip_file,
  prefix 
)
protected

Definition at line 15 of file zip.py.

15def _zip_dir(path, zip_file, prefix):
16 path = path.rstrip('/\\')
17 for root, directories, files in os.walk(path):
18 for directory in directories:
19 if os.path.islink(os.path.join(root, directory)):
20 add_symlink(
21 zip_file,
22 os.path.join(root, directory),
23 os.path.join(root.replace(path, prefix), directory),
24 )
25 for file in files:
26 if os.path.islink(os.path.join(root, file)):
27 add_symlink(
28 zip_file, os.path.join(root, file), os.path.join(root.replace(path, prefix), file)
29 )
30 continue
31 zip_file.write(os.path.join(root, file), os.path.join(root.replace(path, prefix), file))
32
33

◆ add_symlink()

zip.add_symlink (   zip_file,
  source,
  target 
)
Adds a symlink to a zip file.

Args:
  zip_file: The ZipFile obj where the symlink will be added.
  source: The full path to the symlink.
  target: The target path for the symlink within the zip file.

Definition at line 34 of file zip.py.

34def add_symlink(zip_file, source, target):
35 """Adds a symlink to a zip file.
36
37 Args:
38 zip_file: The ZipFile obj where the symlink will be added.
39 source: The full path to the symlink.
40 target: The target path for the symlink within the zip file.
41 """
42 zip_info = zipfile.ZipInfo(target)
43 zip_info.create_system = 3 # Unix like system
44 unix_st_mode = (
45 stat.S_IFLNK | stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR | stat.S_IRGRP
46 | stat.S_IWGRP | stat.S_IXGRP | stat.S_IROTH | stat.S_IWOTH | stat.S_IXOTH
47 )
48 zip_info.external_attr = unix_st_mode << 16
49 zip_file.writestr(zip_info, os.readlink(source))
50
51

◆ main()

zip.main (   args)

Definition at line 52 of file zip.py.

52def main(args):
53 zip_file = zipfile.ZipFile(args.output, 'w', zipfile.ZIP_DEFLATED)
54 if args.source_file:
55 with open(args.source_file) as source_file:
56 file_dict_list = json.load(source_file)
57 for file_dict in file_dict_list:
58 if os.path.islink(file_dict['source']):
59 add_symlink(zip_file, file_dict['source'], file_dict['destination'])
60 continue
61 if os.path.isdir(file_dict['source']):
62 _zip_dir(file_dict['source'], zip_file, file_dict['destination'])
63 else:
64 zip_file.write(file_dict['source'], file_dict['destination'])
65 else:
66 for path, archive_name in args.input_pairs:
67 if os.path.islink(path):
68 add_symlink(zip_file, path, archive_name)
69 continue
70 if os.path.isdir(path):
71 _zip_dir(path, zip_file, archive_name)
72 else:
73 zip_file.write(path, archive_name)
74 zip_file.close()
75
76
Definition main.py:1

Variable Documentation

◆ action

zip.action

Definition at line 79 of file zip.py.

◆ dest

zip.dest

Definition at line 79 of file zip.py.

◆ help

zip.help

Definition at line 79 of file zip.py.

◆ nargs

zip.nargs

Definition at line 83 of file zip.py.

◆ parser

zip.parser = argparse.ArgumentParser(description='This script creates zip files.')

Definition at line 78 of file zip.py.