Python shutil.copy() Examples
The following are 30 code examples for showing how to use shutil.copy(). These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example.
You may check out the related API usage on the sidebar.
You may also want to check out all available functions/classes of the module
shutil
, or try the search function
.
Example 1
Project: bottle-yang-extractor-validator Author: YangCatalog File: views.py License: BSD 2-Clause "Simplified" License | 7 votes |
def copy_dependencies(f): config_path = '/etc/yangcatalog/yangcatalog.conf' config = ConfigParser.ConfigParser() config._interpolation = ConfigParser.ExtendedInterpolation() config.read(config_path) yang_models = config.get('Directory-Section', 'save-file-dir') tmp = config.get('Directory-Section', 'temp') out = f.getvalue() letters = string.ascii_letters suffix = ''.join(random.choice(letters) for i in range(8)) dep_dir = '{}/yangvalidator-dependencies-{}'.format(tmp, suffix) os.mkdir(dep_dir) dependencies = out.split(':')[1].strip().split(' ') for dep in dependencies: for file in glob.glob(r'{}/{}*.yang'.format(yang_models, dep)): shutil.copy(file, dep_dir) return dep_dir
Example 2
Project: Traffic_sign_detection_YOLO Author: AmeyaWagh File: datasetGenerator.py License: MIT License | 6 votes |
def generateDatasetFiles(self): with open(os.path.join(self.datasetPath,'frameAnnotations.csv')) as csvfile: anotations_list = csvfile.readlines() # print(anotations_list) anotations_list.pop(0) for sample in anotations_list: sample = sample.split(';') # print(sample) self.labels.add(sample[1]) self.generateXML(file=sample[0], label=sample[1], _bndbox={ "xmin": sample[2], "ymin": sample[3], "xmax": sample[4], "ymax": sample[5]}) shutil.copy( os.path.join(self.datasetPath,sample[0]), self.imgPath) self.FileSequence.append(sample[0]) # break
Example 3
Project: StructEngPy Author: zhuoju36 File: db.py License: MIT License | 6 votes |
def open(self,database): """ params: database: str. Database to be opered. The path should be included """ assert(database[-4:]=='.mdo') if not os.path.exists(database): self._create(database) operate_db=database[:-4]+'.op' shutil.copy(database,operate_db) # engine=create_engine('sqlite:///:memory:') engine=create_engine('sqlite:///'+operate_db) #should be run in memory in the future Session=o.sessionmaker(bind=engine) self.session=Session() self.__operate_db=operate_db self.__storage_db=database
Example 4
Project: multibootusb Author: mbusb File: install.py License: GNU General Public License v2.0 | 6 votes |
def copy_iso(src, dst): """ A simple wrapper for copying larger files. This is necessary as shutil copy files is much slower under Windows platform :param src: Path to source file :param dst: Destination directory :return: """ if platform.system() == "Windows": # Note that xcopy asks if the target is a file or a directory when # source filename (or dest filename) contains space(s) and the target # does not exist. assert os.path.exists(dst) subprocess.call(['xcopy', '/Y', src, dst], shell=True) elif platform.system() == "Linux": shutil.copy(src, dst)
Example 5
Project: CAMISIM Author: CAMI-challenge File: strainsimulationwrapper.py License: Apache License 2.0 | 6 votes |
def _prepare_simulation_subfolder(self, directory_strains): """ Create strain directory and copy templates and parameter file into it. @param directory_strains: Directory for the simulated strains @type directory_strains: str | unicode @return: Nothing @rtype: None """ if not os.path.exists(directory_strains): os.mkdir(directory_strains) for filename in self._directory_template_filenames: src = os.path.join(self._directory_template, filename) dst = os.path.join(directory_strains, filename) shutil.copy(src, dst)
Example 6
Project: pruning_yolov3 Author: zbyuan File: datasets.py License: GNU General Public License v3.0 | 6 votes |
def __next__(self): self.count += 1 img0 = self.imgs.copy() if cv2.waitKey(1) == ord('q'): # q to quit cv2.destroyAllWindows() raise StopIteration # Letterbox img = [letterbox(x, new_shape=self.img_size, interp=cv2.INTER_LINEAR)[0] for x in img0] # Stack img = np.stack(img, 0) # Normalize RGB img = img[:, :, :, ::-1].transpose(0, 3, 1, 2) # BGR to RGB img = np.ascontiguousarray(img, dtype=np.float16 if self.half else np.float32) # uint8 to fp16/fp32 img /= 255.0 # 0 - 255 to 0.0 - 1.0 return self.sources, img, img0, None
Example 7
Project: macops Author: google File: can_haz_image.py License: Apache License 2.0 | 6 votes |
def GetBuildPackages(self): """Downloads the packages to be installed.""" package_path = os.path.join(self.cwd, BUILD, 'Packages/') try: os.mkdir(package_path) except OSError: pass catalogs = [os.path.join(self.cwd, 'base%s_new.catalog' % self.os_version), os.path.join(self.cwd, 'thirdparty%s_new.catalog' % self.os_version)] for catalog in catalogs: f = open(catalog, 'r') packages = f.readlines() for line in packages: shutil.copy(os.path.join(TMPDIR, line.split()[0]), os.path.join(package_path, line.split()[0]))
Example 8
Project: bioservices Author: cokelaer File: settings.py License: GNU General Public License v3.0 | 6 votes |
def __init__(self, name=None, default_params={}): """name is going to be the generic name of the config folder e.g., /home/user/.config/<name>/<name>.cfg """ if name is None: raise Exception("Name parameter must be provided") else: # use input parameters self.name = name self._default_params = copy.deepcopy(default_params) self.params = copy.deepcopy(default_params) # useful tool to handle XDG config file, path and parameters self.appdirs = appdirs.AppDirs(self.name) # useful tool to handle the config ini file self.config_parser = DynamicConfigParser() # Now, create the missing directories if needed self.init() # and read the user config file updating params if needed
Example 9
Project: calmjs Author: calmjs File: toolchain.py License: GNU General Public License v2.0 | 6 votes |
def compile_bundle_entry(self, spec, entry): """ Handler for each entry for the bundle method of the compile process. This copies the source file or directory into the build directory. """ modname, source, target, modpath = entry bundled_modpath = {modname: modpath} bundled_target = {modname: target} export_module_name = [] if isfile(source): export_module_name.append(modname) copy_target = join(spec[BUILD_DIR], target) if not exists(dirname(copy_target)): makedirs(dirname(copy_target)) shutil.copy(source, copy_target) elif isdir(source): copy_target = join(spec[BUILD_DIR], modname) shutil.copytree(source, copy_target) return bundled_modpath, bundled_target, export_module_name
Example 10
Project: glazier Author: google File: log_copy.py License: Apache License 2.0 | 6 votes |
def _ShareUpload(self, source_log: Text, share: Text): """Copy the log file to a network file share. Args: source_log: Path to the source log file to be copied. share: The destination share to copy the file to. Raises: LogCopyError: Failure to mount share and copy log. """ creds = LogCopyCredentials() username = creds.GetUsername() password = creds.GetPassword() mapper = drive_map.DriveMap() result = mapper.MapDrive('l:', share, username, password) if result: destination = self._GetLogFileName() try: shutil.copy(source_log, destination) except shutil.Error: raise LogCopyError('Log copy failed.') mapper.UnmapDrive('l:') else: raise LogCopyError('Drive mapping failed.')
Example 11
Project: imgcomp-cvpr Author: fab-jul File: other_codecs.py License: GNU General Public License v3.0 | 6 votes |
def gen_bpg(in_images, out_dir, qs, first_n): if '*' not in in_images: in_images = os.path.join(in_images, '*.png') images = sorted(glob.glob(in_images))[:first_n] assert len(images) > 0, 'No matches for {}'.format(in_images) for img in images: if 'tmp' in img: print('Skipping {}'.format(img)) continue shutil.copy(img, os.path.join(out_dir, os.path.basename(img).replace('.png', '_base.png'))) print(os.path.basename(img)) for q in qs: with remove_file_after(bpg_compress(img, q=q, tmp_dir=out_dir, chroma_fmt='422')) as p: bpp = bpp_of_bpg_image(p) out_png = decode_bpg_to_png(p) out_name = os.path.basename(img).replace('.png', '_{:.4f}.png'.format(bpp)) out_p = os.path.join(out_dir, out_name) print('-> {:.3f}: {}'.format(bpp, out_name)) os.rename(out_png, out_p)
Example 12
Project: L3C-PyTorch Author: fab-jul File: testset.py License: GNU General Public License v3.0 | 6 votes |
def main(): p = argparse.ArgumentParser('Copy deterministic subset of images to another directory.') p.add_argument('root_dir') p.add_argument('max_imgs', type=int) p.add_argument('out_dir') p.add_argument('--dry') p.add_argument('--verbose', '-v', action='store_true') flags = p.parse_args() os.makedirs(flags.out_dir, exist_ok=True) t = Testset(flags.root_dir, flags.max_imgs) def cp(p1, p2): if os.path.isfile(p2): print('Exists, skipping: {}'.format(p2)) return if flags.verbose: print('cp {} -> {}'.format(p1, p2)) if not flags.dry: shutil.copy(p1, p2) for p in t.iter_orig_paths(): cp(p, os.path.join(flags.out_dir, os.path.basename(p)))
Example 13
Project: L3C-PyTorch Author: fab-jul File: import_train_images.py License: GNU General Public License v3.0 | 6 votes |
def process(self, p_in): fn, ext = os.path.splitext(os.path.basename(p_in)) if fn in self.images_cleaned: return 1 if fn in self.images_discarded: return 0 try: im = Image.open(p_in) except OSError as e: print(f'\n*** Error while opening {p_in}: {e}') return 0 im_out = random_resize_or_discard(im, self.min_res) if im_out is not None: p_out = join(self.out_dir_clean, fn + '.png') # Make sure to use .png! im_out.save(p_out) return 1 else: p_out = join(self.out_dir_discard, os.path.basename(p_in)) shutil.copy(p_in, p_out) return 0
Example 14
Project: firmanal Author: kyechou File: extractor.py License: MIT License | 6 votes |
def _check_kernel(self): """ If this file contains a kernel version string, assume it is a kernel. Only Linux kernels are currently extracted. """ if not self.get_kernel_status(): for module in binwalk.scan(self.item, "-y", "kernel", signature=True, quiet=True): for entry in module.results: if "kernel version" in entry.description: self.update_database("kernel_version", entry.description) if "Linux" in entry.description: if self.get_kernel_path(): shutil.copy(self.item, self.get_kernel_path()) else: self.extractor.do_kernel = False self.printf(">>>> %s" % entry.description) return True # VxWorks, etc else: self.printf(">>>> Ignoring: %s" % entry.description) return False return False return False
Example 15
Project: ICDAR-2019-SROIE Author: zzzDavid File: prepare_dataset.py License: MIT License | 6 votes |
def get_data(): filenames = [os.path.splitext(f)[0] for f in glob.glob("original/*.jpg")] jpg_files = [s + ".jpg" for s in filenames] txt_files = [s + ".txt" for s in filenames] for file in txt_files: boxes = [] with open(file, "r", encoding="utf-8", newline="") as lines: for line in csv.reader(lines): boxes.append([line[0], line[1], line[6], line[7]]) with open('mlt/label/' + file.split('/')[1], "w+") as labelFile: wr = csv.writer(labelFile) wr.writerows(boxes) for jpg in jpg_files: shutil.copy(jpg, 'mlt/image/')
Example 16
Project: MaliciousMacroBot Author: egaus File: test_mmbot.py License: MIT License | 6 votes |
def test_init_files_in_directories_retain_contents(): """ Test ensures the mmb_init function can rebuild a model leveraging saved results without reprocessing all samples every time """ # Create model with a few samples resetTest() mmb = MaliciousMacroBot(benign_path, malicious_path, model_path, retain_sample_contents=True) result = mmb.mmb_init_model(modelRebuild=True) shutil.copy(origsample_path, os.path.join(malicious_path, sample)) # Add a file and rebuild mmb = MaliciousMacroBot(benign_path, malicious_path, model_path, retain_sample_contents=True) result = mmb.mmb_init_model(modelRebuild=True) assert result
Example 17
Project: ConvLab Author: ConvLab File: create_delex_data.py License: MIT License | 6 votes |
def loadData(): data_url = "data/multi-woz/data.json" dataset_url = "https://www.repository.cam.ac.uk/bitstream/handle/1810/280608/MULTIWOZ2.zip?sequence=3&isAllowed=y" if not os.path.exists("data"): os.makedirs("data") os.makedirs("data/multi-woz") if not os.path.exists(data_url): print("Downloading and unzipping the MultiWOZ dataset") resp = urllib.urlopen(dataset_url) zip_ref = ZipFile(BytesIO(resp.read())) zip_ref.extractall("data/multi-woz") zip_ref.close() shutil.copy('data/multi-woz/MULTIWOZ2 2/data.json', 'data/multi-woz/') shutil.copy('data/multi-woz/MULTIWOZ2 2/valListFile.json', 'data/multi-woz/') shutil.copy('data/multi-woz/MULTIWOZ2 2/testListFile.json', 'data/multi-woz/') shutil.copy('data/multi-woz/MULTIWOZ2 2/dialogue_acts.json', 'data/multi-woz/')
Example 18
Project: simnibs Author: simnibs File: postinstall_simnibs.py License: GNU General Public License v3.0 | 6 votes |
def setup_gmsh_options(force=False, silent=False): ''' Copies the gmsh_options file to the appropriate place ''' if sys.platform in ['linux', 'darwin']: target = os.path.expanduser('~/.gmsh-options') else: target = os.path.join(os.getenv('APPDATA'), 'gmsh-options') silent = silent and GUI copy = True if os.path.isfile(target): if force: copy = True else: copy = _get_input( 'Found a gmsh configuration file, do you whish to overwite it?', silent) if copy: gmsh_options_path = os.path.join( SIMNIBSDIR, 'resources', 'gmsh-options_simnibsdefault') _copy_and_log(gmsh_options_path, target)
Example 19
Project: exposure Author: yuanming-hu File: net.py License: MIT License | 6 votes |
def draw_value_reward_score(self, img, value, reward, score): img = img.copy() # Average with 0.5 for semi-transparent background img[:14] = img[:14] * 0.5 + 0.25 img[50:] = img[50:] * 0.5 + 0.25 if self.cfg.gan == 'ls': red = -np.tanh(float(score) / 1) * 0.5 + 0.5 else: red = -np.tanh(float(score) / 10.0) * 0.5 + 0.5 top = '%+.2f %+.2f' % (value, reward) cv2.putText(img, top, (3, 7), cv2.FONT_HERSHEY_SIMPLEX, 0.25, (1.0, 1.0 - red, 1.0 - red)) score = '%+.3f' % score cv2.putText(img, score, (10, 60), cv2.FONT_HERSHEY_SIMPLEX, 0.35, (1.0, 1.0 - red, 1.0 - red)) return img
Example 20
Project: exposure Author: yuanming-hu File: pickle_to_tex.py License: MIT License | 6 votes |
def process(filename, id, src): pkl_fn = os.path.join(src, filename) debug_info_list = pickle.load(open(pkl_fn, 'rb')) filename = filename[:-10] target_dir = 'export/{}'.format(id) os.makedirs(target_dir, exist_ok=True) for i in range(NUM_STEPS - 1): shutil.copy(os.path.join(src, filename + '.intermediate%02d.png' % i), os.path.join(target_dir, 'step%d.png' % (i + 1))) shutil.copy(os.path.join(src, filename + '.retouched.png'), os.path.join(target_dir, 'final.png')) shutil.copy(os.path.join(src, filename + '.linear.png'), os.path.join(target_dir, 'input.png')) with open(target_dir + '/steps.tex', 'w') as f: for i in range(NUM_STEPS): debug_info = debug_info_list[i] print( visualize_step(debug_info, 'agent%d' % (i + 1), (4, i * -3)), end=' ', file=f)
Example 21
Project: exposure Author: yuanming-hu File: evaluate.py License: MIT License | 6 votes |
def evaluate(): if len(sys.argv) < 4: print( "Usage: python3 evaluate.py [config suffix] [model name] [image files name1] [image files name2] ..." ) exit(-1) if len(sys.argv) == 4: print( " Note: Process a single image at a time may be inefficient - try multiple inputs)" ) print("(TODO: batch processing when images have the same resolution)") print() print("Initializing...") config_name = sys.argv[1] import shutil shutil.copy('models/%s/%s/scripts/config_%s.py' % (config_name, sys.argv[2], config_name), 'config_tmp.py') cfg = load_config('tmp') cfg.name = sys.argv[1] + '/' + sys.argv[2] net = GAN(cfg, restore=True) net.restore(20000) spec_files = sys.argv[3:] print('processing files {}', spec_files) net.eval(spec_files=spec_files, step_by_step=True)
Example 22
Project: mutatest Author: EvanKepner File: test_all_op_types.py License: MIT License | 5 votes |
def test_all_op_types(monkeypatch, tmp_path): """Test all operation types. This test ensures KeyError does not occur when accessing mutations by type. The test command is fake, so all mutations will survive, but this is designed to ensure the cached mutations happen as intended, not for pytest assessment. """ shutil.copy(HERE / "all_op_types.py", tmp_path) monkeypatch.chdir(tmp_path) cmds = ["mutatest", "-s", "all_op_types.py", "-t", "echo 'fake'", "-n", "500", "-m", "f"] subprocess.run(cmds, capture_output=False)
Example 23
Project: incubator-spot Author: apache File: flow_oa.py License: Apache License 2.0 | 5 votes |
def _add_ipynb(self): if os.path.isdir(self._ipynb_path): self._logger.info("Adding the advanced mode IPython Notebook") shutil.copy("{0}/ipynb_templates/Advanced_Mode_master.ipynb".format(self._scrtip_path),"{0}/Advanced_Mode.ipynb".format(self._ipynb_path)) self._logger.info("Adding threat investigation IPython Notebook") shutil.copy("{0}/ipynb_templates/Threat_Investigation_master.ipynb".format(self._scrtip_path),"{0}/Threat_Investigation.ipynb".format(self._ipynb_path)) else: self._logger.error("There was a problem adding the IPython Notebooks, please check the directory exists.")
Example 24
Project: incubator-spot Author: apache File: proxy_oa.py License: Apache License 2.0 | 5 votes |
def _add_ipynb(self): if os.path.isdir(self._ipynb_path): self._logger.info("Adding advanced mode IPython Notebook") shutil.copy("{0}/ipynb_templates/Advanced_Mode_master.ipynb".format(self._scrtip_path),"{0}/Advanced_Mode.ipynb".format(self._ipynb_path)) self._logger.info("Adding threat investigation IPython Notebook") shutil.copy("{0}/ipynb_templates/Threat_Investigation_master.ipynb".format(self._scrtip_path),"{0}/Threat_Investigation.ipynb".format(self._ipynb_path)) else: self._logger.error("There was a problem adding the IPython Notebooks, please check the directory exists.")
Example 25
Project: incubator-spot Author: apache File: dns_oa.py License: Apache License 2.0 | 5 votes |
def _add_ipynb(self): if os.path.isdir(self._ipynb_path): self._logger.info("Adding advanced mode IPython Notebook") shutil.copy("{0}/ipynb_templates/Advanced_Mode_master.ipynb".format(self._scrtip_path),"{0}/Advanced_Mode.ipynb".format(self._ipynb_path)) self._logger.info("Adding threat investigation IPython Notebook") shutil.copy("{0}/ipynb_templates/Threat_Investigation_master.ipynb".format(self._scrtip_path),"{0}/Threat_Investigation.ipynb".format(self._ipynb_path)) else: self._logger.error("There was a problem adding the IPython Notebooks, please check the directory exists.")
Example 26
Project: vergeml Author: mme File: fashion_mnist.py License: MIT License | 5 votes |
def download(env): """A MNIST-like fashion product database. Fashion-MNIST is a dataset of Zalando's article images— consisting of a training set of 60,000 examples and a test set of 10,000 examples. Each example is a 28x28 grayscale image, associated with a label from 10 classes. We intend Fashion-MNIST to serve as a direct drop-in replacement for the original MNIST dataset for benchmarking machine learning algorithms. It shares the same image size and structure of training and testing splits. Authors: Han Xiao Kashif Rasul Roland Vollgraf See also: Fashion-MNIST: a Novel Image Dataset for Benchmarking Machine Learning Algorithms. arXiv:1708.07747 https://arxiv.org/abs/1708.07747 For more information visit: https://github.com/zalandoresearch/fashion-mnist""" urls = ["http://fashion-mnist.s3-website.eu-central-1.amazonaws.com/train-images-idx3-ubyte.gz", "http://fashion-mnist.s3-website.eu-central-1.amazonaws.com/train-labels-idx1-ubyte.gz", "http://fashion-mnist.s3-website.eu-central-1.amazonaws.com/t10k-images-idx3-ubyte.gz", "http://fashion-mnist.s3-website.eu-central-1.amazonaws.com/t10k-labels-idx1-ubyte.gz"] samples_dir = env.get('base.samples_dir') print("Downloading fashion mnist to {}.".format(samples_dir)) src_dir = download_files(urls, dir=env.get('base.cache_dir')) for file in ("train-images-idx3-ubyte.gz", "train-labels-idx1-ubyte.gz", "t10k-images-idx3-ubyte.gz", "t10k-labels-idx1-ubyte.gz"): shutil.copy(os.path.join(src_dir, file), samples_dir) shutil.rmtree(src_dir) print("Finished downloading fashion mnist.")
Example 27
Project: vergeml Author: mme File: svhn.py License: MIT License | 5 votes |
def download(env): """The Street View House Numbers (SVHN) Dataset. SVHN is a real-world image dataset for developing machine learning and object recognition algorithms with minimal requirement on data preprocessing and formatting. It can be seen as similar in flavor to MNIST (e.g., the images are of small cropped digits), but incorporates an order of magnitude more labeled data (over 600,000 digit images) and comes from a significantly harder, unsolved, real world problem (recognizing digits and numbers in natural scene images). SVHN is obtained from house numbers in Google Street View images. Authors: Yuval Netzer, Tao Wang, Adam Coates, Alessandro Bissacco, Bo Wu, Andrew Y. Ng Reading Digits in Natural Images with Unsupervised Feature Learning NIPS Workshop on Deep Learning and Unsupervised Feature Learning 2011. http://ufldl.stanford.edu/housenumbers/nips2011_housenumbers.pdf For more information visit: http://ufldl.stanford.edu/housenumbers/""" urls = ["http://ufldl.stanford.edu/housenumbers/train_32x32.mat", "http://ufldl.stanford.edu/housenumbers/test_32x32.mat"] samples_dir = env.get('base.samples_dir') print("Downloading SVHN to {}.".format(samples_dir)) src_dir = download_files(urls, dir=env.get('base.cache_dir')) for file in ("train_32x32.mat", "test_32x32.mat", ): shutil.copy(os.path.join(src_dir, file), samples_dir) shutil.rmtree(src_dir) print("Finished downloading SVHN.")
Example 28
Project: vergeml Author: mme File: mnist.py License: MIT License | 5 votes |
def download(env): """The MNIST database of handwritten digits. The MNIST database of handwritten digits has a training set of 60,000 examples, and a test set of 10,000 examples. It is a subset of a larger set available from NIST. The digits have been size-normalized and centered in a fixed-size image. It is a good database for people who want to try learning techniques and pattern recognition methods on real-world data while spending minimal efforts on preprocessing and formatting. Authors: Yann LeCun, Courant Institute, NYU Corinna Cortes, Google Labs, New York Christopher J.C. Burges, Microsoft Research, Redmond For more information visit:http://yann.lecun.com/exdb/mnist/""" urls = ["http://yann.lecun.com/exdb/mnist/train-images-idx3-ubyte.gz", "http://yann.lecun.com/exdb/mnist/train-labels-idx1-ubyte.gz", "http://yann.lecun.com/exdb/mnist/t10k-images-idx3-ubyte.gz", "http://yann.lecun.com/exdb/mnist/t10k-labels-idx1-ubyte.gz"] samples_dir = env.get('base.samples_dir') print("Downloading mnist to {}.".format(samples_dir)) src_dir = download_files(urls, dir=env.get('base.cache_dir')) for file in ("train-images-idx3-ubyte.gz", "train-labels-idx1-ubyte.gz", "t10k-images-idx3-ubyte.gz", "t10k-labels-idx1-ubyte.gz"): shutil.copy(os.path.join(src_dir, file), samples_dir) shutil.rmtree(src_dir) print("Finished downloading mnist.")
Example 29
Project: aegea Author: kislyuk File: __init__.py License: Apache License 2.0 | 5 votes |
def initialize(): global config, parser from .util.printing import BOLD, RED, ENDC config = AegeaConfig(__name__, use_yaml=True, save_on_exit=False) if not os.path.exists(config.config_files[2]): config_dir = os.path.dirname(os.path.abspath(config.config_files[2])) try: os.makedirs(config_dir) except OSError as e: if not (e.errno == errno.EEXIST and os.path.isdir(config_dir)): raise shutil.copy(os.path.join(os.path.dirname(__file__), "user_config.yml"), config.config_files[2]) logger.info("Wrote new config file %s with default values", config.config_files[2]) config = AegeaConfig(__name__, use_yaml=True, save_on_exit=False) parser = argparse.ArgumentParser( description="{}: {}".format(BOLD() + RED() + __name__.capitalize() + ENDC(), fill(__doc__.strip())), formatter_class=AegeaHelpFormatter ) parser.add_argument("--version", action="version", version="%(prog)s {}\n{} {}\n{}".format( __version__, platform.python_implementation(), platform.python_version(), platform.platform() )) def help(args): parser.print_help() register_parser(help)
Example 30
Project: wechat-alfred-workflow Author: TKkk-iOSer File: notify.py License: MIT License | 5 votes |
def notify(title='', text='', sound=None): """Post notification via Notify.app helper. Args: title (str, optional): Notification title. text (str, optional): Notification body text. sound (str, optional): Name of sound to play. Raises: ValueError: Raised if both ``title`` and ``text`` are empty. Returns: bool: ``True`` if notification was posted, else ``False``. """ if title == text == '': raise ValueError('Empty notification') sound = validate_sound(sound) or '' n = notifier_program() if not os.path.exists(n): install_notifier() env = os.environ.copy() enc = 'utf-8' env['NOTIFY_TITLE'] = title.encode(enc) env['NOTIFY_MESSAGE'] = text.encode(enc) env['NOTIFY_SOUND'] = sound.encode(enc) cmd = [n] retcode = subprocess.call(cmd, env=env) if retcode == 0: return True log().error('Notify.app exited with status {0}.'.format(retcode)) return False