CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
sagemathinc

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

GitHub Repository: sagemathinc/cocalc
Path: blob/master/src/scripts/ensure_file_exists.py
Views: 687
1
#!/usr/bin/python
2
###############################################################################
3
#
4
# CoCalc: Collaborative Calculation
5
#
6
# Copyright (C) 2016, Sagemath Inc.
7
#
8
# This program is free software: you can redistribute it and/or modify
9
# it under the terms of the GNU General Public License as published by
10
# the Free Software Foundation, either version 3 of the License, or
11
# (at your option) any later version.
12
#
13
# This program is distributed in the hope that it will be useful,
14
# but WITHOUT ANY WARRANTY; without even the implied warranty of
15
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
# GNU General Public License for more details.
17
#
18
# You should have received a copy of the GNU General Public License
19
# along with this program. If not, see <http://www.gnu.org/licenses/>.
20
#
21
###############################################################################
22
23
import os, shutil, sys
24
25
if len(sys.argv) != 3:
26
sys.stderr.write(
27
"%s src target\n\n if target doesn't exist, copy src to it and chown target to have permissions of contain dir\n\n"
28
% sys.argv[0])
29
sys.exit(1)
30
31
_, src, target = sys.argv
32
33
if not os.path.exists(target):
34
shutil.copyfile(src, target)
35
s = os.stat(os.path.split(target)[0])
36
os.chown(target, s.st_uid, s.st_gid)
37
38