Add pkg rsc slice tool from tizen_2.4 97/70097/3 accepted/tizen/common/20160520.171030 accepted/tizen/ivi/20160520.081050 accepted/tizen/mobile/20160520.080912 accepted/tizen/tv/20160520.081008 accepted/tizen/wearable/20160520.080929 submit/tizen/20160520.002716
authorJunghyun Yeon <jungh.yeon@samsung.com>
Wed, 18 May 2016 05:45:01 +0000 (14:45 +0900)
committerJunghyun Yeon <jungh.yeon@samsung.com>
Thu, 19 May 2016 11:09:34 +0000 (20:09 +0900)
Migrate rsc-slice tool from tizen_2.4

Change-Id: Ibd4c2e335109086032ad41260f71fe9b122b6b57
Signed-off-by: Junghyun Yeon <jungh.yeon@samsung.com>
CMakeLists.txt
packaging/pkgmgr-tool.spec
src/pkg_rsc_slice.c [new file with mode: 0755]

index f816b98..f5612bb 100644 (file)
@@ -29,7 +29,8 @@ FOREACH(flag ${pkgs_initdb_CFLAGS})
        SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
 ENDFOREACH(flag)
 
-pkg_check_modules(pkgs_test REQUIRED dlog glib-2.0 bundle pkgmgr pkgmgr-parser pkgmgr-info pkgmgr-installer libtzplatform-config)
+pkg_check_modules(pkgs_test REQUIRED dlog glib-2.0 bundle pkgmgr pkgmgr-parser pkgmgr-info pkgmgr-installer
+libtzplatform-config aul)
 FOREACH(flag ${pkgs_test_CFLAGS})
        SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
 ENDFOREACH(flag)
@@ -62,6 +63,10 @@ ADD_EXECUTABLE(install_preload_tpk src/install_preload_tpk.c)
 TARGET_LINK_LIBRARIES(install_preload_tpk ${pkgs_test_LDFLAGS})
 INSTALL(TARGETS install_preload_tpk DESTINATION bin)
 
+ADD_EXECUTABLE(rsc-slice src/pkg_rsc_slice.c)
+TARGET_LINK_LIBRARIES(rsc-slice ${pkgs_test_LDFLAGS})
+INSTALL(TARGETS rsc-slice DESTINATION bin)
+
 INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/data/10_package-manager-add.post  DESTINATION ${SYSCONF_INSTALL_DIR}/gumd/useradd.d/)
 
 INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/data/mime.wac.xml DESTINATION /usr/share/mime/packages/)
index 8e1685e..6de46e9 100644 (file)
@@ -24,6 +24,7 @@ BuildRequires:  pkgconfig(xdgmime)
 BuildRequires:  pkgconfig(db-util)
 BuildRequires:  pkgconfig(pkgmgr)
 BuildRequires:  pkgconfig(pkgmgr-installer)
+BuildRequires:  pkgconfig(aul)
 BuildRequires:  pkgmgr-info-parser-devel
 BuildRequires:  pkgmgr-info-parser
 BuildRequires:  fdupes
@@ -82,6 +83,7 @@ fi
 %{_bindir}/pkg_getsize
 %{_bindir}/pkg_clearcache
 %{_bindir}/pkginfo
+%{_bindir}/rsc-slice
 %attr(0755,root,root) %{_bindir}/install_preload_tpk
 %{_datadir}/mime/packages/mime.wac.xml
 %{_datadir}/mime/packages/mime.tpk.xml
