Skip to content

Jpegphoto2 #45

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions createuserpkg
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ from locallibs import kcpassword
from locallibs import shadowhash
from locallibs import userplist
from locallibs import userpkg
from locallibs import jpegphoto


def main():
Expand Down Expand Up @@ -62,6 +63,9 @@ def main():
optional_user_options.add_option(
'--hint', help='User password hint. Optional.')

optional_user_options.add_option(
'--jpegphoto', help='Path to JPEG photo that contains a profile picture. Image should be square and recommended 512px x 512px and JPEG (RGB). Optional.')

optional_user_options.add_option(
'--home', '-H', help='Path to user home directory. Optional.')
optional_user_options.add_option(
Expand Down Expand Up @@ -107,6 +111,7 @@ def main():
print >> sys.stderr, "Password mismatch!"
exit(-1)


# make user plist
user_data = {'name': options.name,
'uid': options.uid,
Expand All @@ -126,6 +131,11 @@ def main():
if options.hint:
user_data['hint'] = options.hint

if options.jpegphoto:
jpeg_data=jpegphoto.jpeg_photo_from_file(options.jpegphoto)
if (len(jpeg_data)>0):
user_data['image_data'] = jpeg_data

user_plist = userplist.generate(user_data)


Expand Down
28 changes: 28 additions & 0 deletions locallibs/jpegphoto.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Copyright 2019 Timothy Perfitt.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

'''Functions for generating JPEGPhoto'''


import os

def jpeg_photo_from_file(file_path):
'''Read in a file and return binary data'''

photo_data=buffer("")
if os.path.exists(file_path):
with open(file_path,'rb') as photo_file:
photo_data=buffer(photo_file.read())

return photo_data