def create_deployable_zip(self, path_for_zip, sources_path=None, extra_files_paths=None): LOGGER.info('Creating zip package for {} project'.format(self.name)) if not os.path.exists(path_for_zip): os.makedirs(path_for_zip) project_files_path = sources_path if sources_path else self._local_sources_path try: for extra_file_path in extra_files_paths: shutil.copyfile(extra_file_path, os.path.join(project_files_path, ntpath.basename(extra_file_path))) if ntpath.basename(extra_file_path) == 'manifest.yml': app_manifest_path = os.path.join(project_files_path, ntpath.basename(extra_file_path)) with open(app_manifest_path, 'r') as f_stream: manifest_yml = yaml.load(f_stream) manifest_yml['applications'][0]['env']['VERSION'] = self._version_in_manifest with open(app_manifest_path, 'w') as f_stream: f_stream.write(yaml.safe_dump(manifest_yml)) except Exception as e: LOGGER.error('Cannot add extra files to {} project zip package'.format(self.name)) raise e path_for_zip = os.path.join(path_for_zip, self.zip_name + '.zip') if self.zip_name else os.path.join(path_for_zip, self.name + '.zip') try: deployable_zip = zipfile.ZipFile(path_for_zip, 'w') for root, dirs, files in os.walk(project_files_path): for file in files: deployable_zip.write(os.path.join(os.path.relpath(root, PLATFORM_PARENT_PATH), file), os.path.join(os.path.relpath(root, os.path.join(PLATFORM_PARENT_PATH, self.name)), file)) deployable_zip.close() except Exception as e: LOGGER.error('Cannot create zip package for {}'.format(self.name)) raise e LOGGER.info("Package for {} has been created".format(self.name))
def _download_tar_file(self, tar_name, version, dest_tar_path): LOGGER.info('Downloading {} in version {} for {} project'.format( tar_name, version, self.name)) self._local_tar_path = dest_tar_path if version.lower() == LATEST_ATK_VERSION: self._version_in_manifest = self._versions_catalog[ LATEST_ATK_VERSION]['release'] catalog_name_in_path = LATEST_ATK_VERSION else: self._version_in_manifest = version catalog_name_in_path = self._get_catalog_name_by_release_number( version) download_url = os.path.join(self.url, catalog_name_in_path, 'binaries', tar_name) try: response = requests.get(download_url) with open(dest_tar_path, 'wb') as tar: tar.write(response.content) except requests.exceptions.RequestException as e: LOGGER.error( 'Cannot download {} tar archive for {} project.'.format( tar_name, self.name)) raise e except IOError as e: LOGGER.error( 'Cannot save {} tar archive on your hard disk.'.format( tar_name)) raise e LOGGER.info( 'Tar archive for {} app from {} in version {} has been downloaded'. format(self.name, download_url, version))
def download_project_sources(self, snapshot=None, url=None): self.snapshot = self.snapshot if self.snapshot else snapshot self.url = self.url if self.url else url with open(self.build_log_path, 'a') as build_log, \ open(self.err_log_path, 'a') as err_log: if os.path.exists(self.sources_path): LOGGER.info('Updating sources for {} project'.format(self.name)) try: subprocess.check_call(['git', 'checkout', 'master'], cwd=self.sources_path, stdout=build_log, stderr=err_log) subprocess.check_call(['git', 'pull'], cwd=self.sources_path, stdout=build_log, stderr=err_log) except Exception as e: LOGGER.error('Cannot update sources for {} project'.format(self.name)) raise e LOGGER.info('Sources for {} project has been updated'.format(self.name)) else: LOGGER.info('Downloading {} project sources'.format(self.name)) try: subprocess.check_call(['git', 'clone', self.url], cwd=PLATFORM_PARENT_PATH, stdout=build_log, stderr=err_log) except Exception as e: LOGGER.error('Cannot download sources for {} project'.format(self.name)) raise e LOGGER.info('Sources for {} project has been downloaded'.format(self.name)) if self.snapshot: LOGGER.info('Setting release tag {} for {} project sources'.format(self.snapshot, self.name)) try: subprocess.check_call(['git', 'checkout', self.snapshot], cwd=self.sources_path, stdout=build_log, stderr=err_log) except Exception: LOGGER.warning('Cannot set release tag {} for {} project sources. Using "master" branch.'.format(self.snapshot, self.name)) self.ref = subprocess.check_output(['git', 'rev-parse', 'HEAD'], cwd=self.sources_path).rstrip()
def build(self): LOGGER.info("Building {} project using godep".format(self.name)) with open(self.build_log_path, "a") as build_log, open(self.err_log_path, "a") as err_log: try: subprocess.check_call( ["godep", "go", "build", "./..."], cwd=self.sources_path, stdout=build_log, stderr=err_log ) except Exception as e: LOGGER.error("Cannot build {} project using godep".format(self.name)) raise e LOGGER.info("Building {} project using godep has been finished".format(self.name))
def build(self): LOGGER.info('Building %s project', self.name) with open(self.build_log_path, 'a') as build_log, \ open(self.err_log_path, 'a') as err_log: try: subprocess.check_call(['sh', 'pack.sh'], cwd=self.sources_path, stdout=build_log, stderr=err_log) except Exception as e: LOGGER.error('Cannot build {} project'.format(self.name)) raise e LOGGER.info('Building {} project has been finished'.format(self.name))
def check_menu(self,m): strSql = "select * from group_menu a left join user_info b on a.group_code = b.type where b.user_code='admin' and menu_code='"+m+"'" LOGGER.info("----------check_menu----------"+strSql) menus = self.db.get(strSql) self.db.close() if not menus: self.render("login.html", message="无权限访问") return None return "OK"
def download_release_zip(self, dest_path): if not self.url: LOGGER.error('Not specified release url for %s', self.name) raise 'Not specified release url for {}'.format(self.name) LOGGER.info('Downloading release package for %s from %s', self.name, self.url) with open(self.build_log_path, 'a') as build_log, \ open(self.err_log_path, 'a') as err_log: try: subprocess.check_call(['wget', '-O', os.path.join(dest_path, '{}.zip'.format(self.name)), self.url], stdout=build_log, stderr=err_log) except Exception as e: LOGGER.error('Cannot download release package for %s project', self.name) raise e LOGGER.info('Release package has been downloaded for %s project', self.name)
def create_deployable_zip(self, path_for_zip, sources_path=None, extra_files_paths=None): LOGGER.info('Creating zip package for {} project'.format(self.name)) if not os.path.exists(path_for_zip): os.makedirs(path_for_zip) project_files_path = sources_path if sources_path else self._local_sources_path try: for extra_file_path in extra_files_paths: shutil.copyfile( extra_file_path, os.path.join(project_files_path, ntpath.basename(extra_file_path))) if ntpath.basename(extra_file_path) == 'manifest.yml': app_manifest_path = os.path.join( project_files_path, ntpath.basename(extra_file_path)) with open(app_manifest_path, 'r') as f_stream: manifest_yml = yaml.load(f_stream) manifest_yml['applications'][0]['env'][ 'VERSION'] = self._version_in_manifest with open(app_manifest_path, 'w') as f_stream: f_stream.write(yaml.safe_dump(manifest_yml)) except Exception as e: LOGGER.error( 'Cannot add extra files to {} project zip package'.format( self.name)) raise e path_for_zip = os.path.join(path_for_zip, self.zip_name + '.zip') if self.zip_name else os.path.join( path_for_zip, self.name + '.zip') try: deployable_zip = zipfile.ZipFile(path_for_zip, 'w') for root, dirs, files in os.walk(project_files_path): for file in files: deployable_zip.write( os.path.join( os.path.relpath(root, PLATFORM_PARENT_PATH), file), os.path.join( os.path.relpath( root, os.path.join(PLATFORM_PARENT_PATH, self.name)), file)) deployable_zip.close() except Exception as e: LOGGER.error('Cannot create zip package for {}'.format(self.name)) raise e LOGGER.info("Package for {} has been created".format(self.name))
def build(self): LOGGER.info('Building {} project using godep'.format(self.name)) with open(self.build_log_path, 'a') as build_log, \ open(self.err_log_path, 'a') as err_log: try: subprocess.check_call(['godep', 'go', 'build', './...'], cwd=self.sources_path, stdout=build_log, stderr=err_log) except Exception as e: LOGGER.error('Cannot build {} project using godep'.format( self.name)) raise e LOGGER.info('Building {} project using godep has been finished'.format( self.name))
def download_release_zip(self, dest_path): if not self.url: LOGGER.error('Not specified release url for %s', self.name) raise 'Not specified release url for {}'.format(self.name) LOGGER.info('Downloading release package for %s from %s', self.name, self.url) with open(self.build_log_path, 'a') as build_log, \ open(self.err_log_path, 'a') as err_log: try: subprocess.check_call([ 'wget', '-O', os.path.join(dest_path, '{}.zip'.format(self.name)), self.url ], stdout=build_log, stderr=err_log) except Exception as e: LOGGER.error('Cannot download release package for %s project', self.name) raise e LOGGER.info('Release package has been downloaded for %s project', self.name)
def _download_tar_file(self, tar_name, version, dest_tar_path): LOGGER.info('Downloading {} in version {} for {} project'.format(tar_name, version, self.name)) self._local_tar_path = dest_tar_path if version.lower() == LATEST_ATK_VERSION: self._version_in_manifest = self._versions_catalog[LATEST_ATK_VERSION]['release'] catalog_name_in_path = LATEST_ATK_VERSION else: self._version_in_manifest = version catalog_name_in_path = self._get_catalog_name_by_release_number(version) download_url = os.path.join(self.url, catalog_name_in_path, 'binaries', tar_name) try: response = requests.get(download_url) with open(dest_tar_path, 'wb') as tar: tar.write(response.content) except requests.exceptions.RequestException as e: LOGGER.error('Cannot download {} tar archive for {} project.'.format(tar_name, self.name)) raise e except IOError as e: LOGGER.error('Cannot save {} tar archive on your hard disk.'.format(tar_name)) raise e LOGGER.info('Tar archive for {} app from {} in version {} has been downloaded' .format(self.name, download_url, version))
def create_zip_package(self, dest_path, zip_name=None, zip_items=None): zip_name = zip_name if zip_name else self.zip_name LOGGER.info('Creating {} package for {} project'.format(zip_name, self.name)) try: if not os.path.exists(dest_path): os.makedirs(dest_path) if os.path.exists(os.path.join(dest_path, zip_name)): os.remove(os.path.join(dest_path, zip_name)) zip_package = zipfile.ZipFile(os.path.join(dest_path, zip_name), 'w') zip_items = zip_items if zip_items else self.zip_items if zip_items: zip_items_abs_paths = [] for item in zip_items: zip_items_abs_paths.append(os.path.join(self.sources_path, item)) for item in zip_items_abs_paths: if os.path.isdir(item): for root, dirs, files in os.walk(item): for file in files: if os.path.islink(os.path.join(root, file)): link_dest = os.readlink(os.path.join(root, file)) attr = zipfile.ZipInfo() attr.filename = os.path.relpath(os.path.join(root, file), self.sources_path) attr.create_system = 3 # local system code attr.external_attr = 2716663808L # symlink magic number zip_package.writestr(attr, link_dest) else: zip_package.write(os.path.join(root, file), os.path.relpath(os.path.join(root, file), self.sources_path)) else: zip_package.write(item, os.path.relpath(item, self.sources_path)) zip_package.close() except Exception as e: LOGGER.error('Cannot create zip package {} for {} project'.format(zip_name, self.name)) raise e LOGGER.info('Package for {} project has been created'.format(self.name))
def main(): LOGGER.info("Start....") tornado.options.parse_command_line() http_server = tornado.httpserver.HTTPServer(Application()) http_server.listen(options.port) tornado.ioloop.IOLoop.instance().start()
#_*_ coding: utf-8 _*_ """Move all done cards to archive list in prior sprint board. Create new sprint board and move necessary lists from prior board to new board""" import sys sys.path.append('./lib') from lib.logger import LOGGER from lib.config import DOTTED_LINE, TEAM_INFO, DONE_LIST_NAME, ADMIN_USERS, BOARD_LISTS from lib.utils import compute_sprint_n, get_board_name, get_board_id, get_list_id, \ get_the_number_of_card, create_list, move_all_cards, create_board, \ get_labels_data, update_board_label, update_board_member, move_list, \ get_members_data, get_archive_name LOGGER.debug(DOTTED_LINE) LOGGER.info("Start creating new Sprint board for each team") for team in TEAM_INFO: team_info = TEAM_INFO[team] organ_name = team_info['organ_name'] start_ym = team_info['start_ym'] sprint_n = compute_sprint_n(start_ym) board_name = get_board_name(sprint_n, last_month=True) bid = get_board_id(organ_name, board_name) if bid: # move done cards in last month board done_list_id = get_list_id(bid, DONE_LIST_NAME) if done_list_id: n_card = get_the_number_of_card(done_list_id)
def __setitem__(self, index, value): """Override [i] = foo.""" LOGGER.info("Setting LED %s to %s", index, value) super().__setitem__(index, value)
#_*_ coding: utf-8 _*_ """Move all cards from done list to archive list""" import sys sys.path.append('./lib') from lib.config import DOTTED_LINE, TEAM_INFO, DONE_LIST_NAME from lib.logger import LOGGER from lib.utils import get_board_name, get_board_id, get_list_id, get_the_number_of_card, \ create_list, get_archive_name, move_all_cards, compute_sprint_n LOGGER.debug(DOTTED_LINE) LOGGER.info("Start moving done-list cards to archive-list") for team in TEAM_INFO: team_info = TEAM_INFO[team] start_ym = team_info['start_ym'] organ_name = team_info['organ_name'] sprint_n = compute_sprint_n(start_ym) board_name = get_board_name(sprint_n) bid = get_board_id(organ_name, board_name) if bid: done_list_id = get_list_id(bid, DONE_LIST_NAME) n_card = get_the_number_of_card(done_list_id) if done_list_id and n_card > 0: archive_list_name = get_archive_name() archive_list_id, existance = create_list(bid, archive_list_name) if existance: LOGGER.info("List(" + archive_list_name + ") is already in " + board_name) else:
def fill(self, colour): """Pretend to fill the pixels.""" LOGGER.info("Filling with %s", colour) for index, _ in enumerate(self): self[index] = colour