diff --git a/src/pkg_rsc_slice.c b/src/pkg_rsc_slice.c
new file mode 100755 (executable)
index 0000000..275420d
--- /dev/null
@@ -0,0 +1,275 @@
+
+/*
+ * pkgmgr-tool
+ *
+ * Copyright (c) 2015-2016 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * 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.
+ *
+ */
+
+#define _GNU_SOURCE
+
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <ctype.h>
+#include <getopt.h>
+#include <dirent.h>
+#include <fcntl.h>
+#include <dlfcn.h>
+#include <sys/types.h>
+#include <glib.h>
+#include <glib-object.h>
+#include <glib/gstdio.h>
+#include <bundle.h>
+#include <bundle_internal.h>
+#include <sys/time.h>
+#include "aul_rsc_mgr.h"
+
+#define RSC_TOOL_VERSION       "0.1"
+#define BUF_SIZE 1024
+
+static int __process_slice(void);
+static void __print_usage();
+//static int __is_authorized();
+
+struct rsc_tool_args_t {
+       char res_path[PATH_MAX];
+       int dpi;
+       int bpp;
+       char dpi_range[BUF_SIZE];
+       char width_range[BUF_SIZE];
+       char screen_large[BUF_SIZE];
+       char platform_version[BUF_SIZE];
+};
+
+typedef struct rsc_tool_args_t rsc_tool_args;
+rsc_tool_args data;
+GHashTable *valid_file_list;
+
+const char *short_options = "p:d:";
+
+const struct option long_options[] = {
+       {"path", 1, NULL, 'p'},
+       {"screen-dpi", 1, NULL, 'd'},
+       {0, 0, 0, 0}            /* sentinel */
+};
+
+
+static int __convert_to_abs_path(char *path)
+{
+       char abs[BUF_SIZE] = {'\0'};
+       char cwd[BUF_SIZE] = {'\0'};
+       char *buf = NULL;
+       int ret = -1;
+
+       if (path == NULL) {
+               printf("invalid path\n");
+               return -1;
+       }
+
+       buf = getcwd(cwd, BUF_SIZE - 1);
+       if (buf == NULL) {
+               printf("failed to get cwd\n");
+               return -1;
+       }
+
+       ret = chdir(path);
+       if (ret < 0) {
+               printf("failed to change dir[%s]\n", path);
+               return -1;
+       }
+
+       buf = getcwd(abs, BUF_SIZE - 1);
+       if (buf == NULL) {
+               printf("failed to get cwd\n");
+               return -1;
+       }
+
+       memset(data.res_path, '\0', BUF_SIZE);
+       snprintf(data.res_path, BUF_SIZE - 1, "%s/", abs);
+       ret = chdir(cwd);
+       if (ret < 0) {
+               printf("failed to change dir[%s]\n", path);
+               return -1;
+       }
+
+       return 0;
+}
+
+static void __print_usage()
+{
+       printf("\nResource Slicing Tool Version: %s\n\n", RSC_TOOL_VERSION);
+       printf("-p, --path                   set resource path\n");
+       printf("-d, --screen-dpi     set screen dpi value\n");
+
+       printf("Usage: rscslice [options] \n");
+       printf("rsc-slice -p [res path] \n");
+       printf("rsc-slice -p [res_path] -d [dpi value] \n");
+
+       printf("Example:\n");
+       printf("rsc-slice -p /home/userid/workspace/testapp/res/ \n");
+       printf("rsc-slice -p /home/userid/workspace/testapp/res/ -d 300 \n");
+
+       exit(0);
+}
+
+static void __del_file(char *path)
+{
+       struct dirent **items;
+       struct stat fstat;
+       char abs_path[1024] = {0, };
+       char cwd[1024] = {0, };
+       char *tmp = NULL;
+       int nitems, i;
+
+       if (chdir(path) < 0) {
+               printf("failed to chdir[%s]\n", path);
+               return;
+       }
+
+       tmp = getcwd(cwd, 1024 - 1);
+       nitems = scandir("./", &items, NULL, alphasort);
+
+       for (i = 0; i < nitems; i++) {
+               if (items[i]->d_name[0] == '.')
+                       continue;
+
+               snprintf(abs_path, 1024 - 1, "%s/%s", cwd, items[i]->d_name);
+               if (g_lstat(abs_path, &fstat) != 0) {
+                       printf("failed to get info[%s]\n", abs_path);
+                       return;
+               }
+               if ((fstat.st_mode & S_IFDIR) == S_IFDIR) {
+                       __del_file(abs_path);
+               } else {
+                       tmp = g_hash_table_lookup(valid_file_list, abs_path);
+                       if (tmp == NULL) {
+                               printf("deleting [%s]\n", abs_path);
+                               remove(abs_path);
+                       }
+               }
+       }
+}
+
+static int __process_slice(void)
+{
+       int ret = -1;
+       bundle *b = NULL;
+       char dpi_value[1024] = {0, };
+
+       if (data.res_path[0] == '\0')
+               return -1;
+
+       b = bundle_create();
+       if (data.dpi != 0) {
+               snprintf(dpi_value, 1024 - 1, "%d", data.dpi);
+               bundle_add_str(b, "screen-dpi", dpi_value);
+       }
+
+       /* other attributes will be added here*/
+
+       ret = aul_resource_manager_init_slice(data.res_path, b);
+       if (ret < 0) {
+               printf("failed to init rsc manager\n");
+               goto catch;
+       }
+
+       ret = aul_resource_manager_get_path_list(&valid_file_list);
+       if (ret < 0) {
+               printf("failed to init rsc manager\n");
+               goto catch;
+       }
+
+       /* remove useless resources and empty directories */
+       __del_file(data.res_path);
+
+
+catch:
+       if (aul_resource_manager_release() < 0)
+               printf("failed to release resource manager\n");
+
+       bundle_free(b);
+       return ret;
+}
+
+int main(int argc, char *argv[])
+{
+       optind = 1;
+       int opt_idx = 0;
+       int c = -1;
+       int ret = 0;
+       long starttime;
+       long endtime;
+       int i = 0;
+       struct timeval tv;
+
+       if (argc == 1)
+               __print_usage();
+
+       gettimeofday(&tv, NULL);
+       starttime = tv.tv_sec * 1000l + tv.tv_usec / 1000l;
+
+       /* initialization of global structure */
+       data.dpi = 0;
+       data.bpp = 0;
+       memset(data.dpi_range, '\0', BUF_SIZE);
+       memset(data.width_range, '\0', BUF_SIZE);
+       memset(data.screen_large, '\0', BUF_SIZE);
+       memset(data.platform_version, '\0', BUF_SIZE);
+
+       while (1) {
+               i++;
+               c = getopt_long(argc, argv, short_options, long_options, &opt_idx);
+               if (c == -1)
+                       break;  /* Parse end */
+               switch (c) {
+               case 'p':       /* resource path */
+                       if (optarg)
+                               strncpy(data.res_path, optarg, PATH_MAX - 1);
+
+                       ret = __convert_to_abs_path(data.res_path);
+                       if (ret == -1) {
+                               printf("conversion of relative path to absolute path failed\n");
+                               return -1;
+                       }
+                       printf("path is [%s]\n", data.res_path);
+                       break;
+
+               case 'd':       /* set dpi */
+                       if (optarg)
+                               data.dpi = atoi(optarg);
+
+                       if (data.dpi == 0) {
+                               printf("failed to get dpi value\n");
+                               return -1;
+                       }
+                       printf("dpi value is [%d]\n", data.dpi);
+                       break;
+
+               default:
+                       break;
+
+               }
+       }
+
+       ret = __process_slice();
+
+       gettimeofday(&tv, NULL);
+       endtime = tv.tv_sec * 1000l + tv.tv_usec / 1000l;
+       printf("spend time for rsc-slice is [%d]ms\n", (int)(endtime - starttime));
+
+       return 0;
+}