Skip to content

Do not error if the labscript suite profile dir exists. #38

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

Merged
Merged
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
25 changes: 20 additions & 5 deletions labscript_profile/create.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
import os
import shutil
import configparser
from pathlib import Path
from labscript_profile import LABSCRIPT_SUITE_PROFILE, default_labconfig_path


_here = os.path.dirname(os.path.abspath(__file__))
DEFAULT_PROFILE_CONTENTS = os.path.join(_here, 'default_profile')

Expand All @@ -30,14 +30,29 @@ def make_labconfig_file():
config.set('programs', 'text_editor_arguments', '-a TextEdit {file}')
if sys.platform != 'win32':
config.set('programs', 'hdf5_viewer', 'hdfview')
config.set('DEFAULT', 'shared_drive', '$HOME/labscript_shared')
config.set('DEFAULT', 'shared_drive', str(Path.home() / ' labscript_shared'))

with open(target_path, 'w') as f:
config.write(f)


def create_profile():
if os.path.exists(LABSCRIPT_SUITE_PROFILE):
raise FileExistsError(LABSCRIPT_SUITE_PROFILE)
shutil.copytree(DEFAULT_PROFILE_CONTENTS, LABSCRIPT_SUITE_PROFILE)
src = Path(DEFAULT_PROFILE_CONTENTS)
dest = Path(LABSCRIPT_SUITE_PROFILE)
# Profile directory may exist already, but we will error if it contains any of the
# files or directories we want to copy into it:
os.makedirs(dest, exist_ok=True)
# Preferable to raise errors if anything exists before copying anything, rather than
# do a partial copy before hitting an error:
for src_file in src.iterdir():
dest_file = dest / src_file.name
if dest_file.exists():
raise FileExistsError(dest_file)
for src_file in src.iterdir():
dest_file = dest / src_file.name
if src_file.is_dir():
shutil.copytree(src_file, dest_file)
else:
shutil.copy2(src_file, dest_file)

make_labconfig_file()
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy