Repository navigation
Expand file tree
/
Copy pathbuild_dropbox.py
More file actions
53 lines (40 loc) · 1.61 KB
/
Copy pathbuild_dropbox.py
File metadata and controls
53 lines (40 loc) · 1.61 KB
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
import base64
import os
import re
import sys
def replace_many(src2dest, buf):
src_re = re.compile("|".join(re.escape(word) for word in src2dest))
def replace_repl(mo):
return src2dest[mo.group()]
return src_re.sub(replace_repl, buf)
def get_base64_image_data(filepath):
# Load image and convert to base64 string
if not os.path.exists(filepath):
raise FileNotFoundError(f"Image not found: {filepath}")
with open(filepath, "rb") as f:
data = f.read()
# Encode image binary to base64 string literal
return base64.b64encode(data).decode("ascii")
if __name__ == "__main__":
try:
print(f"Current working directory: {os.getcwd()}", file=sys.stderr)
icon64_path = "data/icons/hicolor/64x64/apps/dropbox.png"
icon16_path = "data/icons/hicolor/16x16/apps/dropbox.png"
image64_data = get_base64_image_data(icon64_path)
image16_data = get_base64_image_data(icon16_path)
# Create simple placeholder strings that the app consuming this must decode if needed
src2dest = {
"@PACKAGE_VERSION@": sys.argv[1],
"@DESKTOP_FILE_DIR@": sys.argv[2],
"@IMAGEDATA64@": repr(
image64_data
), # Use repr() to properly escape the string
"@IMAGEDATA16@": repr(
image16_data
), # Use repr() to properly escape the string
}
buf = sys.stdin.read()
sys.stdout.write(replace_many(src2dest, buf))
except Exception as e:
print(f"Error in build_dropbox.py: {str(e)}", file=sys.stderr)
sys.exit(1)